23 #ifndef _FOUNDATIONAL_LIB_HEADER_GUARD
24 #define _FOUNDATIONAL_LIB_HEADER_GUARD
39 void *
memmem(
const void *haystack,
size_t haystacklen,
const void *needle,
size_t needlelen);
47 #ifndef FOUNDATIONAL_LIB_AGGRESSIVE_DIE_TYPE
55 #define FOUNDATIONAL_LIB_AGGRESSIVE_DIE_TYPE unsigned char
92 #ifndef FOUNDATIONAL_LIB_USE_STATIC_ASSERTS_FOR_SAFETY
93 #define FOUNDATIONAL_LIB_USE_STATIC_ASSERTS_FOR_SAFETY 1
96 #if FOUNDATIONAL_LIB_USE_STATIC_ASSERTS_FOR_SAFETY
99 #ifndef FOUNDATIONAL_LIB_Static_assert
100 #define FOUNDATIONAL_LIB_Static_assert static_assert
103 #ifndef FOUNDATIONAL_LIB_Static_assert
104 #define FOUNDATIONAL_LIB_Static_assert _Static_assert
108 #define FOUNDATIONAL_LIB_STATIC_ASSERT_MSG(true_cond, failure_message) FOUNDATIONAL_LIB_Static_assert((true_cond), failure_message)
110 #define FOUNDATIONAL_LIB_STATIC_ASSERT(true_cond) FOUNDATIONAL_LIB_Static_assert((true_cond), "(" #true_cond ") failed")
112 #define FOUNDATIONAL_LIB_SIZE_STRING_OF_NUMBER_SIZE_PLUS_ZERO_TERMINATOR 21
116 #ifndef FOUNDATIONAL_LIB_UNSAFE_FUNCTIONS_ENABLED
118 #define FOUNDATIONAL_LIB_UNSAFE_FUNCTIONS_ENABLED 1
121 #ifndef FOUNDATIONAL_LIB_VA_LIST
122 #define FOUNDATIONAL_LIB_VA_LIST va_list
125 #ifndef FOUNDATIONAL_LIB_VA_START
126 #define FOUNDATIONAL_LIB_VA_START va_start
129 #ifndef FOUNDATIONAL_LIB_VA_ARG
130 #define FOUNDATIONAL_LIB_VA_ARG va_arg
133 #ifndef FOUNDATIONAL_LIB_VA_END
134 #define FOUNDATIONAL_LIB_VA_END va_end
139 #ifndef FOUNDATIONAL_LIB_LIBC_LOCKING_IO_OPERATIONS
142 #define FOUNDATIONAL_LIB_LIBC_LOCKING_IO_OPERATIONS 1
145 #ifndef FOUNDATIONAL_LIB_ISSPACE
146 #define FOUNDATIONAL_LIB_ISSPACE __builtin_isspace
148 #ifndef FOUNDATIONAL_LIB_ISALPHA
149 #define FOUNDATIONAL_LIB_ISALPHA __builtin_isalpha
151 #ifndef FOUNDATIONAL_LIB_ISALNUM
152 #define FOUNDATIONAL_LIB_ISALNUM __builtin_isalnum
154 #ifndef FOUNDATIONAL_LIB_ISDIGIT
155 #define FOUNDATIONAL_LIB_ISDIGIT __builtin_isdigit
157 #ifndef FOUNDATIONAL_LIB_ISPRINT
158 #define FOUNDATIONAL_LIB_ISPRINT __builtin_isprint
160 #ifndef FOUNDATIONAL_LIB_ISUPPER
161 #define FOUNDATIONAL_LIB_ISUPPER __builtin_isupper
163 #ifndef FOUNDATIONAL_LIB_ISLOWER
164 #define FOUNDATIONAL_LIB_ISLOWER __builtin_islower
167 #ifndef FOUNDATIONAL_LIB_STRLEN
168 #define FOUNDATIONAL_LIB_STRLEN __builtin_strlen
171 #ifndef FOUNDATIONAL_LIB_PRINTF
172 #define FOUNDATIONAL_LIB_PRINTF __builtin_printf
175 #ifndef FOUNDATIONAL_LIB_SPRINTF
176 #define FOUNDATIONAL_LIB_SPRINTF __builtin_sprintf
179 #ifndef FOUNDATIONAL_LIB_SNPRINTF
180 #define FOUNDATIONAL_LIB_SNPRINTF __builtin_snprintf
183 #ifndef FOUNDATIONAL_LIB_VSNPRINTF
184 #define FOUNDATIONAL_LIB_VSNPRINTF __builtin_vsnprintf
187 #ifndef FOUNDATIONAL_LIB_FPRINTF
189 #if FOUNDATIONAL_LIB_LIBC_LOCKING_IO_OPERATIONS
190 #define FOUNDATIONAL_LIB_FPRINTF __builtin_fprintf
192 #define FOUNDATIONAL_LIB_FPRINTF __builtin_fprintf
196 #ifndef FOUNDATIONAL_LIB_FPUTS
197 #if FOUNDATIONAL_LIB_LIBC_LOCKING_IO_OPERATIONS
198 #define FOUNDATIONAL_LIB_FPUTS __builtin_fputs
200 #define FOUNDATIONAL_LIB_FPUTS __builtin_fputs_unlocked
204 #ifndef FOUNDATIONAL_LIB_PUTCHAR
206 #if FOUNDATIONAL_LIB_LIBC_LOCKING_IO_OPERATIONS
208 #define FOUNDATIONAL_LIB_PUTCHAR __builtin_putchar
210 #define FOUNDATIONAL_LIB_PUTCHAR __builtin_putchar_unlocked
214 #ifndef FOUNDATIONAL_LIB_FPUTC
216 #if FOUNDATIONAL_LIB_LIBC_LOCKING_IO_OPERATIONS
218 #define FOUNDATIONAL_LIB_FPUTC __builtin_fputc
220 #define FOUNDATIONAL_LIB_FPUTC __builtin_fputc_unlocked
224 #ifndef FOUNDATIONAL_LIB_STRPBRK
225 #define FOUNDATIONAL_LIB_STRPBRK __builtin_strpbrk
241 #ifndef FOUNDATIONAL_LIB_MEMCPY
242 #define FOUNDATIONAL_LIB_MEMCPY __builtin_memcpy
245 #ifndef FOUNDATIONAL_LIB_STRLEN
246 #define FOUNDATIONAL_LIB_STRLEN __builtin_strlen
249 #ifndef FOUNDATIONAL_LIB_STRCMP
250 #define FOUNDATIONAL_LIB_STRCMP __builtin_strcmp
253 #ifndef FOUNDATIONAL_LIB_MEMCMP
254 #define FOUNDATIONAL_LIB_MEMCMP __builtin_memcmp
257 #ifndef FOUNDATIONAL_LIB_MEMMOVE
258 #define FOUNDATIONAL_LIB_MEMMOVE __builtin_memmove
261 #ifndef FOUNDATIONAL_LIB_STRCHR
262 #define FOUNDATIONAL_LIB_STRCHR __builtin_strchr
265 #ifndef FOUNDATIONAL_LIB_MEMCHR
266 #define FOUNDATIONAL_LIB_MEMCHR __builtin_memchr
269 #ifndef FOUNDATIONAL_LIB_STRSTR
270 #define FOUNDATIONAL_LIB_STRSTR __builtin_strstr
273 #define __attribute__((nonnull))
274 #define __attribute__((format(printf, 1, 2)))
275 #define __attribute__((warn_unused_result))
276 #define __attribute__((nothrow))
277 #define __attribute__((malloc))
279 #define FOUNDATIONAL_LIB_CONST __attribute__((const))
280 #define __attribute__((pure))
284 #ifndef FOUNDATIONAL_LIB_PRINTF
285 #define FOUNDATIONAL_LIB_PRINTF printf
288 #ifndef FOUNDATIONAL_LIB_SPRINTF
289 #define FOUNDATIONAL_LIB_SPRINTF sprintf
292 #ifdef FOUNDATIONAL_LIB_SNPRINTF
293 #define FOUNDATIONAL_LIB_SNPRINTF snprintf
296 #ifndef FOUNDATIONAL_LIB_VSNPRINTF
297 #define FOUNDATIONAL_LIB_VSNPRINTF vsnprintf
300 #ifndef FOUNDATIONAL_LIB_FPRINTF
301 #define FOUNDATIONAL_LIB_FPRINTF fprintf
304 #ifndef FOUNDATIONAL_LIB_MEMCPY
305 #define FOUNDATIONAL_LIB_MEMCPY memcpy
308 #ifndef FOUNDATIONAL_LIB_STRLEN
309 #define FOUNDATIONAL_LIB_STRLEN strlen
312 #ifndef FOUNDATIONAL_LIB_STRCMP
313 #define FOUNDATIONAL_LIB_STRCMP strcmp
316 #ifndef FOUNDATIONAL_LIB_MEMCMP
317 #define FOUNDATIONAL_LIB_MEMCMP memcmp
320 #ifndef FOUNDATIONAL_LIB_MEMMOVE
321 #define FOUNDATIONAL_LIB_MEMMOVE memmove
324 #ifndef FOUNDATIONAL_LIB_FPUTS
325 #define FOUNDATIONAL_LIB_FPUTS fputs
328 #ifndef FOUNDATIONAL_LIB_PUTCHAR
329 #define FOUNDATIONAL_LIB_PUTCHAR putchar
332 #ifndef FOUNDATIONAL_LIB_FPUTC
333 #define FOUNDATIONAL_LIB_FPUTC putc
336 #ifndef FOUNDATIONAL_LIB_STRPBRK
337 #define FOUNDATIONAL_LIB_STRPBRK strpbrk
340 #ifndef FOUNDATIONAL_LIB_STRCHR
341 #define FOUNDATIONAL_LIB_STRCHR
344 #ifndef FOUNDATIONAL_LIB_MEMCHR
345 #define FOUNDATIONAL_LIB_MEMCHR
348 #ifndef FOUNDATIONAL_LIB_STRSTR
349 #define FOUNDATIONAL_LIB_STRSTR strstr
352 #ifndef FOUNDATIONAL_LIB_ISSPACE
353 #define FOUNDATIONAL_LIB_ISSPACE isspace
355 #ifndef FOUNDATIONAL_LIB_ISALPHA
356 #define FOUNDATIONAL_LIB_ISALPHA isalpha
358 #ifndef FOUNDATIONAL_LIB_ISALNUM
359 #define FOUNDATIONAL_LIB_ISALNUM isalnum
361 #ifndef FOUNDATIONAL_LIB_ISDIGIT
362 #define FOUNDATIONAL_LIB_ISDIGIT isdigit
364 #ifndef FOUNDATIONAL_LIB_ISPRINT
365 #define FOUNDATIONAL_LIB_ISPRINT isprint
367 #ifndef FOUNDATIONAL_LIB_ISUPPER
368 #define FOUNDATIONAL_LIB_ISUPPER isupper
370 #ifndef FOUNDATIONAL_LIB_ISLOWER
371 #define FOUNDATIONAL_LIB_ISLOWER islower
378 #define __declspec(noalias)
379 #define FOUNDATIONAL_LIB_PRINTF _Printf_format_string_impl_
385 #define FOUNDATIONAL_LIB_CONST
391 #define FOUNDATIONAL_LIB_PRINTF
397 #define FOUNDATIONAL_LIB_CONST
405 #ifndef FOUNDATIONAL_LIB_FROZEN_INITIALIZATION_SIZE_MULTIPLIER
406 #define FOUNDATIONAL_LIB_FROZEN_INITIALIZATION_SIZE_MULTIPLIER 3
410 #ifndef FOUNDATIONAL_LIB_INITIAL_STRING_ARRAY_ALLOC_COUNT
411 #define FOUNDATIONAL_LIB_INITIAL_STRING_ARRAY_ALLOC_COUNT 0
415 #ifndef FOUNDATIONAL_LIB_INITIAL_STRING_ARRAY_ALLOC_SIZE
416 #define FOUNDATIONAL_LIB_INITIAL_STRING_ARRAY_ALLOC_SIZE (sizeof(char *) * 1)
419 #if defined(__GNUC__) || defined(__clang__)
420 #define FOUNDATIONAL_LIB_likely(x) __builtin_expect(!!(x), 1)
421 #define FOUNDATIONAL_LIB_UNLIKELY(x) __builtin_expect(!!(x), 0)
423 #define FOUNDATIONAL_LIB_likely(x) (x)
424 #define FOUNDATIONAL_LIB_UNLIKELY(x) (x)
427 #ifndef FOUNDATIONAL_LIB_ASSERT_ARGUMENT_CHECKING
428 #define FOUNDATIONAL_LIB_ASSERT_ARGUMENT_CHECKING 0
431 #ifndef FOUNDATIONAL_LIB_ASSERT_ARGUMENT_IF_ENABLED
432 #if FOUNDATIONAL_LIB_ASSERT_ARGUMENT_CHECKING
433 #define FOUNDATIONAL_LIB_ASSERT_ARGUMENT_IF_ENABLED(x) assert(x)
435 #define FOUNDATIONAL_LIB_ASSERT_ARGUMENT_IF_ENABLED(x)
441 FOUNDATIONAL_LIB_CONST
469 FOUNDATIONAL_LIB_CONST
484 FOUNDATIONAL_LIB_CONST
524 FOUNDATIONAL_LIB_CONST
529 if (b != 0 && a > SIZE_MAX / b)
543 if (b != 0 && a > SIZE_MAX / b)
554 FOUNDATIONAL_LIB_CONST
559 if (a > SIZE_MAX - b || a + b > SIZE_MAX - c)
570 FOUNDATIONAL_LIB_CONST
575 if (a > SIZE_MAX - b || b > SIZE_MAX - c)
589 if (a > SIZE_MAX - b)
603 if (a > SIZE_MAX - b || b > SIZE_MAX - c)
614 #define FOUNDATIONAL_LIB_safe_increment(variable, label_if_fails) \
615 if (FOUNDATIONAL_LIB_UNLIKELY(FOUNDATIONAL_LIB_safe_add_2_ptr((variable), 1, &(variable)) == 0)) \
621 #ifndef FOUNDATIONAL_LIB_LOW_MEMORY_USAGE
622 #define FOUNDATIONAL_LIB_LOW_MEMORY_USAGE 12
625 #ifndef FOUNDATIONAL_LIB_ALLOCATOR_DIV_AMOUNT
626 #define FOUNDATIONAL_LIB_ALLOCATOR_DIV_AMOUNT 2
632 FOUNDATIONAL_LIB_CONST
649 if (__builtin_add_overflow(old_size_to_add_at_least_one_to, old_size_to_add_at_least_one_to / div_amount, &addition))
676 if (siz > SIZE_MAX / 2 || siz > (SIZE_MAX - siz) / 2)
683 const size_t addition = siz + (siz / div_amount);
692 #ifndef FOUNDATIONAL_LIB_COPY_SIZE_AMOUNT
693 #define FOUNDATIONAL_LIB_COPY_SIZE_AMOUNT 4096
696 #if FOUNDATIONAL_LIB_UNSAFE_FUNCTIONS_ENABLED
698 #ifndef FOUNDATIONAL_LIB_POPEN_INITIAL_ALLOC_SIZE
699 #define FOUNDATIONAL_LIB_POPEN_INITIAL_ALLOC_SIZE 4096
705 #ifndef FOUNDATIONAL_LIB_ATOI
706 #define FOUNDATIONAL_LIB_ATOI atoi
711 #if FOUNDATIONAL_LIB_UNSAFE_FUNCTIONS_ENABLED
713 #define FOUNDATIONAL_LIB_POPEN _popen
714 #define FOUNDATIONAL_LIB_PCLOSE _pclose
716 #define FOUNDATIONAL_LIB_POPEN popen
717 #define FOUNDATIONAL_LIB_PCLOSE pclose
721 #ifndef FOUNDATIONAL_LIB_FERROR
722 #define FOUNDATIONAL_LIB_FERROR ferror
726 #ifndef FOUNDATIONAL_LIB_FSEEKO
727 #define FOUNDATIONAL_LIB_FSEEKO _fseeki64
730 #ifndef FOUNDATIONAL_LIB_FTELLO
731 #define FOUNDATIONAL_LIB_FTELLO _ftelli64
734 #ifndef FOUNDATIONAL_LIB_FSEEKO
735 #define FOUNDATIONAL_LIB_FSEEKO fseeko
738 #ifndef FOUNDATIONAL_LIB_FTELLO
739 #define FOUNDATIONAL_LIB_FTELLO ftello
744 #ifndef FOUNDATIONAL_LIB_FREAD
745 #define FOUNDATIONAL_LIB_FREAD fread
748 #ifndef FOUNDATIONAL_LIB_FWRITE
749 #define FOUNDATIONAL_LIB_FWRITE fwrite
752 #ifndef FOUNDATIONAL_LIB_FOPEN
753 #define FOUNDATIONAL_LIB_FOPEN fopen
756 #ifndef FOUNDATIONAL_LIB_FCLOSE
757 #define FOUNDATIONAL_LIB_FCLOSE fclose
762 #ifndef FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_MALLOC
763 #define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_MALLOC malloc
766 #ifndef FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_REALLOC
767 #define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_REALLOC realloc
770 #ifndef FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_CALLOC
771 #define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_CALLOC calloc
774 #ifndef FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_FREE
775 #define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_FREE free
778 #ifndef FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_STRDUP
779 #define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_STRDUP strdup
785 #ifndef FOUNDATIONAL_LIB_NETWORK_FUNCTIONS_ENABLED
786 #define FOUNDATIONAL_LIB_NETWORK_FUNCTIONS_ENABLED 0
789 #if FOUNDATIONAL_LIB_NETWORK_FUNCTIONS_ENABLED
790 #define FOUNDATIONAL_LIB_INITIAL_NETWORK_DOWNLOAD_BUFFER_SIZE 8192
793 #ifndef FOUNDATIONAL_LIB_HASH_INITIAL_CAPACITY
801 #define FOUNDATIONAL_LIB_HASH_INITIAL_CAPACITY 16
804 #ifndef FOUNDATIONAL_LIB_HASH_LOAD_FACTOR_THRESHOLD
813 #define FOUNDATIONAL_LIB_HASH_LOAD_FACTOR_THRESHOLD 0.75
816 #ifndef FOUNDATIONAL_LIB_FUNC
821 #define FOUNDATIONAL_LIB_FUNC static inline
824 #ifndef FOUNDATIONAL_LIB_THREAD_FUNCTIONS_ENABLED
832 #define FOUNDATIONAL_LIB_THREAD_FUNCTIONS_ENABLED 1
856 #define FOUNDATIONAL_LIB_set_aggressive_die(mode) \
858 FOUNDATIONAL_LIB_aggressive_die = (mode); \
867 #define FOUNDATIONAL_LIB_get_aggressive_die() FOUNDATIONAL_LIB_aggressive_die
869 #ifndef FOUNDATIONAL_LIB_die_aggressively_if_enabled
878 #define FOUNDATIONAL_LIB_die_aggressively_if_enabled() \
879 if (FOUNDATIONAL_LIB_UNLIKELY(FOUNDATIONAL_LIB_aggressive_die)) \
881 FOUNDATIONAL_LIB_FPRINTF(stderr, "Error: %s: %s.\n", __func__, strerror(errno)); \
882 exit(EXIT_FAILURE);
\
942 unsigned long long u;
951 u = (
long long)number;
973 char *return_value = strdup(buffer);
996 unsigned long long a;
999 unsigned long long u;
1006 number = 0 - number;
1008 u = (
unsigned long)number;
1049 a = unsigned_value % 10;
1050 unsigned_value /= 10;
1052 }
while (unsigned_value);
1079 utoa(number, buffer);
1088 return return_value;
1106 for (
size_t i = 0; i <
size; ++i)
1108 const unsigned int value = array[i];
1137 for (
size_t i = 0; i <
size; ++i)
1139 const unsigned int value = *array[i];
1168 for (
size_t i = 0; i <
size; ++i)
1170 const int value = array[i];
1200 for (
size_t i = 0; i <
size; ++i)
1202 const unsigned int value = *array[i];
1234 for (
size_t i = 0; i <
size; ++i)
1262 for (
size_t i = 0; i <
size; ++i)
1289 for (
size_t i = 0; i <
size; ++i)
1291 const unsigned short value = array[i];
1322 for (
size_t i = 0; i <
size; ++i)
1324 const unsigned short value = *(array[i]);
1353 for (
size_t i = 0; i <
size; ++i)
1355 const short value = array[i];
1386 for (
size_t i = 0; i <
size; ++i)
1388 const short value = *(array[i]);
1417 for (
size_t i = 0; i <
size; ++i)
1419 const unsigned long value = array[i];
1450 for (
size_t i = 0; i <
size; ++i)
1452 const unsigned long value = *(array[i]);
1481 for (
size_t i = 0; i <
size; ++i)
1483 const long value = array[i];
1511 for (
size_t i = 0; i <
size; ++i)
1513 const long value = *(array[i]);
1541 for (
size_t i = 0; i <
size; ++i)
1543 const unsigned long long value = array[i];
1572 for (
size_t i = 0; i <
size; ++i)
1574 const unsigned long long value = *(array[i]);
1602 for (
size_t i = 0; i <
size; ++i)
1604 const long long value = array[i];
1633 for (
size_t i = 0; i <
size; ++i)
1635 const long long value = *(array[i]);
1662 for (
size_t i = 0; i <
size; ++i)
1688 for (
size_t i = 0; i <
size; ++i)
1713 for (
size_t i = 0; i <
size; ++i)
1739 for (
size_t i = 0; i <
size; ++i)
1765 for (
size_t i = 0; i <
size; ++i)
1767 const size_t value = array[i];
1796 for (
size_t i = 0; i <
size; ++i)
1798 const size_t value = *(array[i]);
1827 for (
size_t i = 0; i <
size; ++i)
1854 for (
size_t i = 0; i <
size; ++i)
1879 for (
size_t i = 0; i <
size; ++i)
1906 for (
size_t i = 0; i <
size; ++i)
1932 for (
size_t i = 0; i <
size; ++i)
1957 for (
size_t i = 0; i <
size; ++i)
1983 for (
size_t i = 0; i <
size; ++i)
2010 for (
size_t i = 0; i <
size; ++i)
2036 for (
size_t i = 0; i <
size; ++i)
2063 for (
size_t i = 0; i <
size; ++i)
2088 for (
size_t i = 0; i <
size; ++i)
2115 for (
size_t i = 0; i <
size; i++)
2141 for (
size_t i = 0; i <
size; i++)
2168 for (
size_t i = 0; i <
size; i++)
2193 for (
size_t i = 0; i <
size; i++)
2220 for (
size_t i = 0; i <
size; i++)
2247 for (
size_t i = 0; i <
size; i++)
2249 const unsigned long long value = array[i];
2252 utoa(value, buffer);
2278 for (
size_t i = 0; i <
size; i++)
2280 const unsigned long long value = *(array[i]);
2283 utoa(value, buffer);
2308 for (
size_t i = 0; i <
size; i++)
2310 const unsigned long long value = array[i];
2341 for (
size_t i = 0; i <
size; i++)
2343 const long long value = *(array[i]);
2372 for (
size_t i = 0; i <
size; i++)
2399 for (
size_t i = 0; i <
size; i++)
2425 for (
size_t i = 0; i <
size; i++)
2452 for (
size_t i = 0; i <
size; i++)
2478 for (
size_t i = 0; i <
size; i++)
2480 #pragma GCC diagnostic push
2481 #pragma GCC diagnostic ignored "-Wpragmas"
2482 #pragma GCC diagnostic ignored "-Wformat"
2483 #pragma GCC diagnostic ignored "-Wformat-extra-args"
2486 #pragma GCC diagnostic pop
2511 for (
size_t i = 0; i <
size; i++)
2513 #pragma GCC diagnostic push
2514 #pragma GCC diagnostic ignored "-Wpragmas"
2515 #pragma GCC diagnostic ignored "-Wformat"
2516 #pragma GCC diagnostic ignored "-Wformat-extra-args"
2519 #pragma GCC diagnostic pop
2562 for (
size_t i = 0; i < tot_size; i++)
2564 duplicate[i] = ((
char *)array)[i];
2567 return (
void *)duplicate;
2597 for (
size_t i = 0; i <
size; ++i)
2599 if (array[i] != array2[i])
2622 for (
size_t i = 0; i <
size; ++i)
2624 if (array[i] != array2[i])
2646 for (
size_t i = 0; i <
size; ++i)
2648 if (array[i] != array2[i])
2671 for (
size_t i = 0; i <
size; ++i)
2673 if (array[i] != array2[i])
2696 for (
size_t i = 0; i <
size; ++i)
2698 if (array[i] != array2[i])
2721 for (
size_t i = 0; i <
size; ++i)
2723 if (array[i] != array2[i])
2745 for (
size_t i = 0; i <
size; ++i)
2747 if (array[i] != array2[i])
2770 for (
size_t i = 0; i <
size; ++i)
2772 if (array[i] != array2[i])
2795 for (
size_t i = 0; i <
size; ++i)
2797 if (array[i] != array2[i])
2822 for (
size_t i = 0; i <
size; ++i)
2824 if (array[i] != array2[i])
2847 for (
size_t i = 0; i <
size; ++i)
2849 if (array[i] != array2[i])
2872 for (
size_t i = 0; i <
size; ++i)
2874 if (array[i] != array2[i])
2897 for (
size_t i = 0; i <
size; ++i)
2899 if (array[i] != array2[i])
2924 for (
size_t i = 0; i <
size; ++i)
2926 if (array[i] != array2[i])
2949 for (
size_t i = 0; i <
size; ++i)
2951 if (array[i] != array2[i])
2974 for (
size_t i = 0; i <
size; ++i)
2976 if (array[i] != array2[i])
2999 for (
size_t i = 0; i <
size; ++i)
3001 if (array[i] != array2[i])
3027 for (
size_t i = 0; i <
size; ++i)
3029 if (array[i] != array2[i])
3052 for (
size_t i = 0; i <
size; ++i)
3054 if (array[i] != array2[i])
3077 for (
size_t i = 0; i <
size; ++i)
3079 if (array[i] != array2[i])
3102 for (
size_t i = 0; i <
size; ++i)
3104 if (array[i] != array2[i])
3127 for (
size_t i = 0; i <
size; ++i)
3129 if (array[i] != array2[i])
3151 for (
size_t i = 0; i <
size; ++i)
3153 if (array[i] != array2[i])
3175 for (
size_t i = 0; i <
size; ++i)
3177 if (array[i] != array2[i])
3199 for (
size_t i = 0; i <
size; ++i)
3201 if (array[i] != array2[i])
3224 for (
size_t i = 0; i <
size; ++i)
3226 if (array[i] != array2[i])
3249 size_t escaped_length = 0;
3250 size_t input_length = 0;
3254 while (input_string[input_length])
3256 if (input_string[input_length] ==
'"' || input_string[input_length] ==
'\\')
3278 json_length = escaped_length;
3286 alloc_size = json_length +
sizeof(
"");
3300 json_result[0] =
'"';
3303 for (
size_t j = 1, i = 0; i < input_length; ++i, ++j)
3308 json_result[j] =
'\\';
3313 json_result[j] = input_string[i];
3317 json_result[json_length - 1] =
'"';
3320 json_result[json_length] =
'\0';
3367 const size_t memcpy_len = end - start;
3368 size_t alloc_len = memcpy_len;
3382 result[memcpy_len] =
'\0';
3419 for (
const char *ptr =
FOUNDATIONAL_LIB_STRSTR(str, delim); ptr != NULL && (max_times == 0 || *output_size < max_times); ptr = strstr(ptr + delim_len, delim))
3437 const char *token_start;
3443 for (
size_t i = 0; i < *output_size; i++)
3450 size_t token_length = (size_t)(ptr - token_start);
3452 if (keep_delim_in_result)
3454 token_length += delim_len;
3457 const size_t alloc_len = token_length +
sizeof(
"");
3467 result[i][token_length] =
'\0';
3469 token_start = ptr + delim_len;
3484 const size_t alloc_len = token_length +
sizeof(
"");
3495 result[i][token_length] =
'\0';
3536 size_t delimeter_length;
3540 size_t total_length;
3543 for (
size_t i = 0; i < count; i++)
3547 total_length += new_len;
3550 total_length += delimeter_length;
3568 for (array_index = 0; array_index < count; ++array_index)
3570 const size_t len = lens[array_index];
3573 for (
size_t x = 0; x < len; ++x)
3575 result[len_so_far + x] = array[array_index][x];
3579 if (array_index < count - 1)
3582 for (
size_t i = 0; i < delimeter_length; ++i)
3584 result[len_so_far + i] = delimiter[i];
3586 len_so_far += delimeter_length;
3590 result[len_so_far] =
'\0';
3602 #pragma GCC diagnostic push
3603 #pragma GCC diagnostic ignored "-Wpragmas"
3604 #pragma GCC diagnostic ignored "-Wformat"
3605 #pragma GCC diagnostic ignored "-Wformat-extra-args"
3642 if (new_size > *string_alloc_size)
3653 *
string = new_string;
3654 *string_alloc_size = new_size;
3659 *string_length = *string_length + string_to_get_appended_length;
3662 (*string)[*string_length] =
'\0';
3672 #define FOUNDATIONAL_LIB_INITIAL_DATA_ARRAY_ALLOC_SIZE FOUNDATIONAL_LIB_INITIAL_STRING_ARRAY_ALLOC_SIZE
3705 if (*array_current_alloc_size == 0)
3711 *array_current_alloc_size = 0;
3734 if (mul > *array_current_alloc_size)
3746 *array_current_alloc_size = new_size_total;
3806 if (nsize > *array_current_alloc_size)
3817 *array_current_alloc_size = new_size_total;
3866 if (*array_current_alloc_size == 0)
3872 *array_current_alloc_size = 0;
3885 size_t new_size_total;
3893 if (new_size_total > *array_current_alloc_size)
3903 *array_current_alloc_size = new_size_total;
3906 (*array)[*array_size] = (
char *)
string;
3954 size_t new_size_total;
3962 if (new_size_total > *array_current_alloc_size)
3972 *array_current_alloc_size = new_size_total;
3975 (*array)[*array_size] = (
char *)
string;
4017 if (*array_current_alloc_size == 0)
4025 *array_size = *array_current_alloc_size = 0;
4038 if (new_size > *array_current_alloc_size)
4049 *array_current_alloc_size = new_size_total;
4109 if (new_size > *array_current_alloc_size)
4122 *array_current_alloc_size = new_size_total;
4157 for (
size_t i = 0; i < count; i++)
4166 #if FOUNDATIONAL_LIB_UNSAFE_FUNCTIONS_ENABLED
4190 const size_t size_with_null_t = input_len + 1;
4211 for (
size_t i = 0; i < input_len; ++i)
4214 if (input[i] ==
' ' || input[i] ==
'\t' || input[i] ==
'\n' || input[i] ==
'*' || input[i] ==
'?' || input[i] ==
'\'' || input[i] ==
'"' || input[i] ==
'\\' || input[i] ==
'$' || input[i] ==
'`' || input[i] ==
'(' || input[i] ==
')' || input[i] ==
'&' || input[i] ==
';' || input[i] ==
'|' || input[i] ==
'>' || input[i] ==
'<')
4216 escaped[j++] =
'\\';
4218 escaped[j++] = input[i];
4256 for (i = 0, j = length - 1; i < j; i++, j--)
4258 char temp = new_str[i];
4259 new_str[i] = new_str[j];
4294 static inline int ends_with(
const char *str,
const char *suffix)
4299 if (suffix_len > str_len)
4304 return strncmp(str + str_len - suffix_len, suffix, suffix_len) == 0;
4307 #if defined(__GNUC__) && !defined(_WIN32)
4311 #define memory_locate memmem
4322 return (
void *)haystack;
4330 const char *h = (
const char *)haystack;
4331 const char *n = (
const char *)needle;
4333 const size_t max_search = haystack_len - needle_len;
4334 for (
size_t i = 0; i <= max_search; ++i)
4338 return (
void *)(h + i);
4365 const char *pos = str;
4371 pos += substring_length;
4415 return beginning_of_substr_or_null != NULL;
4448 return (
const char *)
memory_locate(memory, memory_length, subchunk, subchunk_length) != NULL;
4485 #if defined(__GNUC__) && defined(__unix__)
4489 const size_t orig_string_length = string_length;
4493 const char *beginning_of_substr_or_null = (
const char *)
memmem(
string + pos, string_length, substring, substring_length);
4501 pos = beginning_of_substr_or_null -
string + substring_length;
4502 string_length = orig_string_length - pos;
4505 const char *pos = string;
4510 pos += substring_length;
4534 return result != NULL ? result - str : -1;
4555 const char *result = strrchr(str, chr);
4556 return result != NULL ? result - str : -1;
4577 for (
size_t i = 0; i < len; i++)
4608 for (
size_t i = 0; i < len; i++)
4650 for (
size_t i = 1; i < count; ++i)
4653 if (current_len < max_common_len)
4655 max_common_len = current_len;
4660 for (
size_t i = 0; i < max_common_len; ++i)
4662 for (
size_t j = 1; j < count; ++j)
4664 if (strings[j][i] != strings[0][i])
4724 return return_value;
4730 for (
size_t i = 1; i < count; ++i)
4733 if (current_len < max_common_len)
4735 max_common_len = current_len;
4740 for (
size_t i = 0; i < max_common_len; ++i)
4742 for (
size_t j = 1; j < count; ++j)
4745 if (strings[j][current_len - i - 1] != strings[0][max_common_len - i - 1])
4778 return return_value;
4796 return atof(
string);
4815 const char *result = strpbrk(str, char_set);
4840 for (ssize_t i = len - 1; i >= 0; i--)
4865 for (
size_t i = 0, j = len - 1; i < j; ++i, --j)
4892 if (*str ==
'+' || *str ==
'-')
4904 while (*str !=
'\0')
4933 const size_t min_len = (len1 < len2) ? len1 : len2;
4935 for (
size_t i = 0; i < min_len; i++)
4937 if (str1[i] != str2[i])
4963 const size_t min_len = (len1 < len2) ? len1 : len2;
4965 for (
size_t i = 1; i <= min_len; i++)
4967 if (str1[len1 - i] != str2[len2 - i])
5007 for (
size_t i = 0; i < len; i++)
5012 title_case[i] = str[i];
5016 title_case[i] = make_upper ? toupper(str[i]) : tolower(str[i]);
5021 title_case[len] =
'\0';
5046 for (
size_t i = 1; i <
size; i++)
5077 for (
size_t i = 1; i <
size; i++)
5102 for (
size_t i = 0; i <
size; ++i)
5122 for (
size_t i = 0, j =
size - 1; i < j; ++i, --j)
5124 int temp = array[i];
5125 array[i] = array[j];
5143 for (
size_t i = 1; i <
size; ++i)
5145 if (array[i] < array[i - 1])
5166 for (
size_t i = 1; i <
size; ++i)
5168 if (array[i] > array[i - 1])
5198 const size_t size = (end - start) / step + 1;
5222 for (
size_t i = 0, value = start; i <
size; ++i, value += step)
5280 char **dup_strings = (
char **)
arraydup(strings,
size,
sizeof(
char *));
5307 return (*(
unsigned int *)a - *(
unsigned int *)b);
5342 unsigned int *dup_uints = (
unsigned int *)
arraydup(uints,
size,
sizeof(
unsigned int));
5368 return (*(
unsigned int **)a - *(
unsigned int **)b);
5406 unsigned int **dup_uint_ptrs = (
unsigned int **)
arraydup(uint_ptrs,
size,
sizeof(
unsigned int *));
5412 return dup_uint_ptrs;
5434 return (*(
int *)a - *(
int *)b);
5470 int *dup_ints = (
int *)
arraydup(ints,
size,
sizeof(
int));
5498 return (*(
int **)a - *(
int **)b);
5533 int **dup_int_ptrs = (
int **)
arraydup(int_ptrs,
size,
sizeof(
int *));
5539 return dup_int_ptrs;
5558 return (*(
unsigned char *)a - *(
unsigned char *)b);
5594 unsigned char *dup_uchars = (
unsigned char *)
arraydup(uchars,
size,
sizeof(
unsigned char));
5621 return (*(
unsigned char **)a - *(
unsigned char **)b);
5658 unsigned char **dup_uchar_ptrs = (
unsigned char **)
arraydup(uchar_ptrs,
size,
sizeof(
unsigned char *));
5664 return dup_uchar_ptrs;
5683 return (*(
char *)a - *(
char *)b);
5716 char *dup_chars = (
char *)
arraydup(chars,
size,
sizeof(
char));
5742 return (*(
char **)a - *(
char **)b);
5777 char **dup_char_ptrs = (
char **)
arraydup(char_ptrs,
size,
sizeof(
char *));
5785 return dup_char_ptrs;
5805 return (*(
unsigned short *)a - *(
unsigned short *)b);
5841 unsigned short *dup_ushorts = (
unsigned short *)
arraydup(ushorts,
size,
sizeof(
unsigned short));
5872 return (*(
unsigned short **)a - *(
unsigned short **)b);
5911 unsigned short **dup_ushort_ptrs = (
unsigned short **)
arraydup(ushort_ptrs,
size,
sizeof(
unsigned short *));
5918 return dup_ushort_ptrs;
5937 return (*(
short *)a - *(
short *)b);
5971 short *dup_shorts = (
short *)
arraydup(shorts,
size,
sizeof(
short));
5999 return (*(
short **)a - *(
short **)b);
6035 short **dup_short_ptrs = (
short **)
arraydup(short_ptrs,
size,
sizeof(
short *));
6043 return dup_short_ptrs;
6062 return (*(
unsigned long *)a - *(
unsigned long *)b);
6096 unsigned long *dup_ulongs = (
unsigned long *)
arraydup(ulongs,
size,
sizeof(
unsigned long));
6126 return (*(
unsigned long **)a - *(
unsigned long **)b);
6165 unsigned long **dup_ulong_ptrs = (
unsigned long **)
arraydup(ulong_ptrs,
size,
sizeof(
unsigned long *));
6172 return dup_ulong_ptrs;
6194 return (*(
long *)a - *(
long *)b);
6235 long *dup_longs = (
long *)
arraydup(longs,
size,
sizeof(
long));
6262 return (*(
long **)a - *(
long **)b);
6295 long **dup_long_ptrs = (
long **)
arraydup(long_ptrs,
size,
sizeof(
long *));
6302 return dup_long_ptrs;
6321 return (*(
unsigned long long *)a - *(
unsigned long long *)b);
6355 unsigned long long *dup_ulong_longs = (
unsigned long long *)
arraydup(ulong_longs,
size,
sizeof(
unsigned long long));
6362 return dup_ulong_longs;
6384 return (*(
unsigned long long **)a - *(
unsigned long long **)b);
6421 unsigned long long **dup_ulong_long_ptrs = (
unsigned long long **)
arraydup(ulong_long_ptrs,
size,
sizeof(
unsigned long long *));
6428 return dup_ulong_long_ptrs;
6447 return (*(
long long *)a - *(
long long *)b);
6478 long long *dup_long_longs = (
long long *)
arraydup(long_longs,
size,
sizeof(
long long));
6486 return dup_long_longs;
6505 return (*(
long long **)a - *(
long long **)b);
6543 long long **dup_long_long_ptrs = (
long long **)
arraydup(long_long_ptrs,
size,
sizeof(
long long *));
6550 return dup_long_long_ptrs;
6569 return (*(
float *)a - *(
float *)b);
6603 float *dup_floats = (
float *)
arraydup(floats,
size,
sizeof(
float));
6629 return (*(
float **)a - *(
float **)b);
6665 float **dup_float_ptrs = (
float **)
arraydup(float_ptrs,
size,
sizeof(
float *));
6672 return dup_float_ptrs;
6692 return (*(
double *)a - *(
double *)b);
6725 double *dup_doubles = (
double *)
arraydup(doubles,
size,
sizeof(
double));
6750 return (*(
double **)a - *(
double **)b);
6787 double **dup_double_ptrs = (
double **)
arraydup(double_ptrs,
size,
sizeof(
double *));
6793 return dup_double_ptrs;
6813 return (*(
size_t *)a - *(
size_t *)b);
6849 size_t *dup_size_ts = (
size_t *)
arraydup(size_ts,
size,
sizeof(
size_t));
6874 return (*(
size_t **)a - *(
size_t **)b);
6912 size_t **dup_size_t_ptrs = (
size_t **)
arraydup(size_t_ptrs,
size,
sizeof(
size_t *));
6921 return dup_size_t_ptrs;
6964 FILE *file = fopen(filename,
"rb");
6988 *
size = (size_t)file_size;
7011 size_t total_read = 0;
7012 const size_t file_size_size_t = (size_t)file_size;
7014 while (total_read < file_size_size_t)
7034 total_read += read_size;
7038 content[total_read] =
'\0';
7070 FILE *file = fopen(filename, mode);
7079 size_t total_written = 0;
7082 while ((write_size =
FOUNDATIONAL_LIB_FWRITE(content + total_written, 1, content_length - total_written, file)) > 0)
7084 total_written += write_size;
7147 #include <sys/stat.h>
7162 return _access(filename, 0) == 0;
7164 return access(filename, F_OK) == 0;
7183 if (stat(filename, &st) == 0)
7184 return (st.st_mode & _S_IFREG) != 0;
7186 if (stat(filename, &st) == 0)
7187 return S_ISREG(st.st_mode);
7206 if (stat(filename, &st) == 0)
7207 return (st.st_mode & _S_IFDIR) != 0;
7209 if (stat(filename, &st) == 0)
7210 return S_ISDIR(st.st_mode);
7230 return _access(filename, 4) == 0;
7232 return access(filename, R_OK) == 0;
7251 return _access(filename, 2) == 0;
7253 return access(filename, W_OK) == 0;
7272 return _access(filename, 1) == 0;
7274 return access(filename, X_OK) == 0;
7295 FILE *file = fopen(filename,
"r");
7311 const off_t file_size = ftello(file);
7369 FILE *source_file = fopen(source_filename,
"rb");
7377 FILE *destination_file = fopen(destination_filename,
"wb");
7428 size_t write_size = 0;
7429 size_t new_write_size;
7433 write_size += new_write_size;
7458 #include <windows.h>
7486 char search_path[MAX_PATH];
7487 FOUNDATIONAL_LIB_SNPRINTF(search_path, MAX_PATH,
"%s\\%s", directory, pattern);
7489 WIN32_FIND_DATA find_file_data;
7490 HANDLE find_handle = FindFirstFile(search_path, &find_file_data);
7505 if (!(find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
7509 }
while (FindNextFile(find_handle, &find_file_data) != 0);
7538 find_handle = FindFirstFile(search_path, &find_file_data);
7541 if (!(find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
7550 }
while (FindNextFile(find_handle, &find_file_data) != 0);
7567 #include <fnmatch.h>
7595 DIR *dir = opendir(directory);
7604 struct dirent *entry;
7605 while ((entry = readdir(dir)) != NULL)
7607 if (fnmatch(pattern, entry->d_name, FNM_PERIOD) == 0)
7632 while ((entry = readdir(dir)) != NULL)
7634 if (fnmatch(pattern, entry->d_name, FNM_PERIOD) == 0)
7692 for (
size_t i = 0; i < num_strings; ++i)
7694 const char *current_string = strings[i];
7697 size_t current_length_of_current_string = 0;
7698 while (current_string[current_length_of_current_string] !=
'\0')
7722 result = new_result;
7726 result[new_len++] = current_string[current_length_of_current_string++];
7731 result[new_len] =
'\0';
7760 const char *strs[2] = {str1, str2};
7805 FOUNDATIONAL_LIB_FUNC int replace_memory(
void *source,
size_t source_len,
void *find,
size_t find_len,
void *replace,
size_t replace_len,
void **output,
size_t *output_length_without_nullt,
int *should_free_after_use,
size_t matches_max ,
size_t *num_matches_found,
int should_nullt)
7825 p = (
const char *)source;
7827 const char *end_of_memory;
7828 end_of_memory = (
const char *)source + source_len;
7832 if ((p = (
const char *)
memory_locate((
const void *)p, (end_of_memory - p), find, find_len)) == NULL)
7834 if (matches_max && matches == matches_max)
7846 *should_free_after_use = 0;
7847 *output_length_without_nullt = source_len;
7852 *should_free_after_use = 1;
7853 *num_matches_found = matches;
7855 size_t final_len = source_len - matches * find_len + matches * replace_len;
7870 *output_length_without_nullt = final_len;
7879 p = (
const char *)source;
7884 for (matches = 0; !matches_max || (matches < matches_max); ++matches)
7886 if ((p = (
const char *)
memory_locate((
const void *)p, end_of_memory - p, find, find_len)) == NULL)
7889 if (matches_max && matches == matches_max)
7892 size_t prefix_len = p - (
const char *)source;
7902 size_t remaining_len;
7904 remaining_len = end_of_memory - (
const char *)source;
7909 rp[remaining_len] =
'\0';
7916 *output_length_without_nullt = 0;
7962 FOUNDATIONAL_LIB_FUNC int replace_all_with_lens(
const char *source,
size_t source_len,
const char *find,
size_t find_len,
const char *replace,
size_t replace_len,
char **output,
size_t *new_len,
int *should_free_after_use,
size_t matches_max,
size_t *num_matches)
7965 return replace_memory((
void *)source, source_len, (
void *)find, find_len, (
void *)replace, replace_len, (
void **)output, new_len, should_free_after_use, matches_max, num_matches, 1);
7988 int should_free_after_use;
7990 const size_t matches_max = 0;
7992 if (
replace_memory((
void *)source, strlen(source), (
void *)find, strlen(find), (
void *)replace, strlen(replace), (
void **)&output, &new_len, &should_free_after_use, matches_max, &num_matches, 1) == -1)
7998 if (!should_free_after_use)
8007 memcpy(new_output, output, new_len + 1);
8034 int should_free_after_use;
8036 const size_t matches_max = 1;
8038 if (
replace_memory((
void *)source, strlen(source), (
void *)find, strlen(find), (
void *)replace, strlen(replace), (
void **)&output, &new_len, &should_free_after_use, matches_max, &num_matches, 1) == -1)
8044 if (!should_free_after_use)
8053 memcpy(new_output, output, new_len + 1);
8080 int should_free_after_use;
8082 if (
replace_memory((
void *)source, strlen(source), (
void *)find, strlen(find), (
void *)replace, strlen(replace), (
void **)&output, &new_len, &should_free_after_use, matches_max, &num_matches, 1) == -1)
8088 if (!should_free_after_use)
8097 memcpy(new_output, output, new_len + 1);
8128 const size_t str_len = strlen(str);
8129 const size_t old_substring_len = strlen(old_substring);
8130 size_t alloc_size = str_len + 1;
8141 const char *pos = str;
8147 const char *found_pos = (
const char *)
memory_locate(pos, str_len - (pos - str), old_substring, old_substring_len);
8150 size_t remaining_len = str_len - (pos - str);
8151 memcpy(result + new_len, pos, remaining_len);
8152 new_len += remaining_len;
8154 result[new_len] =
'\0';
8156 new_len += remaining_len;
8162 char *replacement = callback(old_substring, data_for_callback);
8165 size_t replacement_len = strlen(replacement);
8169 const size_t diff = found_pos - pos;
8181 if (nlen >= alloc_size)
8191 result = new_result;
8194 memcpy(result + new_len, pos, found_pos - pos);
8195 new_len += found_pos - pos;
8196 memcpy(result + new_len, replacement, replacement_len);
8198 new_len += replacement_len;
8199 pos = found_pos + old_substring_len;
8300 for (
size_t i = 0; i < size; i++)
8302 array[i] = transform(array[i]);
8342 int result = array[0];
8343 for (
size_t i = 1; i < size; i++)
8345 result = operation(result, array[i]);
8396 for (
size_t i = 0; i < source_size; i++)
8398 if (condition(source[i]))
8400 destination[count++] = source[i];
8441 for (
size_t i = 0; i < size; i++)
8443 transform(((
char *)array) + i * elem_size);
8487 char *char_array = (
char *)array;
8488 char *char_result = (
char *)result;
8491 for (
size_t i = 0; i < elem_size; i++)
8493 char_result[i] = char_array[i];
8496 for (
size_t i = 1; i < size; i++)
8498 operation(char_result, char_array + i * elem_size);
8543 FOUNDATIONAL_LIB_FUNC size_t filter(
void *source,
size_t source_size,
size_t elem_size,
void *destination,
size_t dest_size,
int (*condition)(
void *))
8550 char *char_source = (
char *)source;
8551 char *char_destination = (
char *)destination;
8554 for (
size_t i = 0; i < source_size; i++)
8556 if (condition(char_source + i * elem_size))
8558 if (count < dest_size)
8560 for (
size_t j = 0; j < elem_size; j++)
8562 char_destination[count * elem_size + j] = char_source[i * elem_size + j];
8690 for (
size_t i = 0; i < array_size; ++i)
8696 if (filter_func((
void *)((
char *)input_array + i * elem_size)))
8700 void *addr = (
char *)result + (*result_size) * elem_size;
8702 transform_func(addr);
8714 #pragma GCC diagnostic push
8715 #pragma GCC diagnostic ignored "-Wpragmas"
8716 #pragma GCC diagnostic ignored "-Wuse-after-free"
8732 #pragma GCC diagnostic pop
8796 #if FOUNDATIONAL_LIB_THREAD_FUNCTIONS_ENABLED
8797 #include <threads.h>
8858 for (
size_t i = 0; i < (*thread_data->
result_size); ++i)
8863 thread_data->
result = buffer;
8972 cannot_allocate_or_create:
8983 size_t chunk_size =
array_size / thread_count;
8984 size_t remaining =
array_size % thread_count;
8985 size_t current_index = 0;
8987 for (
size_t i = 0; i < thread_count; ++i)
8993 goto cannot_allocate_or_create;
9000 thread_data[i].
result_size = &thread_result_sizes[i];
9010 current_index = thread_data[i].
end_index;
9014 goto cannot_allocate_or_create;
9018 for (
size_t i = 0; i < thread_count; ++i)
9020 int return_value_of_thread;
9021 thrd_join(threads[i], &return_value_of_thread);
9025 goto cannot_allocate_or_create;
9028 size_t total_result_size = 0;
9029 for (
size_t i = 0; i < thread_count; ++i)
9035 total_result_size += thread_result_sizes[i];
9092 size_t result_index = 0;
9095 for (
size_t i = 0; i < source_size; ++i)
9098 const void *current_source = (
char *)source + i *
elem_size;
9101 if (!condition(current_source))
9158 size_t result_index = 0;
9161 for (
size_t i = 0; i < source_size; ++i)
9163 const void *current_source = (
char *)source + i *
elem_size;
9166 if (condition(current_source))
9225 for (
size_t i = 0; i < repetitions; ++i)
9260 char *orig_str = new_str;
9263 *new_str = tolower(*new_str);
9294 char *orig_str = new_str;
9297 *new_str = toupper(*new_str);
9502 for (
size_t i = 0; i < size; ++i)
9504 const char *str = array[i];
9532 for (
size_t i = 0; i < size; ++i)
9534 const char *str = array[i];
9563 for (
size_t i = 0; i < size; ++i)
9565 const char *str = array[i];
9644 for (
size_t i = 0; i < size; i++)
9646 (*output)[i] = NULL;
9650 for (
size_t i = 0; i < size; i++)
9655 for (
size_t j = 0; j < count; j++)
9666 (*output)[count] = ((
char **)array)[i];
9673 *output_size = count;
9743 for (
size_t i = 0; i < size; ++i)
9747 (*new_array)[(*new_size)++] = (
char *)first_array[i];
9776 const char *strs[3] = {str1, str2, str3};
9805 const char *strs[4] = {str1, str2, str3, str4};
9836 const char *strs[5] = {str1, str2, str3, str4, str5};
9843 #include <windows.h>
9849 #define FOUNDATIONAL_LIB_DIR_SEPARATOR '\\'
9851 #define FOUNDATIONAL_LIB_DIR_SEPARATOR '/'
9884 WIN32_FIND_DATA findFileData;
9885 HANDLE hFind = FindFirstFile(directory, &findFileData);
9895 if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
9902 char fullFilePath[MAX_PATH];
9914 const char *new_str = map_function(file_data, size);
9931 }
while (FindNextFile(hFind, &findFileData) != 0);
9940 DIR *dir = opendir(directory);
9947 struct dirent *entry;
9948 while ((entry = readdir(dir)) != NULL)
9950 if (entry->d_type == DT_REG)
9956 char fullFilePath[PATH_MAX];
9967 const char *new_str = map_function(file_data, size);
10015 WIN32_FIND_DATA findFileData;
10016 HANDLE hFind = FindFirstFile(directory, &findFileData);
10026 if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !filter_function(findFileData.cFileName))
10029 char fullFilePath[MAX_PATH];
10035 if (FindClose(hFind) == 0)
10044 }
while (FindNextFile(hFind, &findFileData) != 0);
10049 DIR *dir = opendir(directory);
10056 struct dirent *entry;
10057 while ((entry = readdir(dir)) != NULL)
10059 if (entry->d_type == DT_REG)
10061 if (!filter_function(entry->d_name))
10064 char fullFilePath[PATH_MAX];
10070 if (closedir(dir) == -1)
10118 WIN32_FIND_DATA findFileData;
10119 HANDLE hFind = FindFirstFile(directory, &findFileData);
10127 char *last_value = NULL;
10128 char *value = NULL;
10132 if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && findFileData.dwFileAttributes & FILE_ATTRIBUTE_NORMAL)
10138 char fullFilePath[MAX_PATH];
10149 char *new_value = reduce_function(last_value, value, findFileData.cFileName);
10156 last_value = new_value;
10165 }
while (FindNextFile(hFind, &findFileData) != 0);
10173 DIR *dir = opendir(directory);
10180 char *last_value = NULL;
10181 char *value = NULL;
10182 struct dirent *entry;
10184 while ((entry = readdir(dir)) != NULL)
10186 if (entry->d_type == DT_REG)
10192 char fullFilePath[PATH_MAX];
10207 char *new_value = reduce_function(last_value, value, entry->d_name);
10214 last_value = new_value;
10255 for (
size_t i = 0; i < dict->
capacity; ++i)
10258 while (current_pair != NULL)
10263 current_pair = next_pair;
10288 size_t hash = 5381;
10291 while ((c = *
key++))
10293 hash = ((hash << 5) + hash) + c;
10296 return hash % capacity;
10338 for (
size_t i = 0; i < dict->
capacity; ++i)
10341 while (current_pair)
10344 const size_t new_index =
dict_hash(current_pair->
key, new_capacity);
10345 current_pair->
next = new_table[new_index];
10346 new_table[new_index] = current_pair;
10347 current_pair = next_pair;
10352 dict->
table = new_table;
10393 for (
size_t i = 0; i < dict->
capacity; ++i)
10396 while (current_pair)
10399 const size_t new_index =
dict_hash(current_pair->
key, new_capacity);
10400 current_pair->
next = new_table[new_index];
10401 new_table[new_index] = current_pair;
10402 current_pair = next_pair;
10407 dict->
table = new_table;
10433 while (current != NULL)
10460 current = current->
next;
10513 if (dict->
table[index] != NULL)
10534 current = current->
next;
10535 }
while (current != NULL);
10540 dict->
table[index] = new_pair;
10567 while (current_pair != NULL)
10571 return current_pair->
value;
10575 current_pair = current_pair->
next;
10608 while (current_pair != NULL)
10612 *key_is_in_dict = 1;
10613 return current_pair->
value;
10615 current_pair = current_pair->
next;
10618 *key_is_in_dict = 0;
10662 frozen_dict->
size = 0;
10674 for (
size_t i = 0; i < num_pairs; ++i)
10687 return frozen_dict;
10711 while (current_pair != NULL)
10715 return current_pair->
value;
10717 current_pair = current_pair->
next;
10749 while (current_pair != NULL)
10753 *key_is_in_dict = 1;
10754 return current_pair->
value;
10756 current_pair = current_pair->
next;
10759 *key_is_in_dict = 0;
10781 for (
size_t i = 0; i < dict->
capacity; ++i)
10785 while (current != NULL)
10788 callback(current->
key, current->
value);
10791 current = current->
next;
10813 for (
size_t i = 0; i < frozen_dict->
capacity; ++i)
10817 while (current != NULL)
10820 callback(current->
key, current->
value);
10823 current = current->
next;
10893 size_t alloc_size2;
10901 goto error_handler;
10910 goto error_handler;
10913 for (
size_t i = 0, index = 0; i < dict->
capacity; ++i)
10916 while (current_pair != NULL)
10918 (*keys)[index] = (current_pair->
key);
10919 (*values)[index] = current_pair->
value;
10922 current_pair = current_pair->
next;
10926 *size_of_keys_and_values = dict->
size;
10970 size_t alloc_size2;
10978 goto error_handler;
10987 goto error_handler;
10990 for (
size_t i = 0, index = 0; i < dict->
capacity; ++i)
10993 while (current_pair != NULL)
10995 (*keys)[index] = (current_pair->
key);
10996 (*values)[index] = current_pair->
value;
10999 current_pair = current_pair->
next;
11003 *size_of_keys_and_values = dict->
size;
11071 size_t total_length = 2;
11072 for (
size_t i = 0; i < dict->
capacity; ++i)
11075 while (current_pair != NULL)
11080 if (pointer_or_string == 0)
11082 total_length += FOUNDATIONAL_LIB_SNPRINTF(NULL, 0,
"%p",
11083 current_pair->
value);
11087 total_length += FOUNDATIONAL_LIB_SNPRINTF(NULL, 0,
"%s",
11088 (
char *)current_pair->
value);
11091 current_pair = current_pair->
next;
11108 for (
size_t i = 0; i < dict->
capacity; ++i)
11111 while (current_pair != NULL)
11114 if (pointer_or_string == 0)
11116 index += FOUNDATIONAL_LIB_SNPRINTF(result + index, total_length - index,
"%s: %p", current_pair->
key, current_pair->
value);
11118 else if (pointer_or_string == 1)
11120 index += FOUNDATIONAL_LIB_SNPRINTF(result + index, total_length - index,
"%s: %s", current_pair->
key, (
char *)current_pair->
value);
11122 current_pair = current_pair->
next;
11125 if (index < total_length - 2)
11127 result[index++] =
',';
11128 result[index++] =
' ';
11138 result[index++] =
'}';
11139 result[index++] =
'\0';
11167 size_t total_length = 2;
11168 for (
size_t i = 0; i < dict->
capacity; ++i)
11171 while (current_pair != NULL)
11177 if (pointer_or_string == 0)
11179 total_length += FOUNDATIONAL_LIB_SNPRINTF(NULL, 0,
"%p",
11180 current_pair->
value);
11184 total_length += FOUNDATIONAL_LIB_SNPRINTF(NULL, 0,
"%s",
11185 (
char *)current_pair->
value);
11188 current_pair = current_pair->
next;
11205 for (
size_t i = 0; i < dict->
capacity; ++i)
11208 while (current_pair != NULL)
11211 if (pointer_or_string == 0)
11213 index += FOUNDATIONAL_LIB_SNPRINTF(result + index, total_length - index,
"%s: %p", current_pair->
key, current_pair->
value);
11215 else if (pointer_or_string == 1)
11217 index += FOUNDATIONAL_LIB_SNPRINTF(result + index, total_length - index,
"%s: %s", current_pair->
key, (
char *)current_pair->
value);
11219 current_pair = current_pair->
next;
11222 if (index < total_length - 2)
11224 result[index++] =
',';
11225 result[index++] =
' ';
11235 result[index++] =
'}';
11236 result[index++] =
'\0';
11279 for (
size_t i = 0; i < set->
capacity; ++i)
11282 while (current_key != NULL)
11284 struct SetKey *next_key = current_key->
next;
11287 current_key = next_key;
11340 size_t hash = 5381;
11343 while ((c = *
key++))
11345 hash = ((hash << 5) + hash) + c;
11348 return hash % capacity;
11380 for (
size_t i = 0; i < set->
capacity; ++i)
11383 while (current_key)
11385 struct SetKey *next_key = current_key->
next;
11386 const size_t new_index =
set_hash(current_key->
key, new_capacity);
11387 current_key->
next = new_table[new_index];
11388 new_table[new_index] = current_key;
11389 current_key = next_key;
11394 set->
table = new_table;
11416 struct SetKey *prev = NULL;
11418 while (current != NULL)
11445 current = current->
next;
11494 if (set->
table[index] != NULL)
11497 struct SetKey *prev = new_set_key;
11519 current = current->
next;
11520 }
while (current != NULL);
11525 set->
table[index] = new_set_key;
11565 for (
size_t i = 0; i < set->
capacity; ++i)
11568 while (current_key)
11570 struct SetKey *next_key = current_key->
next;
11571 const size_t new_index =
set_hash(current_key->
key, new_capacity);
11572 current_key->
next = new_table[new_index];
11573 new_table[new_index] = current_key;
11574 current_key = next_key;
11579 set->
table = new_table;
11602 while (current_key != NULL)
11608 current_key = current_key->
next;
11647 frozen_set->
size = 0;
11659 for (
size_t i = 0; i < num_args; ++i)
11688 while (current_key != NULL)
11694 current_key = current_key->
next;
11713 for (
size_t i = 0; i < set->
capacity; ++i)
11717 while (current != NULL)
11720 callback(current->
key);
11723 current = current->
next;
11780 goto error_handler;
11782 for (
size_t i = 0, index = 0; i < set->
capacity; ++i)
11785 while (current_pair != NULL)
11787 (*keys)[index] = (current_pair->
key);
11790 current_pair = current_pair->
next;
11794 *size_of_keys = set->
size;
11829 goto error_handler;
11831 for (
size_t i = 0, index = 0; i < set->
capacity; ++i)
11834 while (current_pair != NULL)
11836 (*keys)[index] = (current_pair->
key);
11839 current_pair = current_pair->
next;
11843 *size_of_keys = set->
size;
11870 size_t total_length = 2;
11871 for (
size_t i = 0; i < set->
capacity; ++i)
11874 while (current_key != NULL)
11880 current_key = current_key->
next;
11899 for (
size_t i = 0; i < set->
capacity; ++i)
11902 while (current_key != NULL)
11905 index += FOUNDATIONAL_LIB_SNPRINTF(result + index, total_length - index,
"%s", current_key->
key);
11906 current_key = current_key->
next;
11909 if (index < total_length - 2)
11911 result[index++] =
',';
11912 result[index++] =
' ';
11921 result[index++] =
'}';
11922 result[index++] =
'\0';
11944 size_t total_length = 2;
11945 for (
size_t i = 0; i < frozen_set->
capacity; ++i)
11947 struct SetKey *current_key = frozen_set->
table[i];
11948 while (current_key != NULL)
11954 current_key = current_key->
next;
11971 for (
size_t i = 0; i < frozen_set->
capacity; ++i)
11973 struct SetKey *current_key = frozen_set->
table[i];
11974 while (current_key != NULL)
11977 index += FOUNDATIONAL_LIB_SNPRINTF(result + index, total_length - index,
"%s", current_key->
key);
11978 current_key = current_key->
next;
11981 if (index < total_length - 2)
11983 result[index++] =
',';
11984 result[index++] =
' ';
11994 result[index++] =
'}';
11995 result[index++] =
'\0';
12027 for (
size_t i = 0; i < set->
capacity; ++i)
12031 while (current_key != NULL)
12034 callback(current_key->
key);
12037 current_key = current_key->
next;
12059 if ((str[i] & 0x80) == 0)
12064 else if ((str[i] & 0xE0) == 0xC0)
12067 if (i + 1 >= len || (str[i + 1] & 0xC0) != 0x80)
12071 else if ((str[i] & 0xF0) == 0xE0)
12074 if (i + 2 >= len || (str[i + 1] & 0xC0) != 0x80 || (str[i + 2] & 0xC0) != 0x80)
12078 else if ((str[i] & 0xF8) == 0xF0)
12081 if (i + 3 >= len || (str[i + 1] & 0xC0) != 0x80 || (str[i + 2] & 0xC0) != 0x80 || (str[i + 3] & 0xC0) != 0x80)
12111 unsigned int rand_val;
12112 if (rand_s(&rand_val) != 0)
12118 j = rand_val % size;
12119 #elif defined(__linux__)
12120 j = (long)(drand48() * size);
12141 for (
size_t i = size - 1; i; --i)
12145 unsigned int rand_val;
12152 j = rand_val % (i + 1);
12153 #elif defined(__linux__)
12154 j = (long)(drand48() * (i + 1));
12156 j = rand() % (i + 1);
12160 char *temp = strings[i];
12161 strings[i] = strings[j];
12179 const signed long long range = max - min + 1;
12182 unsigned int rand_val;
12183 if (rand_s(&rand_val) != 0)
12189 return min + (rand_val % range);
12190 #elif defined(__linux__)
12191 return min + (long)(drand48() * range);
12193 return min + (rand() % range);
12208 const unsigned long range = max - min + 1;
12211 unsigned int rand_val;
12212 if (rand_s(&rand_val) != 0)
12218 return min + (rand_val % range);
12219 #elif defined(__linux__)
12220 return min + (
unsigned long)(drand48() * range);
12222 return min + (rand() % range);
12226 #if FOUNDATIONAL_LIB_UNSAFE_FUNCTIONS_ENABLED
12270 size_t total_read = 0;
12292 else if (total_read + read_size + 1 > output_size)
12321 output = new_output;
12323 total_read += read_size;
12338 output[total_read] =
'\0';
12340 *size = total_read;
12381 size_t size_of_file;
12410 char **lines =
split(file, num_lines, delim, 0, 1);
12535 #pragma GCC diagnostic push
12536 #pragma GCC diagnostic ignored "-Wpragmas"
12537 #pragma GCC diagnostic ignored "-Wformat"
12538 #pragma GCC diagnostic ignored "-Wformat-extra-args"
12541 #pragma GCC diagnostic pop
12579 #pragma GCC diagnostic push
12580 #pragma GCC diagnostic ignored "-Wpragmas"
12581 #pragma GCC diagnostic ignored "-Wformat"
12582 #pragma GCC diagnostic ignored "-Wformat-extra-args"
12584 #pragma GCC diagnostic pop
12676 #pragma GCC diagnostic push
12677 #pragma GCC diagnostic ignored "-Wpragmas"
12678 #pragma GCC diagnostic ignored "-Wformat"
12679 #pragma GCC diagnostic ignored "-Wformat-extra-args"
12681 #pragma GCC diagnostic pop
12693 #pragma GCC diagnostic push
12694 #pragma GCC diagnostic ignored "-Wpragmas"
12695 #pragma GCC diagnostic ignored "-Wformat"
12696 #pragma GCC diagnostic ignored "-Wformat-extra-args"
12698 #pragma GCC diagnostic pop
12741 for (
size_t i = 0; i < array_length; ++i)
12774 for (
size_t i = 0; i < array_length; ++i)
12808 for (
size_t i = 0; i < array_length; ++i)
12820 #if FOUNDATIONAL_LIB_NETWORK_FUNCTIONS_ENABLED
12824 #define FOUNDATIONAL_LIB_DEFAULT_USER_AGENT "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"
12826 #include <curl/curl.h>
12829 FOUNDATIONAL_LIB_FUNC size_t FOUNDATIONAL_LIB_libcurl_write_callback(
char *data,
size_t n,
size_t l,
void *userp)
12842 size_t byte_max_cutoff;
12845 const size_t both = n * l;
12848 if (string->byte_max_cutoff != 0 && string->size >= string->byte_max_cutoff)
12896 FOUNDATIONAL_LIB_FUNC int download_website(
const char *website,
char **
string,
size_t *size,
size_t *str_alloc_size,
size_t byte_max_cutoff,
const char *user_agent)
12904 CURL *curl = curl_easy_init();
12910 if (user_agent == NULL)
12912 user_agent = FOUNDATIONAL_LIB_DEFAULT_USER_AGENT;
12915 curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 102400L);
12916 curl_easy_setopt(curl, CURLOPT_URL, website);
12917 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
12918 curl_easy_setopt(curl, CURLOPT_USERAGENT, user_agent);
12919 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
12920 curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
12921 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (
long)CURL_HTTP_VERSION_2TLS);
12922 curl_easy_setopt(curl, CURLOPT_FTP_SKIP_PASV_IP, 1L);
12923 curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
12929 size_t byte_max_cutoff;
12932 data.alloc_size = FOUNDATIONAL_LIB_INITIAL_NETWORK_DOWNLOAD_BUFFER_SIZE;
12934 data.byte_max_cutoff = byte_max_cutoff;
12936 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, FOUNDATIONAL_LIB_libcurl_write_callback);
12937 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);
12938 CURLcode curlcode = curl_easy_perform(curl);
12940 curl_easy_cleanup(curl);
12942 *
string = data.string;
12944 *str_alloc_size = data.alloc_size;
12946 return curlcode == CURLE_OK;
12969 FOUNDATIONAL_LIB_FUNC int download_websites(
const char **websites_to_download,
size_t num_websites,
char ***outputs,
size_t **lens,
size_t byte_limit,
int aggressive_stop_on_error)
12981 for (
size_t i = 0; i < num_websites; ++i)
12984 if (download_website(websites_to_download[i], (*outputs) + i, (*lens) + i, &alloc_size, byte_limit, NULL) == -1)
12986 if (aggressive_stop_on_error)
13039 for (
size_t i = 0; i < num_files; ++i)
13046 if ((*outputs)[i] == NULL)
13048 if (aggressive_stop_on_error)
13059 #pragma GCC diagnostic pop
FOUNDATIONAL_LIB_FUNC int is_string_printable(const char *string)
Check if all characters in a string are printable.
Definition: foundationallib.h:9456
FOUNDATIONAL_LIB_FUNC void sort_long_long_ptrs(long long **long_long_ptrs, size_t size)
Sorts an array of pointers to long longs in ascending order.
Definition: foundationallib.h:6518
FOUNDATIONAL_LIB_FUNC int is_string_valid_integer(const char *str)
Checks if a string is a valid integer.
Definition: foundationallib.h:4882
FOUNDATIONAL_LIB_FUNC size_t frozen_dict_size(struct FrozenDict *dict)
Returns the number of key-value pairs in the frozen dictionary.
Definition: foundationallib.h:10854
FOUNDATIONAL_LIB_FUNC void print_ushort_array(const unsigned short *array, size_t size)
Prints the contents of an array of unsigned short integers.
Definition: foundationallib.h:1284
FOUNDATIONAL_LIB_FUNC int shuffle_strings_in_place(char **strings, size_t size)
Shuffles an array of strings in place.
Definition: foundationallib.h:12137
FOUNDATIONAL_LIB_FUNC unsigned int ** sorted_uint_ptrs(unsigned int **uint_ptrs, size_t size)
Definition: foundationallib.h:5401
FOUNDATIONAL_LIB_FUNC size_t frozen_dict_to_array(struct FrozenDict *dict, char ***keys, void ***values, size_t *size_of_keys_and_values)
Converts the key-value pairs from the frozen dictionary into separate arrays for keys and values.
Definition: foundationallib.h:10959
FOUNDATIONAL_LIB_FUNC void print_ulong_long_array(const unsigned long long *array, size_t size)
Prints the elements of an unsigned long long array.
Definition: foundationallib.h:1536
FOUNDATIONAL_LIB_FUNC unsigned long long * sorted_ulong_longs(unsigned long long *ulong_longs, size_t size)
Creates a new array containing sorted unsigned long longs.
Definition: foundationallib.h:6352
FOUNDATIONAL_LIB_FUNC unsigned char * sorted_uchars(unsigned char *uchars, size_t size)
Creates a new array containing sorted unsigned chars.
Definition: foundationallib.h:5590
static int equal_array_of_long_longs(const long long *array, const long long *array2, size_t size)
Checks if two arrays of long long integers are equal.
Definition: foundationallib.h:3050
#define FOUNDATIONAL_LIB_STRCHR
Definition: foundationallib.h:341
FOUNDATIONAL_LIB_FUNC void print_string_array(char **array, size_t size)
Prints an array of strings.
Definition: foundationallib.h:1229
#define FOUNDATIONAL_LIB_FUNC
Definition: foundationallib.h:821
FOUNDATIONAL_LIB_FUNC char * replace_all(const char *source, const char *find, const char *replace)
Replaces all occurrences of a specified substring in a given string.
Definition: foundationallib.h:7982
FOUNDATIONAL_LIB_FUNC int string_to_int(const char *str)
Converts a string to an integer.
Definition: foundationallib.h:6934
static void dict_del_keys(char **keys)
Deallocates memory associated with an array of keys.
Definition: foundationallib.h:11024
FOUNDATIONAL_LIB_FUNC unsigned long * sorted_ulongs(unsigned long *ulongs, size_t size)
Creates a new array containing sorted unsigned longs.
Definition: foundationallib.h:6093
FOUNDATIONAL_LIB_FUNC void print_float_ptr_array_to_stream(const float **array, size_t size, FILE *stream)
Outputs elements of an array of pointers to float to a stream.
Definition: foundationallib.h:2395
FOUNDATIONAL_LIB_FUNC int remove_file(const char *filename)
Removes a file.
Definition: foundationallib.h:7340
FOUNDATIONAL_LIB_FUNC void print_uint_array_to_stream(const unsigned int *array, size_t size, FILE *stream)
Prints the elements of an unsigned int array to a specified stream.
Definition: foundationallib.h:1823
FOUNDATIONAL_LIB_FUNC void print_ulong_array(const unsigned long *array, size_t size)
Prints the contents of an array of unsigned long integers.
Definition: foundationallib.h:1412
FOUNDATIONAL_LIB_FUNC char ** split(const char *str, size_t *output_size, const char *delim, size_t max_times, int keep_delim_in_result)
Splits a given string into an array based on a specified delimiter.
Definition: foundationallib.h:3409
FOUNDATIONAL_LIB_FUNC char * replace_first(const char *source, const char *find, const char *replace)
Replaces the first occurrence of a specified substring in a given string.
Definition: foundationallib.h:8028
FOUNDATIONAL_LIB_FUNC void sort_ushort_ptrs(unsigned short **ushort_ptrs, size_t size)
Sorts an array of pointers to unsigned shorts in ascending order.
Definition: foundationallib.h:5885
FOUNDATIONAL_LIB_FUNC unsigned char ** sorted_uchar_ptrs(unsigned char **uchar_ptrs, size_t size)
Creates a new array containing sorted pointers to unsigned chars.
Definition: foundationallib.h:5655
FOUNDATIONAL_LIB_FUNC void print_long_long_ptr_array(const long long **array, size_t size)
Prints the elements of a long long array through a pointer.
Definition: foundationallib.h:1628
FOUNDATIONAL_LIB_FUNC int append_string_to_array(char ***array, size_t *array_size, size_t *array_current_alloc_size, const char *string)
Appends a new string element to the end of a dynamically allocated array of strings and updates its s...
Definition: foundationallib.h:3857
static size_t FOUNDATIONAL_LIB_REALLOC_REALLOCATION_ALGORITHM(size_t siz)
Definition: foundationallib.h:661
FOUNDATIONAL_LIB_FUNC void sort_uints(unsigned int *uints, size_t size)
Definition: foundationallib.h:5319
FOUNDATIONAL_LIB_FUNC size_t * generate_range(size_t start, size_t end, size_t step, size_t *range_size)
Generates a range of integers.
Definition: foundationallib.h:5189
FOUNDATIONAL_LIB_FUNC void sort_ulong_ptrs(unsigned long **ulong_ptrs, size_t size)
Sorts an array of pointers to unsigned longs in ascending order.
Definition: foundationallib.h:6139
FOUNDATIONAL_LIB_FUNC size_t dict_size(struct Dict *dict)
Returns the number of key-value pairs in the dictionary.
Definition: foundationallib.h:10837
static ssize_t last_index_of_char(const char *str, char chr)
Finds the index of the last occurrence of a specified character in a given string.
Definition: foundationallib.h:4552
FOUNDATIONAL_LIB_FUNC int is_array_lower(const char **array, size_t size)
Checks if a string array contains only lowercase characters.
Definition: foundationallib.h:9559
static int equal_array_of_chars(const char *array, const char *array2, size_t size)
Checks if two arrays of characters are equal.
Definition: foundationallib.h:2743
FOUNDATIONAL_LIB_FUNC char * string_to_lowercase(char *string)
Convert a string to lowercase.
Definition: foundationallib.h:9248
FOUNDATIONAL_LIB_FUNC size_t common_prefix_length(const char *str1, const char *str2)
Finds the length of the common prefix of two strings.
Definition: foundationallib.h:4925
FOUNDATIONAL_LIB_FUNC void print_ulong_long(const unsigned long long value)
Prints an unsigned long long value to the standard output.
Definition: foundationallib.h:12673
FOUNDATIONAL_LIB_FUNC void * select_array(const void *source, size_t source_size, size_t elem_size, int(*condition)(const void *), size_t *result_size)
Definition: foundationallib.h:9133
FOUNDATIONAL_LIB_FUNC void sort_doubles(double *doubles, size_t size)
Sorts an array of doubles in ascending order.
Definition: foundationallib.h:6703
FOUNDATIONAL_LIB_FUNC char * replace_count(const char *source, const char *find, const char *replace, const size_t matches_max)
Replaces the first N occurrences of a specified substring in a given string.
Definition: foundationallib.h:8074
FOUNDATIONAL_LIB_FUNC void * replicate(const void *source, size_t source_size, size_t elem_size, size_t repetitions)
Definition: foundationallib.h:9195
FOUNDATIONAL_LIB_FUNC char * dict_to_string(struct Dict *dict, int pointer_or_string)
Converts a dictionary to a string representation.
Definition: foundationallib.h:11065
FOUNDATIONAL_LIB_FUNC void print_ulong_to_stream(const unsigned long value, FILE *stream)
Prints an unsigned long value to the specified stream.
Definition: foundationallib.h:12662
FOUNDATIONAL_LIB_FUNC void print_size_t_array(const size_t *array, size_t size)
Prints the elements of a size_t array.
Definition: foundationallib.h:1760
#define FOUNDATIONAL_LIB_VA_LIST
Definition: foundationallib.h:122
#define FOUNDATIONAL_LIB_FCLOSE
Definition: foundationallib.h:757
FOUNDATIONAL_LIB_FUNC void * list_comprehension(const void *input_array, size_t array_size, size_t elem_size, void(*transform_func)(void *value), int(*filter_func)(void *value), size_t *result_size)
Perform a list comprehension operation.
Definition: foundationallib.h:8659
FOUNDATIONAL_LIB_FUNC int dict_add(struct Dict *dict, const char *key, void *value)
Adds a key-value pair to the dictionary.
Definition: foundationallib.h:10476
FOUNDATIONAL_LIB_FUNC char * reverse_string(const char *str)
Reverses a given string.
Definition: foundationallib.h:4244
FOUNDATIONAL_LIB_FUNC void print_int(const int value)
Prints an integer value to the standard output.
Definition: foundationallib.h:12485
FOUNDATIONAL_LIB_FUNC void print_char_array_to_stream(const char *array, size_t size, FILE *stream)
Prints the elements of a char array to a specified stream.
Definition: foundationallib.h:1953
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_double_ptrs(const void *a, const void *b)
Compare function for sorting pointers to doubles.
Definition: foundationallib.h:6745
static int equal_array_of_uints(const unsigned int *array, const unsigned int *array2, size_t size)
Checks if two arrays of unsigned integers are equal.
Definition: foundationallib.h:2595
FOUNDATIONAL_LIB_FUNC void frozen_dict_iter(struct FrozenDict *frozen_dict, void(*callback)(char *key, void *value))
Iterates through the key-value pairs in the FrozenDict, applying a callback function.
Definition: foundationallib.h:10809
FOUNDATIONAL_LIB_FUNC int is_valid_utf8(const char *str, size_t len)
Checks if a string is a valid UTF-8 sequence.
Definition: foundationallib.h:12051
FOUNDATIONAL_LIB_FUNC int replace_all_with_lens(const char *source, size_t source_len, const char *find, size_t find_len, const char *replace, size_t replace_len, char **output, size_t *new_len, int *should_free_after_use, size_t matches_max, size_t *num_matches)
Performs string replacement with specified lengths.
Definition: foundationallib.h:7962
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_int_ptrs(const void *a, const void *b)
Definition: foundationallib.h:5493
FOUNDATIONAL_LIB_FUNC void * arraydup(const void *array, size_t num_mem, size_t size)
Duplicates an array of elements at a shallow level.
Definition: foundationallib.h:2541
FOUNDATIONAL_LIB_FUNC void print_ulong_long_ptr_array(const unsigned long long **array, size_t size)
Prints the elements of an unsigned long long array through a pointer.
Definition: foundationallib.h:1567
FOUNDATIONAL_LIB_FUNC char * concatenate_three_strings(const char *str1, const char *str2, const char *str3)
Concatenates three strings into a new dynamically allocated array.
Definition: foundationallib.h:9770
static int equal_array_of_ulong_long_ptrs(const unsigned long long **array, const unsigned long long **array2, size_t size)
Checks if two arrays of pointers to unsigned long long integers are equal.
Definition: foundationallib.h:3025
#define FOUNDATIONAL_LIB_INITIAL_STRING_ARRAY_ALLOC_COUNT
Definition: foundationallib.h:411
FOUNDATIONAL_LIB_FUNC void print_uchar_to_stream(const unsigned char value, FILE *stream)
Prints an unsigned char value to the specified stream.
Definition: foundationallib.h:12625
FOUNDATIONAL_LIB_FUNC short ** sorted_short_ptrs(short **short_ptrs, size_t size)
Creates a new array containing sorted pointers to shorts.
Definition: foundationallib.h:6031
FOUNDATIONAL_LIB_FUNC void print_ulong_long_array_to_stream(const unsigned long long *array, size_t size, FILE *stream)
Prints the elements of an unsigned long long array to a specified stream.
Definition: foundationallib.h:2243
FOUNDATIONAL_LIB_FUNC void print_float(const float value)
Prints a single-precision floating-point value to the standard output.
Definition: foundationallib.h:12466
#define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_FREE
Definition: foundationallib.h:775
FOUNDATIONAL_LIB_FUNC char * replace_all_with_callback(const char *str, const char *old_substring, char *(*callback)(const char *, void *), void *data_for_callback)
Replaces all occurrences of a substring in a string using a callback function.
Definition: foundationallib.h:8122
#define FOUNDATIONAL_LIB_HASH_LOAD_FACTOR_THRESHOLD
Load factor threshold for hash tables in the foundational library.
Definition: foundationallib.h:813
#define FOUNDATIONAL_LIB_ISPRINT
Definition: foundationallib.h:365
FOUNDATIONAL_LIB_FUNC int frozen_set_to_array(struct FrozenSet *set, char ***keys, size_t *size_of_keys)
Converts a FrozenSet to an array of keys.
Definition: foundationallib.h:11815
FOUNDATIONAL_LIB_FUNC size_t count_occurrences_of_substr_len(const char *string, size_t string_length, const char *substring, size_t substring_length)
Counts the occurrences of a specified substring within a given string.
Definition: foundationallib.h:4469
FOUNDATIONAL_LIB_FUNC void print_uint(const unsigned int value)
Prints an unsigned int value to the standard output.
Definition: foundationallib.h:12636
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_ints(const void *a, const void *b)
Definition: foundationallib.h:5428
FOUNDATIONAL_LIB_FUNC void sort_longs(long *longs, size_t size)
Sorts an array of pointers to unsigned longs in ascending order.
Definition: foundationallib.h:6207
FOUNDATIONAL_LIB_FUNC void print_ulong(const unsigned long value)
Prints an unsigned long value to the standard output.
Definition: foundationallib.h:12654
FOUNDATIONAL_LIB_FUNC size_t common_suffix_length(const char *str1, const char *str2)
Finds the length of the common suffix of two strings.
Definition: foundationallib.h:4955
FOUNDATIONAL_LIB_FUNC void print_char_to_stream(const char value, FILE *stream)
Prints a character value to the specified stream.
Definition: foundationallib.h:12436
static void frozen_dict_del_keys(char **keys)
Deletes keys from a frozen dictionary.
Definition: foundationallib.h:11248
FOUNDATIONAL_LIB_FUNC unsigned long ** sorted_ulong_ptrs(unsigned long **ulong_ptrs, size_t size)
Creates a new array containing sorted pointers to unsigned longs.
Definition: foundationallib.h:6161
FOUNDATIONAL_LIB_FUNC int is_string_digit(const char *string)
Check if all characters in a string are digits.
Definition: foundationallib.h:9397
static int equal_array_of_ints(const int *array, const int *array2, size_t size)
Checks if two arrays of integers are equal.
Definition: foundationallib.h:2644
FOUNDATIONAL_LIB_FUNC void sort_ulong_longs(unsigned long long *ulong_longs, size_t size)
Sorts an array of unsigned long longs in ascending order.
Definition: foundationallib.h:6332
FOUNDATIONAL_LIB_FUNC void print_size_t_ptr_array_to_stream(const size_t **array, size_t size, FILE *stream)
Outputs elements of an array of pointers to size_t to a stream.
Definition: foundationallib.h:2507
FOUNDATIONAL_LIB_FUNC void reverse_int_array_in_place(int *array, size_t size)
Reverses an array of integers in place.
Definition: foundationallib.h:5118
FOUNDATIONAL_LIB_FUNC int sum_of_int_array(const int *array, size_t size)
Calculates the sum of elements in an array of integers.
Definition: foundationallib.h:5097
FOUNDATIONAL_LIB_FUNC int dict_reserve_more(struct Dict *dict, size_t number_of_new_elements_max_one_is_expecting)
Reserves additional space in a Dictionary for anticipated new elements.
Definition: foundationallib.h:10316
FOUNDATIONAL_LIB_FUNC void sort_int_ptrs(int **int_ptrs, size_t size)
Definition: foundationallib.h:5510
static int equal_array_of_ulong_longs(const unsigned long long *array, const unsigned long long *array2, size_t size)
Checks if two arrays of unsigned long long integers are equal.
Definition: foundationallib.h:2997
#define FOUNDATIONAL_LIB_ASSERT_ARGUMENT_IF_ENABLED(x)
Definition: foundationallib.h:435
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_long_longs(const void *a, const void *b)
Compare function for sorting long longs.
Definition: foundationallib.h:6443
FOUNDATIONAL_LIB_FUNC unsigned short * sorted_ushorts(unsigned short *ushorts, size_t size)
Creates a new array containing sorted unsigned shorts.
Definition: foundationallib.h:5838
static ssize_t index_of_char(const char *str, char chr)
Finds the index of the first occurrence of a specified character in a string.
Definition: foundationallib.h:4530
#define FOUNDATIONAL_LIB_MEMMOVE
Definition: foundationallib.h:321
static int equal_array_of_shorts(const short *array, const short *array2, size_t size)
Checks if two arrays of short integers are equal.
Definition: foundationallib.h:2845
FOUNDATIONAL_LIB_FUNC int is_string_numeric(const char *str)
Checks if the provided string consists solely of numeric characters.
Definition: foundationallib.h:4570
FOUNDATIONAL_LIB_FUNC unsigned int * sorted_uints(unsigned int *uints, size_t size)
Definition: foundationallib.h:5338
#define FOUNDATIONAL_LIB_safe_increment(variable, label_if_fails)
Definition: foundationallib.h:614
FOUNDATIONAL_LIB_FUNC void sort_ulong_long_ptrs(unsigned long long **ulong_long_ptrs, size_t size)
Sorts an array of pointers to unsigned long longs in ascending order.
Definition: foundationallib.h:6397
#define FOUNDATIONAL_LIB_ISUPPER
Definition: foundationallib.h:368
FOUNDATIONAL_LIB_FUNC void map(void *array, size_t size, size_t elem_size, void(*transform)(void *))
Applies a transformation to each element of an array (void* version).
Definition: foundationallib.h:8435
static int equal_array_of_int_ptrs(const int **array, const int **array2, size_t size)
Checks if two arrays of pointers to integers are equal.
Definition: foundationallib.h:2669
FOUNDATIONAL_LIB_FUNC double * sorted_doubles(double *doubles, size_t size)
Creates a new array containing sorted doubles.
Definition: foundationallib.h:6722
#define FOUNDATIONAL_LIB_AGGRESSIVE_DIE_TYPE
Type of the aggressive die variable.
Definition: foundationallib.h:55
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_uints(const void *a, const void *b)
Definition: foundationallib.h:5302
#define FOUNDATIONAL_LIB_POPEN_INITIAL_ALLOC_SIZE
Definition: foundationallib.h:699
static int equal_array_of_uchar_ptrs(const unsigned char **array, const unsigned char **array2, size_t size)
Checks if two arrays of pointers to unsigned characters are equal.
Definition: foundationallib.h:2719
FOUNDATIONAL_LIB_FUNC void sort_size_t_ptrs(size_t **size_t_ptrs, size_t size)
Sorts an array of pointers to size_t values in ascending order.
Definition: foundationallib.h:6887
FOUNDATIONAL_LIB_FUNC void utoa(size_t unsigned_value, char *output)
Definition: foundationallib.h:1038
static int equal_array_of_ushorts(const unsigned short *array, const unsigned short *array2, size_t size)
Checks if two arrays of unsigned short integers are equal.
Definition: foundationallib.h:2793
FOUNDATIONAL_LIB_FUNC void sort_double_ptrs(double **double_ptrs, size_t size)
Sorts an array of pointers to doubles in ascending order.
Definition: foundationallib.h:6762
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_long_long_ptrs(const void *a, const void *b)
Compare function for sorting pointers to long longs.
Definition: foundationallib.h:6501
FOUNDATIONAL_LIB_AGGRESSIVE_DIE_TYPE FOUNDATIONAL_LIB_aggressive_die
Global variable to control aggressive die behavior.
Definition: foundationallib.h:847
#define FOUNDATIONAL_LIB_VA_ARG
Definition: foundationallib.h:130
FOUNDATIONAL_LIB_FUNC void dict_del_key(struct Dict *dict, const char *key)
Deletes a key-value pair from the dictionary based on the provided key.
Definition: foundationallib.h:10424
#define FOUNDATIONAL_LIB_INITIAL_STRING_ARRAY_ALLOC_SIZE
Definition: foundationallib.h:416
FOUNDATIONAL_LIB_FUNC int file_is_executable(const char *filename)
Checks if a file is executable.
Definition: foundationallib.h:7267
FOUNDATIONAL_LIB_FUNC void print_string_array_array(char ***array, size_t size)
Prints an array of arrays of strings.
Definition: foundationallib.h:1257
FOUNDATIONAL_LIB_FUNC char ** read_file_into_array(const char *filename, const char *delim, size_t *num_lines)
Reads the contents of a file into an array of strings.
Definition: foundationallib.h:12375
FOUNDATIONAL_LIB_FUNC void set_del_keys(char **keys)
Deletes keys from a Set.
Definition: foundationallib.h:11861
FOUNDATIONAL_LIB_FUNC void print_double_ptr_array_to_stream(const double **array, size_t size, FILE *stream)
Outputs elements of an array of pointers to double to a stream.
Definition: foundationallib.h:2448
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_short_ptrs(const void *a, const void *b)
Compare function for sorting pointers to shorts.
Definition: foundationallib.h:5994
FOUNDATIONAL_LIB_FUNC void sort_float_ptrs(float **float_ptrs, size_t size)
Sorts an array of pointers to floats in ascending order.
Definition: foundationallib.h:6641
FOUNDATIONAL_LIB_FUNC void sort_floats(float *floats, size_t size)
Sorts an array of floats in ascending order.
Definition: foundationallib.h:6580
#define FOUNDATIONAL_LIB_VSNPRINTF
Definition: foundationallib.h:297
FOUNDATIONAL_LIB_FUNC void print_long(const long value)
Prints a long integer value to the standard output.
Definition: foundationallib.h:12504
static FOUNDATIONAL_LIB_CONST size_t FOUNDATIONAL_LIB_safe_add_3(size_t a, size_t b, size_t c)
Safely add 3 numbers to avoid unsigned integer overflows and security and stability issues....
Definition: foundationallib.h:571
static int equal_array_of_ulong_ptrs(const unsigned long **array, const unsigned long **array2, size_t size)
Checks if two arrays of pointers to unsigned long integers are equal.
Definition: foundationallib.h:2922
FOUNDATIONAL_LIB_FUNC void print_double_to_stream(const double value, FILE *stream)
Prints a double-precision floating-point value to the specified stream.
Definition: foundationallib.h:12455
FOUNDATIONAL_LIB_FUNC char * sorted_chars(char *chars, size_t size)
Creates a new array containing sorted chars.
Definition: foundationallib.h:5713
static int equal_array_of_longs(const long *array, const long *array2, size_t size)
Checks if two arrays of long integers are equal.
Definition: foundationallib.h:2947
FOUNDATIONAL_LIB_FUNC int append_string_to_file(const char *filename, const char *content)
Appends a string to a file.
Definition: foundationallib.h:7132
FOUNDATIONAL_LIB_FUNC void sort_chars(char *chars, size_t size)
Sorts an array of chars in ascending order.
Definition: foundationallib.h:5694
static int starts_with(const char *str, const char *prefix)
Definition: foundationallib.h:4277
FOUNDATIONAL_LIB_FUNC int dict_resize(struct Dict *dict)
Resizes the hash table of the dictionary to optimize performance.
Definition: foundationallib.h:10370
static int ends_with(const char *str, const char *suffix)
Checks whether a given string ends with a specified suffix.
Definition: foundationallib.h:4294
FOUNDATIONAL_LIB_FUNC void print_uint_to_stream(const unsigned int value, FILE *stream)
Prints an unsigned int value to the specified stream.
Definition: foundationallib.h:12644
FOUNDATIONAL_LIB_FUNC int frozen_set_in(struct FrozenSet *set, const char *key)
Checks if a key is in a FrozenSet.
Definition: foundationallib.h:11681
static int equal_array_of_double_ptrs(const double **array, const double **array2, size_t size)
Compares arrays of double pointers for equality.
Definition: foundationallib.h:3173
FOUNDATIONAL_LIB_FUNC void sort_char_ptrs(char **char_ptrs, size_t size)
Sorts an array of pointers to chars in ascending order.
Definition: foundationallib.h:5753
FOUNDATIONAL_LIB_FUNC char * frozen_set_to_string(struct FrozenSet *frozen_set)
Converts a frozen set to a string representation.
Definition: foundationallib.h:11939
static double str_to_double(const char *string)
Converts a string to a double-precision floating-point number.
Definition: foundationallib.h:4791
FOUNDATIONAL_LIB_FUNC int filter_ints(int *source, size_t source_size, int *destination, int(*condition)(int))
Filters elements of an integer array based on a specified condition.
Definition: foundationallib.h:8388
FOUNDATIONAL_LIB_FUNC int file_is_regular(const char *filename)
Checks if a file is a regular file.
Definition: foundationallib.h:7177
FOUNDATIONAL_LIB_FUNC void sort_ulongs(unsigned long *ulongs, size_t size)
Sorts an array of unsigned longs in ascending order.
Definition: foundationallib.h:6074
FOUNDATIONAL_LIB_FUNC void print_float_to_stream(const float value, FILE *stream)
Prints a single-precision floating-point value to the specified stream.
Definition: foundationallib.h:12474
FOUNDATIONAL_LIB_FUNC void print_ushort_array_to_stream(const unsigned short *array, size_t size, FILE *stream)
Prints the elements of an unsigned short array to a specified stream.
Definition: foundationallib.h:2032
#define FOUNDATIONAL_LIB_ISDIGIT
Definition: foundationallib.h:362
FOUNDATIONAL_LIB_FUNC void print_ushort_ptr_array_to_stream(const unsigned short **array, size_t size, FILE *stream)
Prints the elements of an unsigned short array through a pointer to a specified stream.
Definition: foundationallib.h:2059
FOUNDATIONAL_LIB_FUNC int file_is_writable(const char *filename)
Checks if a file is writable.
Definition: foundationallib.h:7246
FOUNDATIONAL_LIB_FUNC long long ** sorted_long_long_ptrs(long long **long_long_ptrs, size_t size)
Creates a new array containing sorted pointers to long longs.
Definition: foundationallib.h:6539
FOUNDATIONAL_LIB_FUNC int append_string_to_string(char **string, size_t *string_length, size_t *string_alloc_size, const char *string_to_get_appended, size_t string_to_get_appended_length)
Appends a new string to an existing string and updates its length and allocation size.
Definition: foundationallib.h:3628
void * memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen)
FOUNDATIONAL_LIB_FUNC int copy_file(const char *source_filename, const char *destination_filename)
Copies a file from source to destination.
Definition: foundationallib.h:7365
FOUNDATIONAL_LIB_FUNC void print_size_t_array_to_stream(const size_t *array, size_t size, FILE *stream)
Outputs elements of a size_t array to a stream.
Definition: foundationallib.h:2474
static size_t FOUNDATIONAL_LIB_safe_add_2_ptr(size_t a, size_t b, size_t *ptr)
Safely add 2 numbers to avoid unsigned integer overflows and security and stability issues....
Definition: foundationallib.h:587
FOUNDATIONAL_LIB_FUNC void print_long_long_to_stream(const long long value, FILE *stream)
Prints a long long integer value to the specified stream.
Definition: foundationallib.h:12531
FOUNDATIONAL_LIB_FUNC void print_double_ptr_array(const double **array, size_t size)
Prints the elements of a double array through a pointer.
Definition: foundationallib.h:1735
FOUNDATIONAL_LIB_FUNC char * dup_format(const char *format,...)
Duplicates a formatted string.
Definition: foundationallib.h:8225
FOUNDATIONAL_LIB_FUNC char * string_to_title_case(const char *str)
Converts a string to title case.
Definition: foundationallib.h:4986
FOUNDATIONAL_LIB_FUNC char * concatenate_five_strings(const char *str1, const char *str2, const char *str3, const char *str4, const char *str5)
Concatenates five strings into a new dynamically allocated array.
Definition: foundationallib.h:9828
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_char_ptrs(const void *a, const void *b)
Compare function for sorting pointers to chars.
Definition: foundationallib.h:5737
#define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_STRDUP
Definition: foundationallib.h:779
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_shorts(const void *a, const void *b)
Compare function for sorting shorts.
Definition: foundationallib.h:5933
FOUNDATIONAL_LIB_FUNC void print_string_array_array_to_stream(char ***array, size_t size, FILE *stream)
Prints the elements of an array of string arrays to a specified stream.
Definition: foundationallib.h:2006
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_uchars(const void *a, const void *b)
Compare function for sorting unsigned chars.
Definition: foundationallib.h:5554
#define FOUNDATIONAL_LIB_PRINTF
Definition: foundationallib.h:285
FOUNDATIONAL_LIB_FUNC void * memory_locate(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len)
Definition: foundationallib.h:4316
FOUNDATIONAL_LIB_FUNC int is_array_upper(const char **array, size_t size)
Checks if a string array contains only uppercase characters.
Definition: foundationallib.h:9528
FOUNDATIONAL_LIB_FUNC void sort_long_ptrs(long **long_ptrs, size_t size)
Sorts an array of pointers to longs in ascending order.
Definition: foundationallib.h:6273
#define FOUNDATIONAL_LIB_STRLEN
Definition: foundationallib.h:309
FOUNDATIONAL_LIB_FUNC struct FrozenDict * frozen_dict_new_instance(size_t num_pairs,...)
Creates a new instance of a frozen dictionary.
Definition: foundationallib.h:10652
static int equal_array_of_float_ptrs(const float **array, const float **array2, size_t size)
Checks if two arrays of pointers to float values are equal.
Definition: foundationallib.h:3125
static size_t FOUNDATIONAL_LIB_safe_mul_ptr(size_t a, size_t b, size_t *ptr)
Safely multiply 2 numbers to avoid unsigned integer overflows and security and stability issues....
Definition: foundationallib.h:541
FOUNDATIONAL_LIB_FUNC float * sorted_floats(float *floats, size_t size)
Creates a new array containing sorted floats.
Definition: foundationallib.h:6599
static int equal_array_of_long_ptrs(const long **array, const long **array2, size_t size)
Checks if two arrays of pointers to long integers are equal.
Definition: foundationallib.h:2972
static int equal_array_of_size_ts(const size_t *array, const size_t *array2, size_t size)
Checks if two arrays of size_t values are equal.
Definition: foundationallib.h:3197
FOUNDATIONAL_LIB_FUNC char * set_to_string(struct Set *set)
Definition: foundationallib.h:11864
FOUNDATIONAL_LIB_FUNC int is_string_upper(const char *string)
Check if all characters in a string are uppercase.
Definition: foundationallib.h:9316
static FOUNDATIONAL_LIB_CONST size_t FOUNDATIONAL_LIB_safe_mul(size_t a, size_t b)
Safely multiply 2 numbers to avoid unsigned integer overflows and security and stability issues....
Definition: foundationallib.h:525
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_ulong_longs(const void *a, const void *b)
Compare function for sorting unsigned long longs.
Definition: foundationallib.h:6317
FOUNDATIONAL_LIB_FUNC unsigned long rand_number_from_range_inclusive_unsigned(unsigned long min, unsigned long max)
Generates a random unsigned number within a specified range (inclusive).
Definition: foundationallib.h:12206
FOUNDATIONAL_LIB_FUNC char * longest_common_suffix(const char **strings, size_t count)
Finds the longest common suffix among an array of strings.
Definition: foundationallib.h:4712
FOUNDATIONAL_LIB_FUNC size_t frozen_set_size(struct FrozenSet *set)
Returns the size of a FrozenSet.
Definition: foundationallib.h:11751
FOUNDATIONAL_LIB_FUNC char * frozen_dict_to_string(struct FrozenDict *dict, int pointer_or_string)
Converts a FrozenDict (frozen dictionary) to a string representation.
Definition: foundationallib.h:11162
FOUNDATIONAL_LIB_FUNC void print_uint_ptr_array_to_stream(const unsigned int **array, size_t size, FILE *stream)
Prints the elements of an unsigned int array through a pointer to a specified stream.
Definition: foundationallib.h:1850
FOUNDATIONAL_LIB_FUNC void print_double_array(const double *array, size_t size)
Prints the elements of a double array.
Definition: foundationallib.h:1709
FOUNDATIONAL_LIB_FUNC void print_int_array(const int *array, size_t size)
Prints the elements of an int array.
Definition: foundationallib.h:1163
FOUNDATIONAL_LIB_FUNC char * string_to_json(const char *input_string)
Converts a given input string to its JSON representation.
Definition: foundationallib.h:3246
FOUNDATIONAL_LIB_FUNC void frozen_set_del_keys(char **keys)
Deletes keys from a FrozenSet.
Definition: foundationallib.h:12007
FOUNDATIONAL_LIB_FUNC unsigned short ** sorted_ushort_ptrs(unsigned short **ushort_ptrs, size_t size)
Creates a new array containing sorted pointers to unsigned shorts.
Definition: foundationallib.h:5907
FOUNDATIONAL_LIB_FUNC int string_array_uniq_adjacent(const char **first_array, size_t size, char ***new_array, size_t *new_size)
Remove adjacent duplicate strings from a string array.
Definition: foundationallib.h:9714
FOUNDATIONAL_LIB_FUNC char ** sorted_char_ptrs(char **char_ptrs, size_t size)
Creates a new array containing sorted pointers to chars.
Definition: foundationallib.h:5774
FOUNDATIONAL_LIB_FUNC int read_files_into_array(const char **files_to_open, size_t num_files, char ***outputs, size_t **lens, int aggressive_stop_on_error)
Reads content from multiple files into an array.
Definition: foundationallib.h:13028
static void free_array(void **array, size_t len)
Frees a dynamic array and its elements up to one level deep.
Definition: foundationallib.h:896
FOUNDATIONAL_LIB_FUNC void print_long_long(const long long value)
Prints a long long integer value to the standard output.
Definition: foundationallib.h:12523
FOUNDATIONAL_LIB_FUNC char * string_to_uppercase(char *string)
Convert a string to uppercase.
Definition: foundationallib.h:9284
FOUNDATIONAL_LIB_FUNC int memory_has_subchunk(void *memory, size_t memory_length, void *subchunk, size_t subchunk_length)
Checks if a subchunk exists within a given memory block.
Definition: foundationallib.h:4436
FOUNDATIONAL_LIB_FUNC void print_int_ptr_array(const int **array, size_t size)
Prints the elements of an array of int pointers.
Definition: foundationallib.h:1195
FOUNDATIONAL_LIB_FUNC int get_file_size(const char *filename, size_t *size)
Gets the size of a file.
Definition: foundationallib.h:7290
FOUNDATIONAL_LIB_FUNC void * list_comprehension_multithreaded(const void *input_array, size_t array_size, size_t elem_size, void(*transform_func)(void *value), int(*filter_func)(void *value), size_t *result_size, size_t thread_count)
Definition: foundationallib.h:8885
FOUNDATIONAL_LIB_FUNC int is_array_digit(const char **array, size_t size)
Check if a string array contains only digits.
Definition: foundationallib.h:9498
FOUNDATIONAL_LIB_FUNC int file_is_directory(const char *filename)
Checks if a file is a directory.
Definition: foundationallib.h:7200
FOUNDATIONAL_LIB_FUNC long * sorted_longs(long *longs, size_t size)
Creates a new array containing sorted pointers to unsigned longs.
Definition: foundationallib.h:6230
FOUNDATIONAL_LIB_FUNC void print_int_ptr_array_to_stream(const int **array, size_t size, FILE *stream)
Prints the elements of an int array through a pointer to a specified stream.
Definition: foundationallib.h:1902
FOUNDATIONAL_LIB_FUNC int replace_memory(void *source, size_t source_len, void *find, size_t find_len, void *replace, size_t replace_len, void **output, size_t *output_length_without_nullt, int *should_free_after_use, size_t matches_max, size_t *num_matches_found, int should_nullt)
Performs memory replacement with specified lengths.
Definition: foundationallib.h:7805
static void free_string_array(char **array, size_t len)
Frees a dynamic string array and its elements up to one level deep.
Definition: foundationallib.h:915
FOUNDATIONAL_LIB_FUNC int is_string_lower(const char *string)
Check if all characters in a string are lowercase.
Definition: foundationallib.h:9343
FOUNDATIONAL_LIB_FUNC void print_ushort(const unsigned short value)
Print an unsigned short value.
Definition: foundationallib.h:12705
#define FOUNDATIONAL_LIB_COPY_SIZE_AMOUNT
Definition: foundationallib.h:693
FOUNDATIONAL_LIB_FUNC void print_char(const char value)
Prints a character value to the standard output.
Definition: foundationallib.h:12428
FOUNDATIONAL_LIB_FUNC int string_array_uniq(const char **array, size_t size, char ***output, size_t *output_size)
Remove duplicate strings from a string array.
Definition: foundationallib.h:9614
static int equal_array_of_short_ptrs(const short **array, const short **array2, size_t size)
Checks if two arrays of pointers to short integers are equal.
Definition: foundationallib.h:2870
FOUNDATIONAL_LIB_FUNC void print_ulong_long_ptr_array_to_stream(const unsigned long long **array, size_t size, FILE *stream)
Prints the elements of an unsigned long long array through a pointer to a specified stream.
Definition: foundationallib.h:2274
#define FOUNDATIONAL_LIB_ISLOWER
Definition: foundationallib.h:371
FOUNDATIONAL_LIB_FUNC struct FrozenSet * frozen_set_new_instance(size_t num_args,...)
Creates a new instance of a FrozenSet.
Definition: foundationallib.h:11637
#define FOUNDATIONAL_LIB_MEMCPY
Definition: foundationallib.h:305
FOUNDATIONAL_LIB_FUNC size_t * sorted_size_ts(size_t *size_ts, size_t size)
Creates a new array containing sorted size_t values.
Definition: foundationallib.h:6845
FOUNDATIONAL_LIB_FUNC int set_reserve_more(struct Set *set, size_t number_of_new_elements_max_one_is_expecting)
Reserves additional space in a Set for anticipated new elements.
Definition: foundationallib.h:11545
#define FOUNDATIONAL_LIB_STRSTR
Definition: foundationallib.h:349
FOUNDATIONAL_LIB_FUNC void set_del_key(struct Set *set, const char *key)
Deletes a key from a Set.
Definition: foundationallib.h:11408
FOUNDATIONAL_LIB_FUNC int write_to_file_with_mode(const char *filename, const char *content, size_t content_length, const char *mode)
Writes a string or data to a file with a specified mode.
Definition: foundationallib.h:7065
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_ulong_ptrs(const void *a, const void *b)
Compare function for sorting pointers to unsigned longs.
Definition: foundationallib.h:6121
static int equal_array_of_uint_ptrs(const unsigned int **array, const unsigned int **array2, size_t size)
Checks if two arrays of pointers to unsigned integers are equal.
Definition: foundationallib.h:2620
FOUNDATIONAL_LIB_FUNC void dict_iter(struct Dict *dict, void(*callback)(char *key, void *value))
Iterates through the key-value pairs in the dictionary, applying a callback function.
Definition: foundationallib.h:10776
FOUNDATIONAL_LIB_FUNC void print_uint_array(const unsigned long long *array, size_t size)
Prints the elements of a uint array.
Definition: foundationallib.h:1101
FOUNDATIONAL_LIB_FUNC unsigned long long ** sorted_ulong_long_ptrs(unsigned long long **ulong_long_ptrs, size_t size)
Creates a new array containing sorted pointers to unsigned long longs.
Definition: foundationallib.h:6417
FOUNDATIONAL_LIB_FUNC void print_string_array_to_stream(char **array, size_t size, FILE *stream)
Prints the elements of a string array to a specified stream.
Definition: foundationallib.h:1979
FOUNDATIONAL_LIB_FUNC char * backticks(const char *command, size_t *size)
Executes a command and reads its output into a string.
Definition: foundationallib.h:12247
FOUNDATIONAL_LIB_FUNC size_t filter(void *source, size_t source_size, size_t elem_size, void *destination, size_t dest_size, int(*condition)(void *))
Filters elements of an array (void* version) based on a specified condition.
Definition: foundationallib.h:8543
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_ulong_long_ptrs(const void *a, const void *b)
Compare function for sorting pointers to unsigned long longs.
Definition: foundationallib.h:6379
#define FOUNDATIONAL_LIB_FERROR
Definition: foundationallib.h:722
FOUNDATIONAL_LIB_FUNC char * concatenate_strings(const char *str1, const char *str2)
Concatenates two strings.
Definition: foundationallib.h:7755
FOUNDATIONAL_LIB_FUNC void sort_ushorts(unsigned short *ushorts, size_t size)
Sorts an array of unsigned shorts in ascending order.
Definition: foundationallib.h:5817
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_list_comprehension_worker(void *data)
Definition: foundationallib.h:8817
FOUNDATIONAL_LIB_FUNC int append_data_to_array_no_initial_alloc(void **array, size_t *array_size, size_t *array_current_alloc_size, void *data, size_t data_size)
Appends a new element to the end of a dynamically allocated array and updates its size.
Definition: foundationallib.h:3786
#define FOUNDATIONAL_LIB_UNLIKELY(x)
Definition: foundationallib.h:424
static int equal_array_of_uchars(const unsigned char *array, const unsigned char *array2, size_t size)
Checks if two arrays of unsigned characters are equal.
Definition: foundationallib.h:2694
#define FOUNDATIONAL_LIB_MEMCMP
Definition: foundationallib.h:317
static void frozen_dict_del_values(void **values)
Deletes values from a frozen dictionary.
Definition: foundationallib.h:11262
static int equal_array_of_long_long_ptrs(const long long **array, const long long **array2, size_t size)
Checks if two arrays of pointers to long long integers are equal.
Definition: foundationallib.h:3075
FOUNDATIONAL_LIB_FUNC long long * sorted_long_longs(long long *long_longs, size_t size)
Creates a new array containing sorted long longs.
Definition: foundationallib.h:6475
#define FOUNDATIONAL_LIB_STATIC_ASSERT_MSG(true_cond, failure_message)
Definition: foundationallib.h:108
FOUNDATIONAL_LIB_FUNC int dict_to_array(struct Dict *dict, char ***keys, void ***values, size_t *size_of_keys_and_values)
Converts the key-value pairs from the dictionary into separate arrays for keys and values.
Definition: foundationallib.h:10883
FOUNDATIONAL_LIB_FUNC void print_long_long_ptr_array_to_stream(const long long **array, size_t size, FILE *stream)
Outputs elements of an array of pointers to long long to a stream.
Definition: foundationallib.h:2337
FOUNDATIONAL_LIB_FUNC int * sorted_ints(int *ints, size_t size)
Definition: foundationallib.h:5465
FOUNDATIONAL_LIB_FUNC void int_to_string_with_buffer(long long int number, char *buffer)
Converts an integer to its string representation.
Definition: foundationallib.h:993
FOUNDATIONAL_LIB_FUNC void print_long_long_array(const long long *array, size_t size)
Prints the elements of a long long array.
Definition: foundationallib.h:1597
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_chars(const void *a, const void *b)
Compare function for sorting chars.
Definition: foundationallib.h:5679
FOUNDATIONAL_LIB_FUNC long ** sorted_long_ptrs(long **long_ptrs, size_t size)
Creates a new array containing sorted pointers to longs.
Definition: foundationallib.h:6292
FOUNDATIONAL_LIB_FUNC char * reduce_filesystem_files_as_strings(const char *directory, const char *out_file, char *(*reduce_function)(char *value1,...))
Applies a reduce operation on files in the specified directory, and outputs the result as a string.
Definition: foundationallib.h:10112
FOUNDATIONAL_LIB_FUNC int set_to_array(struct Set *set, char ***keys, size_t *size_of_keys)
Converts a Set to an array of keys.
Definition: foundationallib.h:11767
FOUNDATIONAL_LIB_FUNC void sort_long_longs(long long *long_longs, size_t size)
Sorts an array of long longs in ascending order.
Definition: foundationallib.h:6457
FOUNDATIONAL_LIB_FUNC int string_has_substr(const char *string, size_t string_length, const char *substring, size_t substring_length)
Checks if a substring exists within a given string.
Definition: foundationallib.h:4398
FOUNDATIONAL_LIB_FUNC void print_int_array_to_stream(const int *array, size_t size, FILE *stream)
Prints the elements of an int array to a specified stream.
Definition: foundationallib.h:1875
FOUNDATIONAL_LIB_FUNC void print_long_long_array_to_stream(const long long *array, size_t size, FILE *stream)
Outputs elements of a long_long array to a stream.
Definition: foundationallib.h:2304
FOUNDATIONAL_LIB_FUNC void print_long_ptr_array_to_stream(const long **array, size_t size, FILE *stream)
Prints the elements of a long array through a pointer to a specified stream.
Definition: foundationallib.h:2216
#define FOUNDATIONAL_LIB_DIR_SEPARATOR
Definition: foundationallib.h:9851
#define FOUNDATIONAL_LIB_FTELLO
Definition: foundationallib.h:739
static int equal_array_of_ulongs(const unsigned long *array, const unsigned long *array2, size_t size)
Checks if two arrays of unsigned long integers are equal.
Definition: foundationallib.h:2895
#define FOUNDATIONAL_LIB_VA_END
Definition: foundationallib.h:134
FOUNDATIONAL_LIB_FUNC void print_short_to_stream(const short value, FILE *stream)
Prints a short integer value to the specified stream.
Definition: foundationallib.h:12557
FOUNDATIONAL_LIB_FUNC int append_string_to_array_no_initial_alloc(char ***array, size_t *array_size, size_t *array_current_alloc_size, const char *string)
Appends a new string element to the end of a dynamically allocated array of strings and updates its s...
Definition: foundationallib.h:3941
static int FOUNDATIONAL_LIB_safe_add_3_ptr(size_t a, size_t b, size_t c, size_t *ptr)
Safely add 3 numbers to avoid unsigned integer overflows and security and stability issues....
Definition: foundationallib.h:601
static int equal_array_of_doubles(const double *array, const double *array2, size_t size)
Checks if two arrays of doubles are equal.
Definition: foundationallib.h:3149
#define FOUNDATIONAL_LIB_ISALNUM
Definition: foundationallib.h:359
FOUNDATIONAL_LIB_FUNC void print_ushort_to_stream(const unsigned short value, FILE *stream)
Print an unsigned short value to a stream.
Definition: foundationallib.h:12713
FOUNDATIONAL_LIB_FUNC int write_file(const char *filename, const char *content)
Writes a string to a file.
Definition: foundationallib.h:7109
FOUNDATIONAL_LIB_FUNC int reduce_ints(int *array, size_t size, int(*operation)(int, int))
Performs a reduction on an integer array using a binary operation.
Definition: foundationallib.h:8337
#define FOUNDATIONAL_LIB_FROZEN_INITIALIZATION_SIZE_MULTIPLIER
Definition: foundationallib.h:406
FOUNDATIONAL_LIB_FUNC void sort_size_ts(size_t *size_ts, size_t size)
Sorts an array of size_t values in ascending order.
Definition: foundationallib.h:6825
#define FOUNDATIONAL_LIB_ISSPACE
Definition: foundationallib.h:353
#define FOUNDATIONAL_LIB_SIZE_STRING_OF_NUMBER_SIZE_PLUS_ZERO_TERMINATOR
Definition: foundationallib.h:112
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_size_t_ptrs(const void *a, const void *b)
Compare function for sorting pointers to size_t values.
Definition: foundationallib.h:6870
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_long_ptrs(const void *a, const void *b)
Compare function for sorting pointers to longs.
Definition: foundationallib.h:6257
FOUNDATIONAL_LIB_FUNC void print_uint_ptr_array(const unsigned int **array, size_t size)
Prints the elements of an array of uint pointers.
Definition: foundationallib.h:1132
FOUNDATIONAL_LIB_FUNC void print_short_array(const short *array, size_t size)
Prints the contents of an array of short integers.
Definition: foundationallib.h:1348
#define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_MALLOC
Definition: foundationallib.h:763
FOUNDATIONAL_LIB_FUNC void print_int_to_stream(const int value, FILE *stream)
Prints an integer value to the specified stream.
Definition: foundationallib.h:12493
FOUNDATIONAL_LIB_FUNC char ** list_files_with_pattern(const char *directory, const char *pattern, size_t *len)
Lists files in a directory using a wildcard pattern.
Definition: foundationallib.h:7588
FOUNDATIONAL_LIB_FUNC void reduce(void *array, size_t size, size_t elem_size, void *result, void(*operation)(void *, void *))
Performs a reduction on an array (void* version) using a binary operation.
Definition: foundationallib.h:8481
FOUNDATIONAL_LIB_FUNC void print_float_array_to_stream(const float *array, size_t size, FILE *stream)
Outputs elements of a float array to a stream.
Definition: foundationallib.h:2368
static int equal_array_of_size_t_ptrs(const size_t **array, const size_t **array2, size_t size)
Compares arrays of size_t pointers for equality.
Definition: foundationallib.h:3221
FOUNDATIONAL_LIB_FUNC int ** sorted_int_ptrs(int **int_ptrs, size_t size)
Definition: foundationallib.h:5530
FOUNDATIONAL_LIB_FUNC void print_string_to_stream(char *value, FILE *stream)
Prints a string value to the specified stream.
Definition: foundationallib.h:12604
FOUNDATIONAL_LIB_FUNC char ** sorted_strings(char **strings, size_t size)
Creates a new array of strings sorted in ascending order.
Definition: foundationallib.h:5275
FOUNDATIONAL_LIB_FUNC void print_uchar_array_to_stream(const unsigned char *array, size_t size, FILE *stream)
Prints the elements of an unsigned char array to a specified stream.
Definition: foundationallib.h:1928
FOUNDATIONAL_LIB_FUNC int is_string_space(const char *string)
Check if all characters in a string are spaces.
Definition: foundationallib.h:9423
#define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_CALLOC
Definition: foundationallib.h:771
FOUNDATIONAL_LIB_FUNC char * concatenate_four_strings(const char *str1, const char *str2, const char *str3, const char *str4)
Concatenates four strings into a new dynamically allocated array.
Definition: foundationallib.h:9798
FOUNDATIONAL_LIB_FUNC void map_ints(int *array, size_t size, int(*transform)(int))
Applies a transformation to each element of an integer array.
Definition: foundationallib.h:8295
FOUNDATIONAL_LIB_FUNC char * strip(const char *str)
Trims leading and trailing whitespace from a given string.
Definition: foundationallib.h:3342
FOUNDATIONAL_LIB_FUNC ssize_t find_last_of(const char *str, const char *char_set)
Finds the last occurrence of any character from a specified set within a given string.
Definition: foundationallib.h:4833
FOUNDATIONAL_LIB_FUNC size_t set_size(struct Set *set)
Returns the size of a Set.
Definition: foundationallib.h:11736
FOUNDATIONAL_LIB_FUNC void print_short_ptr_array_to_stream(const short **array, size_t size, FILE *stream)
Prints the elements of a short array through a pointer to a specified stream.
Definition: foundationallib.h:2111
#define FOUNDATIONAL_LIB_HASH_INITIAL_CAPACITY
Initial capacity for hash tables (dict, frozendict, set, frozenset).
Definition: foundationallib.h:801
FOUNDATIONAL_LIB_FUNC int set_resize(struct Set *set)
Resizes a Set data structure.
Definition: foundationallib.h:11359
FOUNDATIONAL_LIB_FUNC int filter_filesystem_files_as_strings(const char *directory, int(*filter_function)(const char *filename))
Applies a filter operation on files in the specified directory.
Definition: foundationallib.h:10010
static int equal_array_of_char_ptrs(const char **array, const char **array2, size_t size)
Checks if two arrays of pointers to characters are equal.
Definition: foundationallib.h:2768
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_floats(const void *a, const void *b)
Compare function for sorting floats.
Definition: foundationallib.h:6565
FOUNDATIONAL_LIB_FUNC char * shellescape(const char *input)
Escapes special characters in a given string for shell usage.
Definition: foundationallib.h:4185
#define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_REALLOC
Definition: foundationallib.h:767
FOUNDATIONAL_LIB_FUNC size_t set_hash(const char *key, size_t capacity)
Hashes a null-terminated string using the djb2 algorithm.
Definition: foundationallib.h:11337
static void dict_del_values(void **values)
Deallocates memory associated with an array of values.
Definition: foundationallib.h:11041
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_ushorts(const void *a, const void *b)
Compare function for sorting unsigned shorts.
Definition: foundationallib.h:5800
FOUNDATIONAL_LIB_FUNC char * read_file_into_string(const char *filename, size_t *size)
Reads the contents of a file into a string.
Definition: foundationallib.h:6957
FOUNDATIONAL_LIB_FUNC int prepend_string_to_array(char ***array, size_t *array_size, size_t *array_current_alloc_size, char *string)
Prepends a new string element to the beginning of a dynamically allocated array of strings and update...
Definition: foundationallib.h:4009
#define FOUNDATIONAL_LIB_ALLOCATOR_DIV_AMOUNT
Definition: foundationallib.h:626
FOUNDATIONAL_LIB_FUNC size_t array_total_string_length(char **array, size_t count)
Calculates the total length of strings in an array.
Definition: foundationallib.h:4152
FOUNDATIONAL_LIB_FUNC int prepend_string_to_array_no_initial_alloc(char ***array, size_t *array_size, size_t *array_current_alloc_size, char *string)
Prepends a new string element to the beginning of a dynamically allocated array of strings and update...
Definition: foundationallib.h:4090
FOUNDATIONAL_LIB_FUNC int set_in(struct Set *set, const char *key)
Checks if a key is in a Set.
Definition: foundationallib.h:11594
FOUNDATIONAL_LIB_FUNC void print_long_array_to_stream(const long *array, size_t size, FILE *stream)
Prints the elements of a long array to a specified stream.
Definition: foundationallib.h:2189
FOUNDATIONAL_LIB_FUNC void print_ulong_ptr_array_to_stream(const unsigned long **array, size_t size, FILE *stream)
Prints the elements of an unsigned long array through a pointer to a specified stream.
Definition: foundationallib.h:2164
FOUNDATIONAL_LIB_FUNC void sort_strings(char **strings, size_t size)
Sorts an array of strings.
Definition: foundationallib.h:5257
FOUNDATIONAL_LIB_FUNC size_t count_occurrences_of_substr(const char *str, const char *substring)
Counts the occurrences of a specified substring within a given string.
Definition: foundationallib.h:4360
#define FOUNDATIONAL_LIB_FPUTS
Definition: foundationallib.h:325
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmpstringp(const void *p1, const void *p2)
Definition: foundationallib.h:5244
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_ulongs(const void *a, const void *b)
Compare function for sorting unsigned longs.
Definition: foundationallib.h:6058
static int equal_array_of_floats(const float *array, const float *array2, size_t size)
Checks if two arrays of float values are equal.
Definition: foundationallib.h:3100
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_doubles(const void *a, const void *b)
Compare function for sorting doubles.
Definition: foundationallib.h:6687
#define FOUNDATIONAL_LIB_ATOI
Definition: foundationallib.h:706
FOUNDATIONAL_LIB_FUNC char * concatenate_string_array(const char **strings, size_t num_strings)
Concatenates an array of strings into a single string.
Definition: foundationallib.h:7674
FOUNDATIONAL_LIB_FUNC void * reject_array(const void *source, size_t source_size, size_t elem_size, int(*condition)(const void *), size_t *result_size)
Definition: foundationallib.h:9068
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_size_ts(const void *a, const void *b)
Compare function for sorting size_t values.
Definition: foundationallib.h:6808
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_uchar_ptrs(const void *a, const void *b)
Compare function for sorting pointers to unsigned chars.
Definition: foundationallib.h:5617
#define FOUNDATIONAL_LIB_likely(x)
Definition: foundationallib.h:423
FOUNDATIONAL_LIB_FUNC void print_float_ptr_array(const float **array, size_t size)
Prints the elements of a float array through a pointer.
Definition: foundationallib.h:1684
FOUNDATIONAL_LIB_FUNC int map_filesystem_files_as_strings(const char *directory, char *(*map_function)(const char *file_string_data, size_t string_size))
Applies a map operation on files in a directory, working with strings.
Definition: foundationallib.h:9877
FOUNDATIONAL_LIB_FUNC char * longest_common_prefix(const char **strings, size_t count)
Finds the longest common prefix among an array of strings.
Definition: foundationallib.h:4632
FOUNDATIONAL_LIB_FUNC void print_double(const double value)
Prints a double-precision floating-point value to the standard output.
Definition: foundationallib.h:12447
#define FOUNDATIONAL_LIB_PUTCHAR
Definition: foundationallib.h:329
FOUNDATIONAL_LIB_FUNC int find_min_int_in_array(const int *array, size_t size)
Finds the minimum element in an array of integers.
Definition: foundationallib.h:5066
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_float_ptrs(const void *a, const void *b)
Compare function for sorting pointers to floats.
Definition: foundationallib.h:6625
#define FOUNDATIONAL_LIB_INITIAL_DATA_ARRAY_ALLOC_SIZE
Definition: foundationallib.h:3672
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_ushort_ptrs(const void *a, const void *b)
Compare function for sorting pointers to unsigned shorts.
Definition: foundationallib.h:5866
FOUNDATIONAL_LIB_FUNC double ** sorted_double_ptrs(double **double_ptrs, size_t size)
Creates a new array containing sorted pointers to doubles.
Definition: foundationallib.h:6782
FOUNDATIONAL_LIB_FUNC void print_short_array_to_stream(const short *array, size_t size, FILE *stream)
Prints the elements of a short array to a specified stream.
Definition: foundationallib.h:2084
FOUNDATIONAL_LIB_FUNC size_t dict_hash(const char *key, size_t capacity)
Hashes a null-terminated string using the djb2 algorithm.
Definition: foundationallib.h:10284
FOUNDATIONAL_LIB_FUNC void set_iter(struct Set *set, void(*callback)(char *key))
Iterates over a Set and applies a callback to each key.
Definition: foundationallib.h:11708
#define FOUNDATIONAL_LIB_STRCMP
Definition: foundationallib.h:313
FOUNDATIONAL_LIB_FUNC void print_short_ptr_array(const short **array, size_t size)
Prints an array of pointers to short integers.
Definition: foundationallib.h:1381
FOUNDATIONAL_LIB_FUNC void print_uchar(const unsigned char value)
Prints an unsigned char value to the standard output.
Definition: foundationallib.h:12617
#define FOUNDATIONAL_LIB_FPRINTF
Definition: foundationallib.h:301
FOUNDATIONAL_LIB_FUNC int file_is_readable(const char *filename)
Checks if a file is readable.
Definition: foundationallib.h:7225
FOUNDATIONAL_LIB_FUNC char * uint_to_string(size_t number)
Converts an integer to its string representation.
Definition: foundationallib.h:1075
static int equal_array_of_ushort_ptrs(const unsigned short **array, const unsigned short **array2, size_t size)
Checks if two arrays of pointers to unsigned short integers are equal.
Definition: foundationallib.h:2820
FOUNDATIONAL_LIB_FUNC void print_ulong_long_to_stream(const unsigned long long value, FILE *stream)
Prints an unsigned long long value to the specified stream.
Definition: foundationallib.h:12690
FOUNDATIONAL_LIB_FUNC size_t count_occurrences_of_adjacent_data_in_array(const void *array_of_adjacent_values, size_t array_length, const void *memory, size_t memory_length)
Counts the occurrences of a block of memory in an array of memory blocks.
Definition: foundationallib.h:12766
FOUNDATIONAL_LIB_FUNC size_t count_occurrences_of_data_in_array(const void **array_of_pointers, size_t array_length, const void *memory, size_t memory_length)
Counts the occurrences of a block of memory in an array of memory blocks.
Definition: foundationallib.h:12799
FOUNDATIONAL_LIB_FUNC float ** sorted_float_ptrs(float **float_ptrs, size_t size)
Creates a new array containing sorted pointers to floats.
Definition: foundationallib.h:6661
FOUNDATIONAL_LIB_FUNC long rand_number_from_range_inclusive_signed(signed long min, signed long max)
Generates a random signed number within a specified range (inclusive).
Definition: foundationallib.h:12177
FOUNDATIONAL_LIB_FUNC void frozen_dict_destructor(struct FrozenDict *dict)
Deallocates memory associated with a frozen dictionary, freeing resources.
Definition: foundationallib.h:10633
FOUNDATIONAL_LIB_FUNC void print_size_t_ptr_array(const size_t **array, size_t size)
Prints the elements of a size_t array through a pointer.
Definition: foundationallib.h:1791
FOUNDATIONAL_LIB_FUNC void * dict_get(struct Dict *dict, const char *key)
Retrieves the value associated with the specified key from the dictionary.
Definition: foundationallib.h:10560
FOUNDATIONAL_LIB_FUNC int append_data_to_array(void **array, size_t *array_size, size_t *array_current_alloc_size, void *data, size_t data_size)
Appends a new element to the end of a dynamically allocated array and updates its size.
Definition: foundationallib.h:3696
FOUNDATIONAL_LIB_FUNC size_t ** sorted_size_t_ptrs(size_t **size_t_ptrs, size_t size)
Creates a new array containing sorted pointers to size_t values.
Definition: foundationallib.h:6908
FOUNDATIONAL_LIB_FUNC void print_short(const short value)
Prints a short integer value to the standard output.
Definition: foundationallib.h:12549
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_uint_ptrs(const void *a, const void *b)
Definition: foundationallib.h:5364
FOUNDATIONAL_LIB_FUNC void sort_shorts(short *shorts, size_t size)
Sorts an array of shorts in ascending order.
Definition: foundationallib.h:5947
FOUNDATIONAL_LIB_FUNC void print_long_array(const long *array, size_t size)
Prints the elements of a long array.
Definition: foundationallib.h:1476
FOUNDATIONAL_LIB_FUNC void print_ushort_ptr_array(const unsigned short **array, size_t size)
Prints an array of pointers to unsigned short integers.
Definition: foundationallib.h:1317
FOUNDATIONAL_LIB_FUNC short * sorted_shorts(short *shorts, size_t size)
Creates a new array containing sorted shorts.
Definition: foundationallib.h:5967
FOUNDATIONAL_LIB_FUNC int ints_are_sorted_descending(const int *array, size_t size)
Checks if an array of integers is sorted in descending order.
Definition: foundationallib.h:5163
FOUNDATIONAL_LIB_FUNC void reverse_string_in_place(char *str)
Reverses a string in place.
Definition: foundationallib.h:4858
#define FOUNDATIONAL_LIB_FWRITE
Definition: foundationallib.h:749
FOUNDATIONAL_LIB_FUNC void sort_uchars(unsigned char *uchars, size_t size)
Sorts an array of unsigned chars in ascending order.
Definition: foundationallib.h:5570
FOUNDATIONAL_LIB_FUNC int ints_are_sorted_ascending(const int *array, size_t size)
Checks if an array of integers is sorted in ascending order.
Definition: foundationallib.h:5140
FOUNDATIONAL_LIB_FUNC const char * sample_strings(const char **strings, size_t size)
Selects a random string from an array of strings without dynamic memory allocation.
Definition: foundationallib.h:12104
FOUNDATIONAL_LIB_FUNC void print_long_ptr_array(const long **array, size_t size)
Prints the elements of a long array.
Definition: foundationallib.h:1506
FOUNDATIONAL_LIB_FUNC char * join(const char **array, size_t count, const char *delimiter)
Joins an array of strings into a single string using a specified delimiter.
Definition: foundationallib.h:3522
FOUNDATIONAL_LIB_FUNC void sort_uchar_ptrs(unsigned char **uchar_ptrs, size_t size)
Sorts an array of pointers to unsigned chars in ascending order.
Definition: foundationallib.h:5633
FOUNDATIONAL_LIB_FUNC char * int_to_string(long long int number)
Converts an integer to its string representation.
Definition: foundationallib.h:933
FOUNDATIONAL_LIB_FUNC void * frozen_dict_get(struct FrozenDict *dict, const char *key)
Retrieves the value associated with the specified key from the frozen dictionary.
Definition: foundationallib.h:10704
FOUNDATIONAL_LIB_FUNC void sort_uint_ptrs(unsigned int **uint_ptrs, size_t size)
Definition: foundationallib.h:5380
FOUNDATIONAL_LIB_FUNC void frozen_set_destructor(struct FrozenSet *frozen_set)
The destructor for a Frozen Set.
Definition: foundationallib.h:11621
#define FOUNDATIONAL_LIB_POPEN
Definition: foundationallib.h:716
FOUNDATIONAL_LIB_FUNC int is_string_alpha(const char *string)
Check if all characters in a string are alphanumeric.
Definition: foundationallib.h:9370
FOUNDATIONAL_LIB_FUNC void set_destructor(struct Set *set)
The destructor for a Set.
Definition: foundationallib.h:11275
FOUNDATIONAL_LIB_FUNC void print_string(char *value)
Prints a string value to the standard output.
Definition: foundationallib.h:12592
FOUNDATIONAL_LIB_FUNC struct Set * set_new_instance(void)
Creates a new instance of a Set.
Definition: foundationallib.h:11301
FOUNDATIONAL_LIB_FUNC void print_ulong_ptr_array(const unsigned long **array, size_t size)
Prints an array of pointers to unsigned long integers.
Definition: foundationallib.h:1445
FOUNDATIONAL_LIB_FUNC void print_size_t_to_stream(const size_t value, FILE *stream)
Prints a size_t value to the specified stream.
Definition: foundationallib.h:12575
FOUNDATIONAL_LIB_FUNC int set_add(struct Set *set, const char *key)
Adds a key pair to the set.
Definition: foundationallib.h:11460
FOUNDATIONAL_LIB_FUNC void * dict_get_check(struct Dict *dict, const char *key, int *key_is_in_dict)
Retrieves the value associated with the specified key from the dictionary.
Definition: foundationallib.h:10599
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_longs(const void *a, const void *b)
Compare function for sorting pointers to unsigned longs.
Definition: foundationallib.h:6189
FOUNDATIONAL_LIB_FUNC size_t count_occurrences_of_string_in_array(const char **array, const char *string, size_t array_length)
Counts the occurrences of a string in an array of strings.
Definition: foundationallib.h:12732
FOUNDATIONAL_LIB_FUNC void print_float_array(const float *array, size_t size)
Prints the elements of a float array.
Definition: foundationallib.h:1658
#define FOUNDATIONAL_LIB_FREAD
Definition: foundationallib.h:745
#define FOUNDATIONAL_LIB_die_aggressively_if_enabled()
Macro to die aggressively if enabled.
Definition: foundationallib.h:878
FOUNDATIONAL_LIB_FUNC ssize_t find_first_of(const char *str, const char *char_set)
Finds the first occurrence of any character from a set in a string.
Definition: foundationallib.h:4810
FOUNDATIONAL_LIB_FUNC int is_string_alphanumeric(const char *str)
Determines whether a given string consists solely of alphanumeric characters.
Definition: foundationallib.h:4602
FOUNDATIONAL_LIB_FUNC int file_exists(const char *filename)
Checks if a file exists.
Definition: foundationallib.h:7157
FOUNDATIONAL_LIB_FUNC void print_size_t(const size_t value)
Prints a size_t value to the standard output.
Definition: foundationallib.h:12567
static FOUNDATIONAL_LIB_CONST size_t FOUNDATIONAL_LIB_safe_add_2(size_t a, size_t b)
Safely add 2 numbers to avoid unsigned integer overflows and security and stability issues....
Definition: foundationallib.h:555
FOUNDATIONAL_LIB_FUNC void print_long_to_stream(const long value, FILE *stream)
Prints a long integer value to the specified stream.
Definition: foundationallib.h:12512
FOUNDATIONAL_LIB_FUNC void * frozen_dict_get_check(struct FrozenDict *dict, const char *key, int *key_is_in_dict)
Retrieves the value associated with the specified key from the frozen dictionary.
Definition: foundationallib.h:10740
#define FOUNDATIONAL_LIB_VA_START
Definition: foundationallib.h:126
FOUNDATIONAL_LIB_FUNC int find_max_int_in_array(const int *array, size_t size)
Finds the maximum element in an array of integers.
Definition: foundationallib.h:5035
FOUNDATIONAL_LIB_FUNC void print_ulong_array_to_stream(const unsigned long *array, size_t size, FILE *stream)
Prints the elements of an unsigned long array to a specified stream.
Definition: foundationallib.h:2137
FOUNDATIONAL_LIB_FUNC void print_double_array_to_stream(const double *array, size_t size, FILE *stream)
Outputs elements of a double array to a stream.
Definition: foundationallib.h:2421
FOUNDATIONAL_LIB_FUNC void sort_ints(int *ints, size_t size)
Definition: foundationallib.h:5446
#define FOUNDATIONAL_LIB_FSEEKO
Definition: foundationallib.h:735
#define FOUNDATIONAL_LIB_FPUTC
Definition: foundationallib.h:333
static int equal_strings(const char *first, const char *second)
Compares two strings for equality.
Definition: foundationallib.h:2580
FOUNDATIONAL_LIB_FUNC void frozen_set_iter(struct Set *set, void(*callback)(char *key))
Iterates over a Set and applies a callback to each key.
Definition: foundationallib.h:12022
FOUNDATIONAL_LIB_FUNC void dict_destructor(struct Dict *dict)
Deallocates memory associated with a dictionary, freeing resources.
Definition: foundationallib.h:10250
FOUNDATIONAL_LIB_FUNC void sort_short_ptrs(short **short_ptrs, size_t size)
Sorts an array of pointers to shorts in ascending order.
Definition: foundationallib.h:6011
Definition: foundationallib.h:8752
struct DictKeyValue ** table
Definition: foundationallib.h:8753
size_t size
Definition: foundationallib.h:8755
size_t capacity
Definition: foundationallib.h:8754
Definition: foundationallib.h:8767
void * value
Definition: foundationallib.h:8769
char * key
Definition: foundationallib.h:8768
struct DictKeyValue * next
Definition: foundationallib.h:8770
Definition: foundationallib.h:8774
size_t capacity
Definition: foundationallib.h:8776
struct DictKeyValue ** table
Definition: foundationallib.h:8775
size_t size
Definition: foundationallib.h:8777
Definition: foundationallib.h:8782
size_t capacity
Definition: foundationallib.h:8784
size_t size
Definition: foundationallib.h:8785
struct SetKey ** table
Definition: foundationallib.h:8783
Definition: foundationallib.h:8759
struct SetKey ** table
Definition: foundationallib.h:8760
size_t size
Definition: foundationallib.h:8762
size_t capacity
Definition: foundationallib.h:8761
Definition: foundationallib.h:8746
struct SetKey * next
Definition: foundationallib.h:8748
char * key
Definition: foundationallib.h:8747
Definition: foundationallib.h:8801
size_t elem_size
Definition: foundationallib.h:8804
size_t start_index
Definition: foundationallib.h:8809
size_t array_size
Definition: foundationallib.h:8803
void * result
Definition: foundationallib.h:8808
size_t end_index
Definition: foundationallib.h:8810
const void * input_array
Definition: foundationallib.h:8802
size_t * result_size
Definition: foundationallib.h:8807
void(* transform_func)(void *value)
Definition: foundationallib.h:8805
int(* filter_func)(void *value)
Definition: foundationallib.h:8806