diff options
Diffstat (limited to 'boot/common.c')
| -rw-r--r-- | boot/common.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/boot/common.c b/boot/common.c index d814538..65dc780 100644 --- a/boot/common.c +++ b/boot/common.c @@ -166,6 +166,47 @@ string_print(struct String s) printf("%.*s", (int32)s.length, s.data); } +#define STRING_ARRAY_MAX 8 + +// a string array, used for storing multiple strings. +// if we ever need more strings, just bump `STRING_ARRAY_MAX` up. +struct String_Array +{ + struct String strings[STRING_ARRAY_MAX]; + uint count; +}; + +// initializes a string array with no strings. +struct String_Array +string_array_new() +{ + return (struct String_Array){ + .strings = { 0 }, + .count = 0, + }; +} + +// adds a string to the string array. +bool +string_array_add(struct String_Array* array, struct String string) +{ + if (array->count >= STRING_ARRAY_MAX) return false; + + array->strings[array->count++] = string; + return true; +} + +struct String +string_array_at(const struct String_Array* array, uint index) +{ + check(index < array->count, "index out of bounds"); + return array->strings[index]; +} + +#define STRING_ARRAY_FOR_EACH(cursor, str, array) \ + struct String str = array.strings[0]; \ + for (uint cursor = 0; cursor < array.count; str = array.strings[++cursor]) + // single iteration of the CRC32 checksum algorithm // described in POSIX. // see: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/cksum.html |
