ps4: add_string

This commit is contained in:
2026-03-26 20:16:21 +01:00
parent 1a1df8f751
commit d0bf7cd2cb

View File

@@ -225,17 +225,12 @@ static size_t string_list_capacity;
// Takes ownership of the string, and returns its position in the string list.
static size_t add_string(char* string)
{
// TODO: Write a helper function you can use during bind_names(),
// to easily add a string into the dynamically growing string_list.
// The length of the string list should be stored in string_list_len.
// The variable string_list_capacity should contain the maximum number of char*
// that can fit in the current string_list before we need to allocate a larger array.
// If length is about to surpass capacity, create a larger allocation first.
// Tip: See the realloc function from the standard library
// Return the position the added string gets in the list.
if (string_list_len >= string_list_capacity) {
string_list_capacity = string_list_capacity * 2 + 8;
string_list = realloc(string_list, string_list_capacity * sizeof(char*));
}
string_list[string_list_len] = string; // takes ownership
return string_list_len++;
}
// Prints all strings added to the global string list