@@ -305,30 +305,52 @@ VkResult create_string_list(const struct loader_instance *inst, uint32_t allocat
305305 return VK_SUCCESS ;
306306}
307307
308- VkResult append_str_to_string_list (const struct loader_instance * inst , struct loader_string_list * string_list , char * str ) {
309- assert (string_list && str );
308+ VkResult incrase_str_capacity_by_at_least_one (const struct loader_instance * inst , struct loader_string_list * string_list ) {
309+ assert (string_list );
310310 if (string_list -> allocated_count == 0 ) {
311311 string_list -> allocated_count = 32 ;
312312 string_list -> list =
313313 loader_instance_heap_calloc (inst , sizeof (char * ) * string_list -> allocated_count , VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE );
314314 if (NULL == string_list -> list ) {
315- loader_instance_heap_free (inst , str ); // Must clean up in case of failure
316315 return VK_ERROR_OUT_OF_HOST_MEMORY ;
317316 }
318317 } else if (string_list -> count + 1 > string_list -> allocated_count ) {
319318 uint32_t new_allocated_count = string_list -> allocated_count * 2 ;
320319 string_list -> list = loader_instance_heap_realloc (inst , string_list -> list , sizeof (char * ) * string_list -> allocated_count ,
321320 sizeof (char * ) * new_allocated_count , VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE );
322321 if (NULL == string_list -> list ) {
323- loader_instance_heap_free (inst , str ); // Must clean up in case of failure
324322 return VK_ERROR_OUT_OF_HOST_MEMORY ;
325323 }
326324 string_list -> allocated_count *= 2 ;
327325 }
326+ return VK_SUCCESS ;
327+ }
328+
329+ VkResult append_str_to_string_list (const struct loader_instance * inst , struct loader_string_list * string_list , char * str ) {
330+ assert (string_list && str );
331+ VkResult res = incrase_str_capacity_by_at_least_one (inst , string_list );
332+ if (res == VK_ERROR_OUT_OF_HOST_MEMORY ) {
333+ loader_instance_heap_free (inst , str ); // Must clean up in case of failure
334+ return res ;
335+ }
328336 string_list -> list [string_list -> count ++ ] = str ;
329337 return VK_SUCCESS ;
330338}
331339
340+ VkResult prepend_str_to_string_list (const struct loader_instance * inst , struct loader_string_list * string_list , char * str ) {
341+ assert (string_list && str );
342+ VkResult res = incrase_str_capacity_by_at_least_one (inst , string_list );
343+ if (res == VK_ERROR_OUT_OF_HOST_MEMORY ) {
344+ loader_instance_heap_free (inst , str ); // Must clean up in case of failure
345+ return res ;
346+ }
347+ // Shift everything down one
348+ void * ptr_to_list = memmove (string_list -> list + 1 , string_list -> list , sizeof (char * ) * string_list -> count );
349+ if (ptr_to_list ) string_list -> list [0 ] = str ; // Write new string to start of list
350+ string_list -> count ++ ;
351+ return VK_SUCCESS ;
352+ }
353+
332354VkResult copy_str_to_string_list (const struct loader_instance * inst , struct loader_string_list * string_list , const char * str ,
333355 size_t str_len ) {
334356 assert (string_list && str );
@@ -341,6 +363,18 @@ VkResult copy_str_to_string_list(const struct loader_instance *inst, struct load
341363 return append_str_to_string_list (inst , string_list , new_str );
342364}
343365
366+ VkResult copy_str_to_start_of_string_list (const struct loader_instance * inst , struct loader_string_list * string_list ,
367+ const char * str , size_t str_len ) {
368+ assert (string_list && str );
369+ char * new_str = loader_instance_heap_calloc (inst , sizeof (char * ) * str_len + 1 , VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE );
370+ if (NULL == new_str ) {
371+ return VK_ERROR_OUT_OF_HOST_MEMORY ;
372+ }
373+ loader_strncpy (new_str , sizeof (char * ) * str_len + 1 , str , str_len );
374+ new_str [str_len ] = '\0' ;
375+ return prepend_str_to_string_list (inst , string_list , new_str );
376+ }
377+
344378void free_string_list (const struct loader_instance * inst , struct loader_string_list * string_list ) {
345379 assert (string_list );
346380 if (string_list -> list ) {
@@ -3002,10 +3036,8 @@ void copy_data_file_info(const char *cur_path, const char *relative_path, size_t
30023036 }
30033037}
30043038
3005- // If the file found is a manifest file name, add it to the out_files manifest list.
3039+ // If the file found is a manifest file name, add it to the end of out_files manifest list.
30063040VkResult add_if_manifest_file (const struct loader_instance * inst , const char * file_name , struct loader_string_list * out_files ) {
3007- VkResult vk_result = VK_SUCCESS ;
3008-
30093041 assert (NULL != file_name && "add_if_manifest_file: Received NULL pointer for file_name" );
30103042 assert (NULL != out_files && "add_if_manifest_file: Received NULL pointer for out_files" );
30113043
@@ -3014,15 +3046,26 @@ VkResult add_if_manifest_file(const struct loader_instance *inst, const char *fi
30143046 const char * name_suffix = file_name + name_len - 5 ;
30153047 if (!is_json (name_suffix , name_len )) {
30163048 // Use incomplete to indicate invalid name, but to keep going.
3017- vk_result = VK_INCOMPLETE ;
3018- goto out ;
3049+ return VK_INCOMPLETE ;
30193050 }
30203051
3021- vk_result = copy_str_to_string_list (inst , out_files , file_name , name_len );
3052+ return copy_str_to_string_list (inst , out_files , file_name , name_len );
3053+ }
30223054
3023- out :
3055+ // If the file found is a manifest file name, add it to the start of the out_files manifest list.
3056+ VkResult prepend_if_manifest_file (const struct loader_instance * inst , const char * file_name , struct loader_string_list * out_files ) {
3057+ assert (NULL != file_name && "prepend_if_manifest_file: Received NULL pointer for file_name" );
3058+ assert (NULL != out_files && "prepend_if_manifest_file: Received NULL pointer for out_files" );
30243059
3025- return vk_result ;
3060+ // Look for files ending with ".json" suffix
3061+ size_t name_len = strlen (file_name );
3062+ const char * name_suffix = file_name + name_len - 5 ;
3063+ if (!is_json (name_suffix , name_len )) {
3064+ // Use incomplete to indicate invalid name, but to keep going.
3065+ return VK_INCOMPLETE ;
3066+ }
3067+
3068+ return copy_str_to_start_of_string_list (inst , out_files , file_name , name_len );
30263069}
30273070
30283071// Add any files found in the search_path. If any path in the search path points to a specific JSON, attempt to
0 commit comments