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 fputc
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)
473 FOUNDATIONAL_LIB_CONST
488 FOUNDATIONAL_LIB_CONST
537 if (b != 0 && a > SIZE_MAX / b)
551 if (b != 0 && a > SIZE_MAX / b)
562 FOUNDATIONAL_LIB_CONST
567 if (a > SIZE_MAX - b || a + b > SIZE_MAX - c)
578 FOUNDATIONAL_LIB_CONST
583 if (a > SIZE_MAX - b || b > SIZE_MAX - c)
597 if (a > SIZE_MAX - b)
611 if (a > SIZE_MAX - b || b > SIZE_MAX - c)
622 #define FOUNDATIONAL_LIB_safe_increment(variable, label_if_fails) \
623 if (FOUNDATIONAL_LIB_UNLIKELY(FOUNDATIONAL_LIB_safe_add_2_ptr((variable), 1, &(variable)) == 0)) \
628 #ifndef FOUNDATIONAL_LIB_LOW_MEMORY_USAGE
629 #define FOUNDATIONAL_LIB_LOW_MEMORY_USAGE 12
632 #ifndef FOUNDATIONAL_LIB_ALLOCATOR_DIV_AMOUNT
633 #define FOUNDATIONAL_LIB_ALLOCATOR_DIV_AMOUNT 2
639 FOUNDATIONAL_LIB_CONST
656 if (__builtin_add_overflow(old_size_to_add_at_least_one_to, old_size_to_add_at_least_one_to / div_amount, &addition))
683 if (siz > SIZE_MAX / 2 || siz > (SIZE_MAX - siz) / 2)
690 const size_t addition = siz + (siz / div_amount);
699 #ifndef FOUNDATIONAL_LIB_COPY_SIZE_AMOUNT
700 #define FOUNDATIONAL_LIB_COPY_SIZE_AMOUNT 4096
703 #if FOUNDATIONAL_LIB_UNSAFE_FUNCTIONS_ENABLED
705 #ifndef FOUNDATIONAL_LIB_POPEN_INITIAL_ALLOC_SIZE
706 #define FOUNDATIONAL_LIB_POPEN_INITIAL_ALLOC_SIZE 4096
712 #ifndef FOUNDATIONAL_LIB_ATOI
713 #define FOUNDATIONAL_LIB_ATOI atoi
718 #if FOUNDATIONAL_LIB_UNSAFE_FUNCTIONS_ENABLED
720 #define FOUNDATIONAL_LIB_POPEN _popen
721 #define FOUNDATIONAL_LIB_PCLOSE _pclose
723 #define FOUNDATIONAL_LIB_POPEN popen
724 #define FOUNDATIONAL_LIB_PCLOSE pclose
728 #ifndef FOUNDATIONAL_LIB_FERROR
729 #define FOUNDATIONAL_LIB_FERROR ferror
733 #ifndef FOUNDATIONAL_LIB_FSEEKO
734 #define FOUNDATIONAL_LIB_FSEEKO _fseeki64
737 #ifndef FOUNDATIONAL_LIB_FTELLO
738 #define FOUNDATIONAL_LIB_FTELLO _ftelli64
741 #ifndef FOUNDATIONAL_LIB_FSEEKO
742 #define FOUNDATIONAL_LIB_FSEEKO fseeko
745 #ifndef FOUNDATIONAL_LIB_FTELLO
746 #define FOUNDATIONAL_LIB_FTELLO ftello
751 #ifndef FOUNDATIONAL_LIB_FREAD
752 #define FOUNDATIONAL_LIB_FREAD fread
755 #ifndef FOUNDATIONAL_LIB_FWRITE
756 #define FOUNDATIONAL_LIB_FWRITE fwrite
759 #ifndef FOUNDATIONAL_LIB_FOPEN
760 #define FOUNDATIONAL_LIB_FOPEN fopen
763 #ifndef FOUNDATIONAL_LIB_FCLOSE
764 #define FOUNDATIONAL_LIB_FCLOSE fclose
769 #ifndef FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_MALLOC
770 #define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_MALLOC malloc
773 #ifndef FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_REALLOC
774 #define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_REALLOC realloc
777 #ifndef FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_CALLOC
778 #define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_CALLOC calloc
781 #ifndef FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_FREE
782 #define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_FREE free
785 #ifndef FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_STRDUP
786 #define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_STRDUP strdup
792 #ifndef FOUNDATIONAL_LIB_NETWORK_FUNCTIONS_ENABLED
793 #define FOUNDATIONAL_LIB_NETWORK_FUNCTIONS_ENABLED 0
796 #if FOUNDATIONAL_LIB_NETWORK_FUNCTIONS_ENABLED
797 #define FOUNDATIONAL_LIB_INITIAL_NETWORK_DOWNLOAD_BUFFER_SIZE 8192
800 #ifndef FOUNDATIONAL_LIB_HASH_INITIAL_CAPACITY
808 #define FOUNDATIONAL_LIB_HASH_INITIAL_CAPACITY 16
811 #ifndef FOUNDATIONAL_LIB_HASH_LOAD_FACTOR_THRESHOLD
820 #define FOUNDATIONAL_LIB_HASH_LOAD_FACTOR_THRESHOLD 0.75
823 #ifndef FOUNDATIONAL_LIB_FUNC
828 #define FOUNDATIONAL_LIB_FUNC static inline
831 #ifndef FOUNDATIONAL_LIB_THREAD_FUNCTIONS_ENABLED
839 #define FOUNDATIONAL_LIB_THREAD_FUNCTIONS_ENABLED 1
863 #define FOUNDATIONAL_LIB_set_aggressive_die(mode) \
865 FOUNDATIONAL_LIB_aggressive_die = (mode); \
874 #define FOUNDATIONAL_LIB_get_aggressive_die() FOUNDATIONAL_LIB_aggressive_die
876 #ifndef FOUNDATIONAL_LIB_die_aggressively_if_enabled
885 #define FOUNDATIONAL_LIB_die_aggressively_if_enabled() \
886 if (FOUNDATIONAL_LIB_UNLIKELY(FOUNDATIONAL_LIB_aggressive_die)) \
888 FOUNDATIONAL_LIB_FPRINTF(stderr, "Error: %s: %s.\n", __func__, strerror(errno)); \
889 exit(EXIT_FAILURE);
\
949 unsigned long long u;
958 u = (
long long)number;
980 char *return_value = strdup(buffer);
1003 unsigned long long a;
1006 unsigned long long u;
1013 number = 0 - number;
1015 u = (
unsigned long)number;
1056 a = unsigned_value % 10;
1057 unsigned_value /= 10;
1059 }
while (unsigned_value);
1086 utoa(number, buffer);
1095 return return_value;
1113 for (
size_t i = 0; i <
size; ++i)
1115 const unsigned int value = array[i];
1144 for (
size_t i = 0; i <
size; ++i)
1146 const unsigned int value = *array[i];
1175 for (
size_t i = 0; i <
size; ++i)
1177 const int value = array[i];
1207 for (
size_t i = 0; i <
size; ++i)
1209 const unsigned int value = *array[i];
1241 for (
size_t i = 0; i <
size; ++i)
1269 for (
size_t i = 0; i <
size; ++i)
1296 for (
size_t i = 0; i <
size; ++i)
1298 const unsigned short value = array[i];
1329 for (
size_t i = 0; i <
size; ++i)
1331 const unsigned short value = *(array[i]);
1360 for (
size_t i = 0; i <
size; ++i)
1362 const short value = array[i];
1393 for (
size_t i = 0; i <
size; ++i)
1395 const short value = *(array[i]);
1424 for (
size_t i = 0; i <
size; ++i)
1426 const unsigned long value = array[i];
1457 for (
size_t i = 0; i <
size; ++i)
1459 const unsigned long value = *(array[i]);
1488 for (
size_t i = 0; i <
size; ++i)
1490 const long value = array[i];
1518 for (
size_t i = 0; i <
size; ++i)
1520 const long value = *(array[i]);
1548 for (
size_t i = 0; i <
size; ++i)
1550 const unsigned long long value = array[i];
1579 for (
size_t i = 0; i <
size; ++i)
1581 const unsigned long long value = *(array[i]);
1609 for (
size_t i = 0; i <
size; ++i)
1611 const long long value = array[i];
1640 for (
size_t i = 0; i <
size; ++i)
1642 const long long value = *(array[i]);
1669 for (
size_t i = 0; i <
size; ++i)
1695 for (
size_t i = 0; i <
size; ++i)
1720 for (
size_t i = 0; i <
size; ++i)
1746 for (
size_t i = 0; i <
size; ++i)
1772 for (
size_t i = 0; i <
size; ++i)
1774 const size_t value = array[i];
1803 for (
size_t i = 0; i <
size; ++i)
1805 const size_t value = *(array[i]);
1834 for (
size_t i = 0; i <
size; ++i)
1861 for (
size_t i = 0; i <
size; ++i)
1886 for (
size_t i = 0; i <
size; ++i)
1913 for (
size_t i = 0; i <
size; ++i)
1939 for (
size_t i = 0; i <
size; ++i)
1964 for (
size_t i = 0; i <
size; ++i)
1990 for (
size_t i = 0; i <
size; ++i)
2017 for (
size_t i = 0; i <
size; ++i)
2043 for (
size_t i = 0; i <
size; ++i)
2070 for (
size_t i = 0; i <
size; ++i)
2095 for (
size_t i = 0; i <
size; ++i)
2122 for (
size_t i = 0; i <
size; ++i)
2148 for (
size_t i = 0; i <
size; ++i)
2175 for (
size_t i = 0; i <
size; ++i)
2200 for (
size_t i = 0; i <
size; ++i)
2227 for (
size_t i = 0; i <
size; ++i)
2254 for (
size_t i = 0; i <
size; ++i)
2256 const unsigned long long value = array[i];
2259 utoa(value, buffer);
2285 for (
size_t i = 0; i <
size; ++i)
2287 const unsigned long long value = *(array[i]);
2290 utoa(value, buffer);
2315 for (
size_t i = 0; i <
size; ++i)
2317 const unsigned long long value = array[i];
2348 for (
size_t i = 0; i <
size; ++i)
2350 const long long value = *(array[i]);
2379 for (
size_t i = 0; i <
size; ++i)
2406 for (
size_t i = 0; i <
size; ++i)
2432 for (
size_t i = 0; i <
size; ++i)
2459 for (
size_t i = 0; i <
size; ++i)
2485 for (
size_t i = 0; i <
size; ++i)
2487 #pragma GCC diagnostic push
2488 #pragma GCC diagnostic ignored "-Wpragmas"
2489 #pragma GCC diagnostic ignored "-Wformat"
2490 #pragma GCC diagnostic ignored "-Wformat-extra-args"
2493 #pragma GCC diagnostic pop
2518 for (
size_t i = 0; i <
size; ++i)
2520 #pragma GCC diagnostic push
2521 #pragma GCC diagnostic ignored "-Wpragmas"
2522 #pragma GCC diagnostic ignored "-Wformat"
2523 #pragma GCC diagnostic ignored "-Wformat-extra-args"
2526 #pragma GCC diagnostic pop
2569 for (
size_t i = 0; i < tot_size; ++i)
2571 duplicate[i] = ((
char *)array)[i];
2574 return (
void *)duplicate;
2604 for (
size_t i = 0; i <
size; ++i)
2606 if (array[i] != array2[i])
2629 for (
size_t i = 0; i <
size; ++i)
2631 if (array[i] != array2[i])
2653 for (
size_t i = 0; i <
size; ++i)
2655 if (array[i] != array2[i])
2678 for (
size_t i = 0; i <
size; ++i)
2680 if (array[i] != array2[i])
2703 for (
size_t i = 0; i <
size; ++i)
2705 if (array[i] != array2[i])
2728 for (
size_t i = 0; i <
size; ++i)
2730 if (array[i] != array2[i])
2752 for (
size_t i = 0; i <
size; ++i)
2754 if (array[i] != array2[i])
2777 for (
size_t i = 0; i <
size; ++i)
2779 if (array[i] != array2[i])
2802 for (
size_t i = 0; i <
size; ++i)
2804 if (array[i] != array2[i])
2829 for (
size_t i = 0; i <
size; ++i)
2831 if (array[i] != array2[i])
2854 for (
size_t i = 0; i <
size; ++i)
2856 if (array[i] != array2[i])
2879 for (
size_t i = 0; i <
size; ++i)
2881 if (array[i] != array2[i])
2904 for (
size_t i = 0; i <
size; ++i)
2906 if (array[i] != array2[i])
2931 for (
size_t i = 0; i <
size; ++i)
2933 if (array[i] != array2[i])
2956 for (
size_t i = 0; i <
size; ++i)
2958 if (array[i] != array2[i])
2981 for (
size_t i = 0; i <
size; ++i)
2983 if (array[i] != array2[i])
3006 for (
size_t i = 0; i <
size; ++i)
3008 if (array[i] != array2[i])
3034 for (
size_t i = 0; i <
size; ++i)
3036 if (array[i] != array2[i])
3059 for (
size_t i = 0; i <
size; ++i)
3061 if (array[i] != array2[i])
3084 for (
size_t i = 0; i <
size; ++i)
3086 if (array[i] != array2[i])
3109 for (
size_t i = 0; i <
size; ++i)
3111 if (array[i] != array2[i])
3134 for (
size_t i = 0; i <
size; ++i)
3136 if (array[i] != array2[i])
3158 for (
size_t i = 0; i <
size; ++i)
3160 if (array[i] != array2[i])
3182 for (
size_t i = 0; i <
size; ++i)
3184 if (array[i] != array2[i])
3206 for (
size_t i = 0; i <
size; ++i)
3208 if (array[i] != array2[i])
3231 for (
size_t i = 0; i <
size; ++i)
3233 if (array[i] != array2[i])
3256 size_t escaped_length = 0;
3257 size_t input_length = 0;
3261 while (input_string[input_length])
3263 if (input_string[input_length] ==
'"' || input_string[input_length] ==
'\\')
3285 json_length = escaped_length;
3293 alloc_size = json_length +
sizeof(
"");
3307 json_result[0] =
'"';
3310 for (
size_t j = 1, i = 0; i < input_length; ++i, ++j)
3315 json_result[j] =
'\\';
3320 json_result[j] = input_string[i];
3324 json_result[json_length - 1] =
'"';
3327 json_result[json_length] =
'\0';
3374 const size_t memcpy_len = end - start;
3375 size_t alloc_len = memcpy_len;
3389 result[memcpy_len] =
'\0';
3426 for (
const char *ptr =
FOUNDATIONAL_LIB_STRSTR(str, delim); ptr != NULL && (max_times == 0 || *output_size < max_times); ptr = strstr(ptr + delim_len, delim))
3444 const char *token_start;
3450 for (
size_t i = 0; i < *output_size; ++i)
3457 size_t token_length = (size_t)(ptr - token_start);
3459 if (keep_delim_in_result)
3461 token_length += delim_len;
3464 const size_t alloc_len = token_length +
sizeof(
"");
3474 result[i][token_length] =
'\0';
3476 token_start = ptr + delim_len;
3491 const size_t alloc_len = token_length +
sizeof(
"");
3502 result[i][token_length] =
'\0';
3543 size_t delimeter_length;
3547 size_t total_length;
3550 for (
size_t i = 0; i < count; ++i)
3554 total_length += new_len;
3557 total_length += delimeter_length;
3575 for (array_index = 0; array_index < count; ++array_index)
3577 const size_t len = lens[array_index];
3580 for (
size_t x = 0; x < len; ++x)
3582 result[len_so_far + x] = array[array_index][x];
3586 if (array_index < count - 1)
3589 for (
size_t i = 0; i < delimeter_length; ++i)
3591 result[len_so_far + i] = delimiter[i];
3593 len_so_far += delimeter_length;
3597 result[len_so_far] =
'\0';
3609 #pragma GCC diagnostic push
3610 #pragma GCC diagnostic ignored "-Wpragmas"
3611 #pragma GCC diagnostic ignored "-Wformat"
3612 #pragma GCC diagnostic ignored "-Wformat-extra-args"
3649 if (new_size > *string_alloc_size)
3660 *
string = new_string;
3661 *string_alloc_size = new_size;
3666 *string_length = *string_length + string_to_get_appended_length;
3669 (*string)[*string_length] =
'\0';
3679 #define FOUNDATIONAL_LIB_INITIAL_DATA_ARRAY_ALLOC_SIZE FOUNDATIONAL_LIB_INITIAL_STRING_ARRAY_ALLOC_SIZE
3712 if (*array_current_alloc_size == 0)
3718 *array_current_alloc_size = 0;
3741 if (mul > *array_current_alloc_size)
3753 *array_current_alloc_size = new_size_total;
3813 if (nsize > *array_current_alloc_size)
3824 *array_current_alloc_size = new_size_total;
3873 if (*array_current_alloc_size == 0)
3879 *array_current_alloc_size = 0;
3892 size_t new_size_total;
3900 if (new_size_total > *array_current_alloc_size)
3910 *array_current_alloc_size = new_size_total;
3913 (*array)[*array_size] = (
char *)
string;
3961 size_t new_size_total;
3969 if (new_size_total > *array_current_alloc_size)
3979 *array_current_alloc_size = new_size_total;
3982 (*array)[*array_size] = (
char *)
string;
4024 if (*array_current_alloc_size == 0)
4032 *array_size = *array_current_alloc_size = 0;
4045 if (new_size > *array_current_alloc_size)
4056 *array_current_alloc_size = new_size_total;
4116 if (new_size > *array_current_alloc_size)
4129 *array_current_alloc_size = new_size_total;
4164 for (
size_t i = 0; i < count; ++i)
4173 #if FOUNDATIONAL_LIB_UNSAFE_FUNCTIONS_ENABLED
4197 const size_t size_with_null_t = input_len + 1;
4218 for (
size_t i = 0; i < input_len; ++i)
4221 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] ==
'<')
4223 escaped[j++] =
'\\';
4225 escaped[j++] = input[i];
4263 for (i = 0, j = length - 1; i < j; ++i, j--)
4265 char temp = new_str[i];
4266 new_str[i] = new_str[j];
4301 static inline int ends_with(
const char *str,
const char *suffix)
4306 if (suffix_len > str_len)
4311 return strncmp(str + str_len - suffix_len, suffix, suffix_len) == 0;
4314 #if defined(__GNUC__) && !defined(_WIN32)
4318 #define memory_locate memmem
4329 return (
void *)haystack;
4337 const char *h = (
const char *)haystack;
4338 const char *n = (
const char *)needle;
4340 const size_t max_search = haystack_len - needle_len;
4341 for (
size_t i = 0; i <= max_search; ++i)
4345 return (
void *)(h + i);
4372 const char *pos = str;
4378 pos += substring_length;
4422 return beginning_of_substr_or_null != NULL;
4455 return (
const char *)
memory_locate(memory, memory_length, subchunk, subchunk_length) != NULL;
4492 #if defined(__GNUC__) && defined(__unix__)
4496 const size_t orig_string_length = string_length;
4500 const char *beginning_of_substr_or_null = (
const char *)
memmem(
string + pos, string_length, substring, substring_length);
4508 pos = beginning_of_substr_or_null -
string + substring_length;
4509 string_length = orig_string_length - pos;
4512 const char *pos = string;
4517 pos += substring_length;
4541 return result != NULL ? result - str : -1;
4562 const char *result = strrchr(str, chr);
4563 return result != NULL ? result - str : -1;
4584 for (
size_t i = 0; i < len; ++i)
4615 for (
size_t i = 0; i < len; ++i)
4657 for (
size_t i = 1; i < count; ++i)
4660 if (current_len < max_common_len)
4662 max_common_len = current_len;
4667 for (
size_t i = 0; i < max_common_len; ++i)
4669 for (
size_t j = 1; j < count; ++j)
4671 if (strings[j][i] != strings[0][i])
4731 return return_value;
4737 for (
size_t i = 1; i < count; ++i)
4740 if (current_len < max_common_len)
4742 max_common_len = current_len;
4747 for (
size_t i = 0; i < max_common_len; ++i)
4749 for (
size_t j = 1; j < count; ++j)
4752 if (strings[j][current_len - i - 1] != strings[0][max_common_len - i - 1])
4785 return return_value;
4803 return atof(
string);
4822 const char *result = strpbrk(str, char_set);
4847 for (ssize_t i = len - 1; i >= 0; i--)
4872 for (
size_t i = 0, j = len - 1; i < j; ++i, --j)
4899 if (*str ==
'+' || *str ==
'-')
4911 while (*str !=
'\0')
4940 const size_t min_len = (len1 < len2) ? len1 : len2;
4942 for (
size_t i = 0; i < min_len; ++i)
4944 if (str1[i] != str2[i])
4970 const size_t min_len = (len1 < len2) ? len1 : len2;
4972 for (
size_t i = 1; i <= min_len; ++i)
4974 if (str1[len1 - i] != str2[len2 - i])
5014 for (
size_t i = 0; i < len; ++i)
5019 title_case[i] = str[i];
5023 title_case[i] = make_upper ? toupper(str[i]) : tolower(str[i]);
5028 title_case[len] =
'\0';
5053 for (
size_t i = 1; i <
size; ++i)
5084 for (
size_t i = 1; i <
size; ++i)
5109 for (
size_t i = 0; i <
size; ++i)
5129 for (
size_t i = 0, j =
size - 1; i < j; ++i, --j)
5131 int temp = array[i];
5132 array[i] = array[j];
5150 for (
size_t i = 1; i <
size; ++i)
5152 if (array[i] < array[i - 1])
5173 for (
size_t i = 1; i <
size; ++i)
5175 if (array[i] > array[i - 1])
5205 const size_t size = (end - start) / step + 1;
5229 for (
size_t i = 0, value = start; i <
size; ++i, value += step)
5287 char **dup_strings = (
char **)
arraydup(strings,
size,
sizeof(
char *));
5314 return (*(
unsigned int *)a - *(
unsigned int *)b);
5349 unsigned int *dup_uints = (
unsigned int *)
arraydup(uints,
size,
sizeof(
unsigned int));
5375 return (*(
unsigned int **)a - *(
unsigned int **)b);
5413 unsigned int **dup_uint_ptrs = (
unsigned int **)
arraydup(uint_ptrs,
size,
sizeof(
unsigned int *));
5419 return dup_uint_ptrs;
5441 return (*(
int *)a - *(
int *)b);
5477 int *dup_ints = (
int *)
arraydup(ints,
size,
sizeof(
int));
5505 return (*(
int **)a - *(
int **)b);
5540 int **dup_int_ptrs = (
int **)
arraydup(int_ptrs,
size,
sizeof(
int *));
5546 return dup_int_ptrs;
5565 return (*(
unsigned char *)a - *(
unsigned char *)b);
5601 unsigned char *dup_uchars = (
unsigned char *)
arraydup(uchars,
size,
sizeof(
unsigned char));
5628 return (*(
unsigned char **)a - *(
unsigned char **)b);
5665 unsigned char **dup_uchar_ptrs = (
unsigned char **)
arraydup(uchar_ptrs,
size,
sizeof(
unsigned char *));
5671 return dup_uchar_ptrs;
5690 return (*(
char *)a - *(
char *)b);
5723 char *dup_chars = (
char *)
arraydup(chars,
size,
sizeof(
char));
5749 return (*(
char **)a - *(
char **)b);
5784 char **dup_char_ptrs = (
char **)
arraydup(char_ptrs,
size,
sizeof(
char *));
5792 return dup_char_ptrs;
5812 return (*(
unsigned short *)a - *(
unsigned short *)b);
5848 unsigned short *dup_ushorts = (
unsigned short *)
arraydup(ushorts,
size,
sizeof(
unsigned short));
5879 return (*(
unsigned short **)a - *(
unsigned short **)b);
5918 unsigned short **dup_ushort_ptrs = (
unsigned short **)
arraydup(ushort_ptrs,
size,
sizeof(
unsigned short *));
5925 return dup_ushort_ptrs;
5944 return (*(
short *)a - *(
short *)b);
5978 short *dup_shorts = (
short *)
arraydup(shorts,
size,
sizeof(
short));
6006 return (*(
short **)a - *(
short **)b);
6042 short **dup_short_ptrs = (
short **)
arraydup(short_ptrs,
size,
sizeof(
short *));
6050 return dup_short_ptrs;
6069 return (*(
unsigned long *)a - *(
unsigned long *)b);
6103 unsigned long *dup_ulongs = (
unsigned long *)
arraydup(ulongs,
size,
sizeof(
unsigned long));
6133 return (*(
unsigned long **)a - *(
unsigned long **)b);
6172 unsigned long **dup_ulong_ptrs = (
unsigned long **)
arraydup(ulong_ptrs,
size,
sizeof(
unsigned long *));
6179 return dup_ulong_ptrs;
6201 return (*(
long *)a - *(
long *)b);
6242 long *dup_longs = (
long *)
arraydup(longs,
size,
sizeof(
long));
6269 return (*(
long **)a - *(
long **)b);
6302 long **dup_long_ptrs = (
long **)
arraydup(long_ptrs,
size,
sizeof(
long *));
6309 return dup_long_ptrs;
6328 return (*(
unsigned long long *)a - *(
unsigned long long *)b);
6362 unsigned long long *dup_ulong_longs = (
unsigned long long *)
arraydup(ulong_longs,
size,
sizeof(
unsigned long long));
6369 return dup_ulong_longs;
6391 return (*(
unsigned long long **)a - *(
unsigned long long **)b);
6428 unsigned long long **dup_ulong_long_ptrs = (
unsigned long long **)
arraydup(ulong_long_ptrs,
size,
sizeof(
unsigned long long *));
6435 return dup_ulong_long_ptrs;
6454 return (*(
long long *)a - *(
long long *)b);
6485 long long *dup_long_longs = (
long long *)
arraydup(long_longs,
size,
sizeof(
long long));
6493 return dup_long_longs;
6512 return (*(
long long **)a - *(
long long **)b);
6550 long long **dup_long_long_ptrs = (
long long **)
arraydup(long_long_ptrs,
size,
sizeof(
long long *));
6557 return dup_long_long_ptrs;
6576 return (*(
float *)a - *(
float *)b);
6610 float *dup_floats = (
float *)
arraydup(floats,
size,
sizeof(
float));
6636 return (*(
float **)a - *(
float **)b);
6672 float **dup_float_ptrs = (
float **)
arraydup(float_ptrs,
size,
sizeof(
float *));
6679 return dup_float_ptrs;
6699 return (*(
double *)a - *(
double *)b);
6732 double *dup_doubles = (
double *)
arraydup(doubles,
size,
sizeof(
double));
6757 return (*(
double **)a - *(
double **)b);
6794 double **dup_double_ptrs = (
double **)
arraydup(double_ptrs,
size,
sizeof(
double *));
6800 return dup_double_ptrs;
6820 return (*(
size_t *)a - *(
size_t *)b);
6856 size_t *dup_size_ts = (
size_t *)
arraydup(size_ts,
size,
sizeof(
size_t));
6881 return (*(
size_t **)a - *(
size_t **)b);
6919 size_t **dup_size_t_ptrs = (
size_t **)
arraydup(size_t_ptrs,
size,
sizeof(
size_t *));
6928 return dup_size_t_ptrs;
6971 FILE *file = fopen(filename,
"rb");
6995 *
size = (size_t)file_size;
7018 size_t total_read = 0;
7019 const size_t file_size_size_t = (size_t)file_size;
7021 while (total_read < file_size_size_t)
7041 total_read += read_size;
7045 content[total_read] =
'\0';
7077 FILE *file = fopen(filename, mode);
7086 size_t total_written = 0;
7089 while ((write_size =
FOUNDATIONAL_LIB_FWRITE(content + total_written, 1, content_length - total_written, file)) > 0)
7091 total_written += write_size;
7154 #include <sys/stat.h>
7169 return _access(filename, 0) == 0;
7171 return access(filename, F_OK) == 0;
7190 if (stat(filename, &st) == 0)
7191 return (st.st_mode & _S_IFREG) != 0;
7193 if (stat(filename, &st) == 0)
7194 return S_ISREG(st.st_mode);
7213 if (stat(filename, &st) == 0)
7214 return (st.st_mode & _S_IFDIR) != 0;
7216 if (stat(filename, &st) == 0)
7217 return S_ISDIR(st.st_mode);
7237 return _access(filename, 4) == 0;
7239 return access(filename, R_OK) == 0;
7258 return _access(filename, 2) == 0;
7260 return access(filename, W_OK) == 0;
7279 return _access(filename, 1) == 0;
7281 return access(filename, X_OK) == 0;
7302 FILE *file = fopen(filename,
"r");
7318 const off_t file_size = ftello(file);
7376 FILE *source_file = fopen(source_filename,
"rb");
7384 FILE *destination_file = fopen(destination_filename,
"wb");
7435 size_t write_size = 0;
7436 size_t new_write_size;
7440 write_size += new_write_size;
7465 #include <windows.h>
7493 char search_path[MAX_PATH];
7494 FOUNDATIONAL_LIB_SNPRINTF(search_path, MAX_PATH,
"%s\\%s", directory, pattern);
7496 WIN32_FIND_DATA find_file_data;
7497 HANDLE find_handle = FindFirstFile(search_path, &find_file_data);
7512 if (!(find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
7516 }
while (FindNextFile(find_handle, &find_file_data) != 0);
7545 find_handle = FindFirstFile(search_path, &find_file_data);
7548 if (!(find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
7557 }
while (FindNextFile(find_handle, &find_file_data) != 0);
7574 #include <fnmatch.h>
7602 DIR *dir = opendir(directory);
7611 struct dirent *entry;
7612 while ((entry = readdir(dir)) != NULL)
7614 if (fnmatch(pattern, entry->d_name, FNM_PERIOD) == 0)
7639 while ((entry = readdir(dir)) != NULL)
7641 if (fnmatch(pattern, entry->d_name, FNM_PERIOD) == 0)
7699 for (
size_t i = 0; i < num_strings; ++i)
7701 const char *current_string = strings[i];
7704 size_t current_length_of_current_string = 0;
7705 while (current_string[current_length_of_current_string] !=
'\0')
7729 result = new_result;
7733 result[new_len++] = current_string[current_length_of_current_string++];
7738 result[new_len] =
'\0';
7767 const char *strs[2] = {str1, str2};
7812 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)
7832 p = (
const char *)source;
7834 const char *end_of_memory;
7835 end_of_memory = (
const char *)source + source_len;
7839 if ((p = (
const char *)
memory_locate((
const void *)p, (end_of_memory - p), find, find_len)) == NULL)
7841 if (matches_max && matches == matches_max)
7853 *should_free_after_use = 0;
7854 *output_length_without_nullt = source_len;
7859 *should_free_after_use = 1;
7860 *num_matches_found = matches;
7862 size_t final_len = source_len - matches * find_len + matches * replace_len;
7877 *output_length_without_nullt = final_len;
7886 p = (
const char *)source;
7891 for (matches = 0; !matches_max || (matches < matches_max); ++matches)
7893 if ((p = (
const char *)
memory_locate((
const void *)p, end_of_memory - p, find, find_len)) == NULL)
7896 if (matches_max && matches == matches_max)
7899 size_t prefix_len = p - (
const char *)source;
7909 size_t remaining_len;
7911 remaining_len = end_of_memory - (
const char *)source;
7916 rp[remaining_len] =
'\0';
7923 *output_length_without_nullt = 0;
7969 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)
7972 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);
7995 int should_free_after_use;
7997 const size_t matches_max = 0;
7999 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)
8005 if (!should_free_after_use)
8014 memcpy(new_output, output, new_len + 1);
8041 int should_free_after_use;
8043 const size_t matches_max = 1;
8045 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)
8051 if (!should_free_after_use)
8060 memcpy(new_output, output, new_len + 1);
8087 int should_free_after_use;
8089 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)
8095 if (!should_free_after_use)
8104 memcpy(new_output, output, new_len + 1);
8135 const size_t str_len = strlen(str);
8136 const size_t old_substring_len = strlen(old_substring);
8137 size_t alloc_size = str_len + 1;
8148 const char *pos = str;
8154 const char *found_pos = (
const char *)
memory_locate(pos, str_len - (pos - str), old_substring, old_substring_len);
8157 size_t remaining_len = str_len - (pos - str);
8158 memcpy(result + new_len, pos, remaining_len);
8159 new_len += remaining_len;
8161 result[new_len] =
'\0';
8163 new_len += remaining_len;
8169 char *replacement = callback(old_substring, data_for_callback);
8172 size_t replacement_len = strlen(replacement);
8176 const size_t diff = found_pos - pos;
8188 if (nlen >= alloc_size)
8198 result = new_result;
8201 memcpy(result + new_len, pos, found_pos - pos);
8202 new_len += found_pos - pos;
8203 memcpy(result + new_len, replacement, replacement_len);
8205 new_len += replacement_len;
8206 pos = found_pos + old_substring_len;
8307 for (
size_t i = 0; i < size; ++i)
8309 array[i] = transform(array[i]);
8349 int result = array[0];
8350 for (
size_t i = 1; i < size; ++i)
8352 result = operation(result, array[i]);
8403 for (
size_t i = 0; i < source_size; ++i)
8405 if (condition(source[i]))
8407 destination[count++] = source[i];
8448 for (
size_t i = 0; i < size; ++i)
8450 transform(((
char *)array) + i * elem_size);
8494 char *char_array = (
char *)array;
8495 char *char_result = (
char *)result;
8498 for (
size_t i = 0; i < elem_size; ++i)
8500 char_result[i] = char_array[i];
8503 for (
size_t i = 1; i < size; ++i)
8505 operation(char_result, char_array + i * elem_size);
8550 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 *))
8557 char *char_source = (
char *)source;
8558 char *char_destination = (
char *)destination;
8561 for (
size_t i = 0; i < source_size; ++i)
8563 if (condition(char_source + i * elem_size))
8565 if (count < dest_size)
8567 for (
size_t j = 0; j < elem_size; ++j)
8569 char_destination[count * elem_size + j] = char_source[i * elem_size + j];
8698 for (
size_t i = 0; i < array_size; ++i)
8704 if (filter_func((
void *)((
char *)input_array + i * elem_size)))
8708 void *addr = (
char *)result + (*result_size) * elem_size;
8710 transform_func(addr);
8722 #pragma GCC diagnostic push
8723 #pragma GCC diagnostic ignored "-Wpragmas"
8724 #pragma GCC diagnostic ignored "-Wuse-after-free"
8740 #pragma GCC diagnostic pop
8804 #if FOUNDATIONAL_LIB_THREAD_FUNCTIONS_ENABLED
8805 #include <threads.h>
8866 for (
size_t i = 0; i < (*thread_data->
result_size); ++i)
8871 thread_data->
result = buffer;
8980 cannot_allocate_or_create:
8991 size_t chunk_size =
array_size / thread_count;
8992 size_t remaining =
array_size % thread_count;
8993 size_t current_index = 0;
8995 for (
size_t i = 0; i < thread_count; ++i)
9001 goto cannot_allocate_or_create;
9008 thread_data[i].
result_size = &thread_result_sizes[i];
9018 current_index = thread_data[i].
end_index;
9022 goto cannot_allocate_or_create;
9026 for (
size_t i = 0; i < thread_count; ++i)
9028 int return_value_of_thread;
9029 thrd_join(threads[i], &return_value_of_thread);
9033 goto cannot_allocate_or_create;
9036 size_t total_result_size = 0;
9037 for (
size_t i = 0; i < thread_count; ++i)
9043 total_result_size += thread_result_sizes[i];
9100 size_t result_index = 0;
9103 for (
size_t i = 0; i < source_size; ++i)
9106 const void *current_source = (
char *)source + i *
elem_size;
9109 if (!condition(current_source))
9166 size_t result_index = 0;
9169 for (
size_t i = 0; i < source_size; ++i)
9171 const void *current_source = (
char *)source + i *
elem_size;
9174 if (condition(current_source))
9233 for (
size_t i = 0; i < repetitions; ++i)
9268 char *orig_str = new_str;
9271 *new_str = tolower(*new_str);
9302 char *orig_str = new_str;
9305 *new_str = toupper(*new_str);
9510 for (
size_t i = 0; i < size; ++i)
9512 const char *str = array[i];
9540 for (
size_t i = 0; i < size; ++i)
9542 const char *str = array[i];
9571 for (
size_t i = 0; i < size; ++i)
9573 const char *str = array[i];
9652 for (
size_t i = 0; i < size; ++i)
9654 (*output)[i] = NULL;
9658 for (
size_t i = 0; i < size; ++i)
9663 for (
size_t j = 0; j < count; ++j)
9674 (*output)[count] = ((
char **)array)[i];
9681 *output_size = count;
9751 for (
size_t i = 0; i < size; ++i)
9755 (*new_array)[(*new_size)++] = (
char *)first_array[i];
9784 const char *strs[3] = {str1, str2, str3};
9813 const char *strs[4] = {str1, str2, str3, str4};
9844 const char *strs[5] = {str1, str2, str3, str4, str5};
9851 #include <windows.h>
9857 #define FOUNDATIONAL_LIB_DIR_SEPARATOR '\\'
9859 #define FOUNDATIONAL_LIB_DIR_SEPARATOR '/'
9892 WIN32_FIND_DATA findFileData;
9893 HANDLE hFind = FindFirstFile(directory, &findFileData);
9903 if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
9910 char fullFilePath[MAX_PATH];
9922 const char *new_str = map_function(file_data, size);
9939 }
while (FindNextFile(hFind, &findFileData) != 0);
9948 DIR *dir = opendir(directory);
9955 struct dirent *entry;
9956 while ((entry = readdir(dir)) != NULL)
9958 if (entry->d_type == DT_REG)
9964 char fullFilePath[PATH_MAX];
9975 const char *new_str = map_function(file_data, size);
10023 WIN32_FIND_DATA findFileData;
10024 HANDLE hFind = FindFirstFile(directory, &findFileData);
10034 if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !filter_function(findFileData.cFileName))
10037 char fullFilePath[MAX_PATH];
10043 if (FindClose(hFind) == 0)
10052 }
while (FindNextFile(hFind, &findFileData) != 0);
10057 DIR *dir = opendir(directory);
10064 struct dirent *entry;
10065 while ((entry = readdir(dir)) != NULL)
10067 if (entry->d_type == DT_REG)
10069 if (!filter_function(entry->d_name))
10072 char fullFilePath[PATH_MAX];
10078 if (closedir(dir) == -1)
10126 WIN32_FIND_DATA findFileData;
10127 HANDLE hFind = FindFirstFile(directory, &findFileData);
10135 char *last_value = NULL;
10136 char *value = NULL;
10140 if (!(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && findFileData.dwFileAttributes & FILE_ATTRIBUTE_NORMAL)
10146 char fullFilePath[MAX_PATH];
10157 char *new_value = reduce_function(last_value, value, findFileData.cFileName);
10164 last_value = new_value;
10173 }
while (FindNextFile(hFind, &findFileData) != 0);
10181 DIR *dir = opendir(directory);
10188 char *last_value = NULL;
10189 char *value = NULL;
10190 struct dirent *entry;
10192 while ((entry = readdir(dir)) != NULL)
10194 if (entry->d_type == DT_REG)
10200 char fullFilePath[PATH_MAX];
10215 char *new_value = reduce_function(last_value, value, entry->d_name);
10222 last_value = new_value;
10263 for (
size_t i = 0; i < dict->
capacity; ++i)
10266 while (current_pair != NULL)
10271 current_pair = next_pair;
10296 size_t hash = 5381;
10299 while ((c = *
key++))
10301 hash = ((hash << 5) + hash) + c;
10304 return hash % capacity;
10346 for (
size_t i = 0; i < dict->
capacity; ++i)
10349 while (current_pair)
10352 const size_t new_index =
dict_hash(current_pair->
key, new_capacity);
10353 current_pair->
next = new_table[new_index];
10354 new_table[new_index] = current_pair;
10355 current_pair = next_pair;
10360 dict->
table = new_table;
10401 for (
size_t i = 0; i < dict->
capacity; ++i)
10404 while (current_pair)
10407 const size_t new_index =
dict_hash(current_pair->
key, new_capacity);
10408 current_pair->
next = new_table[new_index];
10409 new_table[new_index] = current_pair;
10410 current_pair = next_pair;
10415 dict->
table = new_table;
10441 while (current != NULL)
10468 current = current->
next;
10521 if (dict->
table[index] != NULL)
10542 current = current->
next;
10543 }
while (current != NULL);
10548 dict->
table[index] = new_pair;
10575 while (current_pair != NULL)
10579 return current_pair->
value;
10583 current_pair = current_pair->
next;
10616 while (current_pair != NULL)
10620 *key_is_in_dict = 1;
10621 return current_pair->
value;
10623 current_pair = current_pair->
next;
10626 *key_is_in_dict = 0;
10670 frozen_dict->
size = 0;
10682 for (
size_t i = 0; i < num_pairs; ++i)
10695 return frozen_dict;
10719 while (current_pair != NULL)
10723 return current_pair->
value;
10725 current_pair = current_pair->
next;
10757 while (current_pair != NULL)
10761 *key_is_in_dict = 1;
10762 return current_pair->
value;
10764 current_pair = current_pair->
next;
10767 *key_is_in_dict = 0;
10789 for (
size_t i = 0; i < dict->
capacity; ++i)
10793 while (current != NULL)
10796 callback(current->
key, current->
value);
10799 current = current->
next;
10821 for (
size_t i = 0; i < frozen_dict->
capacity; ++i)
10825 while (current != NULL)
10828 callback(current->
key, current->
value);
10831 current = current->
next;
10901 size_t alloc_size2;
10909 goto error_handler;
10918 goto error_handler;
10921 for (
size_t i = 0, index = 0; i < dict->
capacity; ++i)
10924 while (current_pair != NULL)
10926 (*keys)[index] = (current_pair->
key);
10927 (*values)[index] = current_pair->
value;
10930 current_pair = current_pair->
next;
10934 *size_of_keys_and_values = dict->
size;
10978 size_t alloc_size2;
10986 goto error_handler;
10995 goto error_handler;
10998 for (
size_t i = 0, index = 0; i < dict->
capacity; ++i)
11001 while (current_pair != NULL)
11003 (*keys)[index] = (current_pair->
key);
11004 (*values)[index] = current_pair->
value;
11007 current_pair = current_pair->
next;
11011 *size_of_keys_and_values = dict->
size;
11079 size_t total_length = 2;
11080 for (
size_t i = 0; i < dict->
capacity; ++i)
11083 while (current_pair != NULL)
11088 if (pointer_or_string == 0)
11090 total_length += FOUNDATIONAL_LIB_SNPRINTF(NULL, 0,
"%p",
11091 current_pair->
value);
11095 total_length += FOUNDATIONAL_LIB_SNPRINTF(NULL, 0,
"%s",
11096 (
char *)current_pair->
value);
11099 current_pair = current_pair->
next;
11116 for (
size_t i = 0; i < dict->
capacity; ++i)
11119 while (current_pair != NULL)
11122 if (pointer_or_string == 0)
11124 index += FOUNDATIONAL_LIB_SNPRINTF(result + index, total_length - index,
"%s: %p", current_pair->
key, current_pair->
value);
11126 else if (pointer_or_string == 1)
11128 index += FOUNDATIONAL_LIB_SNPRINTF(result + index, total_length - index,
"%s: %s", current_pair->
key, (
char *)current_pair->
value);
11130 current_pair = current_pair->
next;
11133 if (index < total_length - 2)
11135 result[index++] =
',';
11136 result[index++] =
' ';
11146 result[index++] =
'}';
11147 result[index++] =
'\0';
11175 size_t total_length = 2;
11176 for (
size_t i = 0; i < dict->
capacity; ++i)
11179 while (current_pair != NULL)
11185 if (pointer_or_string == 0)
11187 total_length += FOUNDATIONAL_LIB_SNPRINTF(NULL, 0,
"%p",
11188 current_pair->
value);
11192 total_length += FOUNDATIONAL_LIB_SNPRINTF(NULL, 0,
"%s",
11193 (
char *)current_pair->
value);
11196 current_pair = current_pair->
next;
11213 for (
size_t i = 0; i < dict->
capacity; ++i)
11216 while (current_pair != NULL)
11219 if (pointer_or_string == 0)
11221 index += FOUNDATIONAL_LIB_SNPRINTF(result + index, total_length - index,
"%s: %p", current_pair->
key, current_pair->
value);
11223 else if (pointer_or_string == 1)
11225 index += FOUNDATIONAL_LIB_SNPRINTF(result + index, total_length - index,
"%s: %s", current_pair->
key, (
char *)current_pair->
value);
11227 current_pair = current_pair->
next;
11230 if (index < total_length - 2)
11232 result[index++] =
',';
11233 result[index++] =
' ';
11243 result[index++] =
'}';
11244 result[index++] =
'\0';
11287 for (
size_t i = 0; i < set->
capacity; ++i)
11290 while (current_key != NULL)
11292 struct SetKey *next_key = current_key->
next;
11295 current_key = next_key;
11348 size_t hash = 5381;
11351 while ((c = *
key++))
11353 hash = ((hash << 5) + hash) + c;
11356 return hash % capacity;
11388 for (
size_t i = 0; i < set->
capacity; ++i)
11391 while (current_key)
11393 struct SetKey *next_key = current_key->
next;
11394 const size_t new_index =
set_hash(current_key->
key, new_capacity);
11395 current_key->
next = new_table[new_index];
11396 new_table[new_index] = current_key;
11397 current_key = next_key;
11402 set->
table = new_table;
11424 struct SetKey *prev = NULL;
11426 while (current != NULL)
11453 current = current->
next;
11502 if (set->
table[index] != NULL)
11505 struct SetKey *prev = new_set_key;
11527 current = current->
next;
11528 }
while (current != NULL);
11533 set->
table[index] = new_set_key;
11573 for (
size_t i = 0; i < set->
capacity; ++i)
11576 while (current_key)
11578 struct SetKey *next_key = current_key->
next;
11579 const size_t new_index =
set_hash(current_key->
key, new_capacity);
11580 current_key->
next = new_table[new_index];
11581 new_table[new_index] = current_key;
11582 current_key = next_key;
11587 set->
table = new_table;
11610 while (current_key != NULL)
11616 current_key = current_key->
next;
11655 frozen_set->
size = 0;
11667 for (
size_t i = 0; i < num_args; ++i)
11696 while (current_key != NULL)
11702 current_key = current_key->
next;
11721 for (
size_t i = 0; i < set->
capacity; ++i)
11725 while (current != NULL)
11728 callback(current->
key);
11731 current = current->
next;
11788 goto error_handler;
11790 for (
size_t i = 0, index = 0; i < set->
capacity; ++i)
11793 while (current_pair != NULL)
11795 (*keys)[index] = (current_pair->
key);
11798 current_pair = current_pair->
next;
11802 *size_of_keys = set->
size;
11837 goto error_handler;
11839 for (
size_t i = 0, index = 0; i < set->
capacity; ++i)
11842 while (current_pair != NULL)
11844 (*keys)[index] = (current_pair->
key);
11847 current_pair = current_pair->
next;
11851 *size_of_keys = set->
size;
11878 size_t total_length = 2;
11879 for (
size_t i = 0; i < set->
capacity; ++i)
11882 while (current_key != NULL)
11888 current_key = current_key->
next;
11907 for (
size_t i = 0; i < set->
capacity; ++i)
11910 while (current_key != NULL)
11913 index += FOUNDATIONAL_LIB_SNPRINTF(result + index, total_length - index,
"%s", current_key->
key);
11914 current_key = current_key->
next;
11917 if (index < total_length - 2)
11919 result[index++] =
',';
11920 result[index++] =
' ';
11929 result[index++] =
'}';
11930 result[index++] =
'\0';
11952 size_t total_length = 2;
11953 for (
size_t i = 0; i < frozen_set->
capacity; ++i)
11955 struct SetKey *current_key = frozen_set->
table[i];
11956 while (current_key != NULL)
11962 current_key = current_key->
next;
11979 for (
size_t i = 0; i < frozen_set->
capacity; ++i)
11981 struct SetKey *current_key = frozen_set->
table[i];
11982 while (current_key != NULL)
11985 index += FOUNDATIONAL_LIB_SNPRINTF(result + index, total_length - index,
"%s", current_key->
key);
11986 current_key = current_key->
next;
11989 if (index < total_length - 2)
11991 result[index++] =
',';
11992 result[index++] =
' ';
12002 result[index++] =
'}';
12003 result[index++] =
'\0';
12035 for (
size_t i = 0; i < set->
capacity; ++i)
12039 while (current_key != NULL)
12042 callback(current_key->
key);
12045 current_key = current_key->
next;
12067 if ((str[i] & 0x80) == 0)
12072 else if ((str[i] & 0xE0) == 0xC0)
12075 if (i + 1 >= len || (str[i + 1] & 0xC0) != 0x80)
12079 else if ((str[i] & 0xF0) == 0xE0)
12082 if (i + 2 >= len || (str[i + 1] & 0xC0) != 0x80 || (str[i + 2] & 0xC0) != 0x80)
12086 else if ((str[i] & 0xF8) == 0xF0)
12089 if (i + 3 >= len || (str[i + 1] & 0xC0) != 0x80 || (str[i + 2] & 0xC0) != 0x80 || (str[i + 3] & 0xC0) != 0x80)
12119 unsigned int rand_val;
12120 if (rand_s(&rand_val) != 0)
12126 j = rand_val % size;
12127 #elif defined(__linux__)
12128 j = (long)(drand48() * size);
12149 for (
size_t i = size - 1; i; --i)
12153 unsigned int rand_val;
12160 j = rand_val % (i + 1);
12161 #elif defined(__linux__)
12162 j = (long)(drand48() * (i + 1));
12164 j = rand() % (i + 1);
12168 char *temp = strings[i];
12169 strings[i] = strings[j];
12187 const signed long long range = max - min + 1;
12190 unsigned int rand_val;
12191 if (rand_s(&rand_val) != 0)
12197 return min + (rand_val % range);
12198 #elif defined(__linux__)
12199 return min + (long)(drand48() * range);
12201 return min + (rand() % range);
12216 const unsigned long range = max - min + 1;
12219 unsigned int rand_val;
12220 if (rand_s(&rand_val) != 0)
12226 return min + (rand_val % range);
12227 #elif defined(__linux__)
12228 return min + (
unsigned long)(drand48() * range);
12230 return min + (rand() % range);
12234 #if FOUNDATIONAL_LIB_UNSAFE_FUNCTIONS_ENABLED
12278 size_t total_read = 0;
12300 else if (total_read + read_size + 1 > output_size)
12329 output = new_output;
12331 total_read += read_size;
12346 output[total_read] =
'\0';
12348 *size = total_read;
12389 size_t size_of_file;
12418 char **lines =
split(file, num_lines, delim, 0, 1);
12543 #pragma GCC diagnostic push
12544 #pragma GCC diagnostic ignored "-Wpragmas"
12545 #pragma GCC diagnostic ignored "-Wformat"
12546 #pragma GCC diagnostic ignored "-Wformat-extra-args"
12549 #pragma GCC diagnostic pop
12587 #pragma GCC diagnostic push
12588 #pragma GCC diagnostic ignored "-Wpragmas"
12589 #pragma GCC diagnostic ignored "-Wformat"
12590 #pragma GCC diagnostic ignored "-Wformat-extra-args"
12592 #pragma GCC diagnostic pop
12684 #pragma GCC diagnostic push
12685 #pragma GCC diagnostic ignored "-Wpragmas"
12686 #pragma GCC diagnostic ignored "-Wformat"
12687 #pragma GCC diagnostic ignored "-Wformat-extra-args"
12689 #pragma GCC diagnostic pop
12701 #pragma GCC diagnostic push
12702 #pragma GCC diagnostic ignored "-Wpragmas"
12703 #pragma GCC diagnostic ignored "-Wformat"
12704 #pragma GCC diagnostic ignored "-Wformat-extra-args"
12706 #pragma GCC diagnostic pop
12749 for (
size_t i = 0; i < array_length; ++i)
12782 for (
size_t i = 0; i < array_length; ++i)
12816 for (
size_t i = 0; i < array_length; ++i)
12828 #if FOUNDATIONAL_LIB_NETWORK_FUNCTIONS_ENABLED
12832 #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"
12834 #include <curl/curl.h>
12837 FOUNDATIONAL_LIB_FUNC size_t FOUNDATIONAL_LIB_libcurl_write_callback(
char *data,
size_t n,
size_t l,
void *userp)
12850 size_t byte_max_cutoff;
12853 const size_t both = n * l;
12856 if (string->byte_max_cutoff != 0 && string->size >= string->byte_max_cutoff)
12904 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)
12912 CURL *curl = curl_easy_init();
12918 if (user_agent == NULL)
12920 user_agent = FOUNDATIONAL_LIB_DEFAULT_USER_AGENT;
12923 curl_easy_setopt(curl, CURLOPT_BUFFERSIZE, 102400L);
12924 curl_easy_setopt(curl, CURLOPT_URL, website);
12925 curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
12926 curl_easy_setopt(curl, CURLOPT_USERAGENT, user_agent);
12927 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
12928 curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
12929 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, (
long)CURL_HTTP_VERSION_2TLS);
12930 curl_easy_setopt(curl, CURLOPT_FTP_SKIP_PASV_IP, 1L);
12931 curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
12937 size_t byte_max_cutoff;
12940 data.alloc_size = FOUNDATIONAL_LIB_INITIAL_NETWORK_DOWNLOAD_BUFFER_SIZE;
12942 data.byte_max_cutoff = byte_max_cutoff;
12944 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, FOUNDATIONAL_LIB_libcurl_write_callback);
12945 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);
12946 CURLcode curlcode = curl_easy_perform(curl);
12948 curl_easy_cleanup(curl);
12950 *
string = data.string;
12952 *str_alloc_size = data.alloc_size;
12954 return curlcode == CURLE_OK;
12977 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)
12989 for (
size_t i = 0; i < num_websites; ++i)
12992 if (download_website(websites_to_download[i], (*outputs) + i, (*lens) + i, &alloc_size, byte_limit, NULL) == -1)
12994 if (aggressive_stop_on_error)
13047 for (
size_t i = 0; i < num_files; ++i)
13054 if ((*outputs)[i] == NULL)
13056 if (aggressive_stop_on_error)
13067 #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:9464
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:6525
FOUNDATIONAL_LIB_FUNC int is_string_valid_integer(const char *str)
Checks if a string is a valid integer.
Definition: foundationallib.h:4889
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:10862
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:1291
FOUNDATIONAL_LIB_FUNC int shuffle_strings_in_place(char **strings, size_t size)
Shuffles an array of strings in place.
Definition: foundationallib.h:12145
FOUNDATIONAL_LIB_FUNC unsigned int ** sorted_uint_ptrs(unsigned int **uint_ptrs, size_t size)
Definition: foundationallib.h:5408
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:10967
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:1543
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:6359
FOUNDATIONAL_LIB_FUNC unsigned char * sorted_uchars(unsigned char *uchars, size_t size)
Creates a new array containing sorted unsigned chars.
Definition: foundationallib.h:5597
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:3057
#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:1236
#define FOUNDATIONAL_LIB_FUNC
Definition: foundationallib.h:828
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:7989
FOUNDATIONAL_LIB_FUNC int string_to_int(const char *str)
Converts a string to an integer.
Definition: foundationallib.h:6941
static void dict_del_keys(char **keys)
Deallocates memory associated with an array of keys.
Definition: foundationallib.h:11032
FOUNDATIONAL_LIB_FUNC unsigned long * sorted_ulongs(unsigned long *ulongs, size_t size)
Creates a new array containing sorted unsigned longs.
Definition: foundationallib.h:6100
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:2402
FOUNDATIONAL_LIB_FUNC int remove_file(const char *filename)
Removes a file.
Definition: foundationallib.h:7347
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:1830
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:1419
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:3416
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:8035
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:5892
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:5662
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:1635
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:3864
static size_t FOUNDATIONAL_LIB_REALLOC_REALLOCATION_ALGORITHM(size_t siz)
Definition: foundationallib.h:668
FOUNDATIONAL_LIB_FUNC void sort_uints(unsigned int *uints, size_t size)
Definition: foundationallib.h:5326
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:5196
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:6146
FOUNDATIONAL_LIB_FUNC size_t dict_size(struct Dict *dict)
Returns the number of key-value pairs in the dictionary.
Definition: foundationallib.h:10845
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:4559
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:9567
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:2750
FOUNDATIONAL_LIB_FUNC char * string_to_lowercase(char *string)
Convert a string to lowercase.
Definition: foundationallib.h:9256
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:4932
#define FOUNDATIONAL_LIB_LIKELY(x)
Definition: foundationallib.h:423
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:12681
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:9141
FOUNDATIONAL_LIB_FUNC void sort_doubles(double *doubles, size_t size)
Sorts an array of doubles in ascending order.
Definition: foundationallib.h:6710
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:8081
FOUNDATIONAL_LIB_FUNC void * replicate(const void *source, size_t source_size, size_t elem_size, size_t repetitions)
Definition: foundationallib.h:9203
FOUNDATIONAL_LIB_FUNC char * dict_to_string(struct Dict *dict, int pointer_or_string)
Converts a dictionary to a string representation.
Definition: foundationallib.h:11073
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:12670
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:1767
#define FOUNDATIONAL_LIB_VA_LIST
Definition: foundationallib.h:122
#define FOUNDATIONAL_LIB_FCLOSE
Definition: foundationallib.h:764
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:8667
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:10484
FOUNDATIONAL_LIB_FUNC char * reverse_string(const char *str)
Reverses a given string.
Definition: foundationallib.h:4251
FOUNDATIONAL_LIB_FUNC void print_int(const int value)
Prints an integer value to the standard output.
Definition: foundationallib.h:12493
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:1960
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:6752
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:2602
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:10817
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:12059
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:7969
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_int_ptrs(const void *a, const void *b)
Definition: foundationallib.h:5500
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:2548
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:1574
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:9778
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:3032
#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:12633
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:6038
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:2250
FOUNDATIONAL_LIB_FUNC void print_float(const float value)
Prints a single-precision floating-point value to the standard output.
Definition: foundationallib.h:12474
#define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_FREE
Definition: foundationallib.h:782
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:8129
#define FOUNDATIONAL_LIB_HASH_LOAD_FACTOR_THRESHOLD
Load factor threshold for hash tables in the foundational library.
Definition: foundationallib.h:820
#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:11823
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:4476
FOUNDATIONAL_LIB_FUNC void print_uint(const unsigned int value)
Prints an unsigned int value to the standard output.
Definition: foundationallib.h:12644
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_ints(const void *a, const void *b)
Definition: foundationallib.h:5435
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:6214
FOUNDATIONAL_LIB_FUNC void print_ulong(const unsigned long value)
Prints an unsigned long value to the standard output.
Definition: foundationallib.h:12662
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:4962
FOUNDATIONAL_LIB_FUNC void print_char_to_stream(const char value, FILE *stream)
Prints a character value to the specified stream.
Definition: foundationallib.h:12444
static void frozen_dict_del_keys(char **keys)
Deletes keys from a frozen dictionary.
Definition: foundationallib.h:11256
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:6168
FOUNDATIONAL_LIB_FUNC int is_string_digit(const char *string)
Check if all characters in a string are digits.
Definition: foundationallib.h:9405
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:2651
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:6339
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:2514
FOUNDATIONAL_LIB_FUNC void reverse_int_array_in_place(int *array, size_t size)
Reverses an array of integers in place.
Definition: foundationallib.h:5125
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:5104
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:10324
FOUNDATIONAL_LIB_FUNC void sort_int_ptrs(int **int_ptrs, size_t size)
Definition: foundationallib.h:5517
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:3004
#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:6450
FOUNDATIONAL_LIB_FUNC unsigned short * sorted_ushorts(unsigned short *ushorts, size_t size)
Creates a new array containing sorted unsigned shorts.
Definition: foundationallib.h:5845
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:4537
#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:2852
FOUNDATIONAL_LIB_FUNC int is_string_numeric(const char *str)
Checks if the provided string consists solely of numeric characters.
Definition: foundationallib.h:4577
FOUNDATIONAL_LIB_FUNC unsigned int * sorted_uints(unsigned int *uints, size_t size)
Definition: foundationallib.h:5345
#define FOUNDATIONAL_LIB_safe_increment(variable, label_if_fails)
Definition: foundationallib.h:622
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:6404
#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:8442
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:2676
FOUNDATIONAL_LIB_FUNC double * sorted_doubles(double *doubles, size_t size)
Creates a new array containing sorted doubles.
Definition: foundationallib.h:6729
#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:5309
#define FOUNDATIONAL_LIB_POPEN_INITIAL_ALLOC_SIZE
Definition: foundationallib.h:706
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:2726
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:6894
FOUNDATIONAL_LIB_FUNC void utoa(size_t unsigned_value, char *output)
Definition: foundationallib.h:1045
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:2800
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:6769
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:6508
FOUNDATIONAL_LIB_AGGRESSIVE_DIE_TYPE FOUNDATIONAL_LIB_aggressive_die
Global variable to control aggressive die behavior.
Definition: foundationallib.h:854
#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:10432
#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:7274
FOUNDATIONAL_LIB_FUNC void print_string_array_array(char ***array, size_t size)
Prints an array of arrays of strings.
Definition: foundationallib.h:1264
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:12383
FOUNDATIONAL_LIB_FUNC void set_del_keys(char **keys)
Deletes keys from a Set.
Definition: foundationallib.h:11869
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:2455
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:6001
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:6648
FOUNDATIONAL_LIB_FUNC void sort_floats(float *floats, size_t size)
Sorts an array of floats in ascending order.
Definition: foundationallib.h:6587
#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:12512
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:579
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:2929
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:12463
FOUNDATIONAL_LIB_FUNC char * sorted_chars(char *chars, size_t size)
Creates a new array containing sorted chars.
Definition: foundationallib.h:5720
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:2954
FOUNDATIONAL_LIB_FUNC int append_string_to_file(const char *filename, const char *content)
Appends a string to a file.
Definition: foundationallib.h:7139
FOUNDATIONAL_LIB_FUNC void sort_chars(char *chars, size_t size)
Sorts an array of chars in ascending order.
Definition: foundationallib.h:5701
static int starts_with(const char *str, const char *prefix)
Definition: foundationallib.h:4284
FOUNDATIONAL_LIB_FUNC int dict_resize(struct Dict *dict)
Resizes the hash table of the dictionary to optimize performance.
Definition: foundationallib.h:10378
static int ends_with(const char *str, const char *suffix)
Checks whether a given string ends with a specified suffix.
Definition: foundationallib.h:4301
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:12652
FOUNDATIONAL_LIB_FUNC int frozen_set_in(struct FrozenSet *set, const char *key)
Checks if a key is in a FrozenSet.
Definition: foundationallib.h:11689
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:3180
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:5760
FOUNDATIONAL_LIB_FUNC char * frozen_set_to_string(struct FrozenSet *frozen_set)
Converts a frozen set to a string representation.
Definition: foundationallib.h:11947
static double str_to_double(const char *string)
Converts a string to a double-precision floating-point number.
Definition: foundationallib.h:4798
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:8395
FOUNDATIONAL_LIB_FUNC int file_is_regular(const char *filename)
Checks if a file is a regular file.
Definition: foundationallib.h:7184
FOUNDATIONAL_LIB_FUNC void sort_ulongs(unsigned long *ulongs, size_t size)
Sorts an array of unsigned longs in ascending order.
Definition: foundationallib.h:6081
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:12482
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:2039
#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:2066
FOUNDATIONAL_LIB_FUNC int file_is_writable(const char *filename)
Checks if a file is writable.
Definition: foundationallib.h:7253
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:6546
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:3635
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:7372
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:2481
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:595
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:12539
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:1742
FOUNDATIONAL_LIB_FUNC char * dup_format(const char *format,...)
Duplicates a formatted string.
Definition: foundationallib.h:8232
FOUNDATIONAL_LIB_FUNC char * string_to_title_case(const char *str)
Converts a string to title case.
Definition: foundationallib.h:4993
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:9836
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:5744
#define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_STRDUP
Definition: foundationallib.h:786
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_shorts(const void *a, const void *b)
Compare function for sorting shorts.
Definition: foundationallib.h:5940
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:2013
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_uchars(const void *a, const void *b)
Compare function for sorting unsigned chars.
Definition: foundationallib.h:5561
#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:4323
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:9536
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:6280
#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:10660
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:3132
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:549
FOUNDATIONAL_LIB_FUNC float * sorted_floats(float *floats, size_t size)
Creates a new array containing sorted floats.
Definition: foundationallib.h:6606
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:2979
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:3204
FOUNDATIONAL_LIB_FUNC char * set_to_string(struct Set *set)
Definition: foundationallib.h:11872
FOUNDATIONAL_LIB_FUNC int is_string_upper(const char *string)
Check if all characters in a string are uppercase.
Definition: foundationallib.h:9324
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:6324
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:12214
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:4719
FOUNDATIONAL_LIB_FUNC size_t frozen_set_size(struct FrozenSet *set)
Returns the size of a FrozenSet.
Definition: foundationallib.h:11759
static 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:533
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:11170
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:1857
FOUNDATIONAL_LIB_FUNC void print_double_array(const double *array, size_t size)
Prints the elements of a double array.
Definition: foundationallib.h:1716
FOUNDATIONAL_LIB_FUNC void print_int_array(const int *array, size_t size)
Prints the elements of an int array.
Definition: foundationallib.h:1170
FOUNDATIONAL_LIB_FUNC char * string_to_json(const char *input_string)
Converts a given input string to its JSON representation.
Definition: foundationallib.h:3253
FOUNDATIONAL_LIB_FUNC void frozen_set_del_keys(char **keys)
Deletes keys from a FrozenSet.
Definition: foundationallib.h:12015
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:5914
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:9722
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:5781
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:13036
static void free_array(void **array, size_t len)
Frees a dynamic array and its elements up to one level deep.
Definition: foundationallib.h:903
FOUNDATIONAL_LIB_FUNC void print_long_long(const long long value)
Prints a long long integer value to the standard output.
Definition: foundationallib.h:12531
FOUNDATIONAL_LIB_FUNC char * string_to_uppercase(char *string)
Convert a string to uppercase.
Definition: foundationallib.h:9292
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:4443
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:1202
FOUNDATIONAL_LIB_FUNC int get_file_size(const char *filename, size_t *size)
Gets the size of a file.
Definition: foundationallib.h:7297
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:8893
FOUNDATIONAL_LIB_FUNC int is_array_digit(const char **array, size_t size)
Check if a string array contains only digits.
Definition: foundationallib.h:9506
FOUNDATIONAL_LIB_FUNC int file_is_directory(const char *filename)
Checks if a file is a directory.
Definition: foundationallib.h:7207
FOUNDATIONAL_LIB_FUNC long * sorted_longs(long *longs, size_t size)
Creates a new array containing sorted pointers to unsigned longs.
Definition: foundationallib.h:6237
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:1909
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:7812
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:922
FOUNDATIONAL_LIB_FUNC int is_string_lower(const char *string)
Check if all characters in a string are lowercase.
Definition: foundationallib.h:9351
FOUNDATIONAL_LIB_FUNC void print_ushort(const unsigned short value)
Print an unsigned short value.
Definition: foundationallib.h:12713
#define FOUNDATIONAL_LIB_COPY_SIZE_AMOUNT
Definition: foundationallib.h:700
FOUNDATIONAL_LIB_FUNC void print_char(const char value)
Prints a character value to the standard output.
Definition: foundationallib.h:12436
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:9622
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:2877
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:2281
#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:11645
#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:6852
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:11553
#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:11416
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:7072
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:6128
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:2627
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:10784
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:1108
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:6424
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:1986
FOUNDATIONAL_LIB_FUNC char * backticks(const char *command, size_t *size)
Executes a command and reads its output into a string.
Definition: foundationallib.h:12255
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:8550
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:6386
#define FOUNDATIONAL_LIB_FERROR
Definition: foundationallib.h:729
FOUNDATIONAL_LIB_FUNC char * concatenate_strings(const char *str1, const char *str2)
Concatenates two strings.
Definition: foundationallib.h:7762
FOUNDATIONAL_LIB_FUNC void sort_ushorts(unsigned short *ushorts, size_t size)
Sorts an array of unsigned shorts in ascending order.
Definition: foundationallib.h:5824
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_list_comprehension_worker(void *data)
Definition: foundationallib.h:8825
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:3793
#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:2701
#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:11270
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:3082
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:6482
#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:10891
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:2344
FOUNDATIONAL_LIB_FUNC int * sorted_ints(int *ints, size_t size)
Definition: foundationallib.h:5472
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:1000
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:1604
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_chars(const void *a, const void *b)
Compare function for sorting chars.
Definition: foundationallib.h:5686
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:6299
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:10120
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:11775
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:6464
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:4405
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:1882
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:2311
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:2223
#define FOUNDATIONAL_LIB_DIR_SEPARATOR
Definition: foundationallib.h:9859
#define FOUNDATIONAL_LIB_FTELLO
Definition: foundationallib.h:746
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:2902
#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:12565
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:3948
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:609
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:3156
#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:12721
FOUNDATIONAL_LIB_FUNC int write_file(const char *filename, const char *content)
Writes a string to a file.
Definition: foundationallib.h:7116
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:8344
#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:6832
#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:6877
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:6264
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:1139
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:1355
#define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_MALLOC
Definition: foundationallib.h:770
FOUNDATIONAL_LIB_FUNC void print_int_to_stream(const int value, FILE *stream)
Prints an integer value to the specified stream.
Definition: foundationallib.h:12501
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:7595
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:8488
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:2375
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:3228
FOUNDATIONAL_LIB_FUNC int ** sorted_int_ptrs(int **int_ptrs, size_t size)
Definition: foundationallib.h:5537
FOUNDATIONAL_LIB_FUNC void print_string_to_stream(char *value, FILE *stream)
Prints a string value to the specified stream.
Definition: foundationallib.h:12612
FOUNDATIONAL_LIB_FUNC char ** sorted_strings(char **strings, size_t size)
Creates a new array of strings sorted in ascending order.
Definition: foundationallib.h:5282
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:1935
FOUNDATIONAL_LIB_FUNC int is_string_space(const char *string)
Check if all characters in a string are spaces.
Definition: foundationallib.h:9431
#define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_CALLOC
Definition: foundationallib.h:778
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:9806
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:8302
FOUNDATIONAL_LIB_FUNC char * strip(const char *str)
Trims leading and trailing whitespace from a given string.
Definition: foundationallib.h:3349
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:4840
FOUNDATIONAL_LIB_FUNC size_t set_size(struct Set *set)
Returns the size of a Set.
Definition: foundationallib.h:11744
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:2118
#define FOUNDATIONAL_LIB_HASH_INITIAL_CAPACITY
Initial capacity for hash tables (dict, frozendict, set, frozenset).
Definition: foundationallib.h:808
FOUNDATIONAL_LIB_FUNC int set_resize(struct Set *set)
Resizes a Set data structure.
Definition: foundationallib.h:11367
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:10018
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:2775
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_floats(const void *a, const void *b)
Compare function for sorting floats.
Definition: foundationallib.h:6572
FOUNDATIONAL_LIB_FUNC char * shellescape(const char *input)
Escapes special characters in a given string for shell usage.
Definition: foundationallib.h:4192
#define FOUNDATIONAL_LIB_MEMORY_ALLOCATOR_REALLOC
Definition: foundationallib.h:774
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:11345
static void dict_del_values(void **values)
Deallocates memory associated with an array of values.
Definition: foundationallib.h:11049
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_ushorts(const void *a, const void *b)
Compare function for sorting unsigned shorts.
Definition: foundationallib.h:5807
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:6964
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:4016
#define FOUNDATIONAL_LIB_ALLOCATOR_DIV_AMOUNT
Definition: foundationallib.h:633
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:4159
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:4097
FOUNDATIONAL_LIB_FUNC int set_in(struct Set *set, const char *key)
Checks if a key is in a Set.
Definition: foundationallib.h:11602
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:2196
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:2171
FOUNDATIONAL_LIB_FUNC void sort_strings(char **strings, size_t size)
Sorts an array of strings.
Definition: foundationallib.h:5264
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:4367
#define FOUNDATIONAL_LIB_FPUTS
Definition: foundationallib.h:325
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmpstringp(const void *p1, const void *p2)
Definition: foundationallib.h:5251
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_ulongs(const void *a, const void *b)
Compare function for sorting unsigned longs.
Definition: foundationallib.h:6065
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:3107
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_doubles(const void *a, const void *b)
Compare function for sorting doubles.
Definition: foundationallib.h:6694
#define FOUNDATIONAL_LIB_ATOI
Definition: foundationallib.h:713
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:7681
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:9076
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:6815
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:5624
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:1691
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:9885
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:4639
FOUNDATIONAL_LIB_FUNC void print_double(const double value)
Prints a double-precision floating-point value to the standard output.
Definition: foundationallib.h:12455
#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:5073
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:6632
#define FOUNDATIONAL_LIB_INITIAL_DATA_ARRAY_ALLOC_SIZE
Definition: foundationallib.h:3679
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:5873
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:6789
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:2091
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:10292
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:11716
#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:1388
FOUNDATIONAL_LIB_FUNC void print_uchar(const unsigned char value)
Prints an unsigned char value to the standard output.
Definition: foundationallib.h:12625
#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:7232
FOUNDATIONAL_LIB_FUNC char * uint_to_string(size_t number)
Converts an integer to its string representation.
Definition: foundationallib.h:1082
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:2827
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:12698
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:12774
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:12807
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:6668
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:12185
FOUNDATIONAL_LIB_FUNC void frozen_dict_destructor(struct FrozenDict *dict)
Deallocates memory associated with a frozen dictionary, freeing resources.
Definition: foundationallib.h:10641
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:1798
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:10568
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:3703
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:6915
FOUNDATIONAL_LIB_FUNC void print_short(const short value)
Prints a short integer value to the standard output.
Definition: foundationallib.h:12557
FOUNDATIONAL_LIB_FUNC int FOUNDATIONAL_LIB_cmp_uint_ptrs(const void *a, const void *b)
Definition: foundationallib.h:5371
FOUNDATIONAL_LIB_FUNC void sort_shorts(short *shorts, size_t size)
Sorts an array of shorts in ascending order.
Definition: foundationallib.h:5954
FOUNDATIONAL_LIB_FUNC void print_long_array(const long *array, size_t size)
Prints the elements of a long array.
Definition: foundationallib.h:1483
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:1324
FOUNDATIONAL_LIB_FUNC short * sorted_shorts(short *shorts, size_t size)
Creates a new array containing sorted shorts.
Definition: foundationallib.h:5974
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:5170
FOUNDATIONAL_LIB_FUNC void reverse_string_in_place(char *str)
Reverses a string in place.
Definition: foundationallib.h:4865
#define FOUNDATIONAL_LIB_FWRITE
Definition: foundationallib.h:756
FOUNDATIONAL_LIB_FUNC void sort_uchars(unsigned char *uchars, size_t size)
Sorts an array of unsigned chars in ascending order.
Definition: foundationallib.h:5577
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:5147
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:12112
FOUNDATIONAL_LIB_FUNC void print_long_ptr_array(const long **array, size_t size)
Prints the elements of a long array.
Definition: foundationallib.h:1513
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:3529
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:5640
FOUNDATIONAL_LIB_FUNC char * int_to_string(long long int number)
Converts an integer to its string representation.
Definition: foundationallib.h:940
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:10712
FOUNDATIONAL_LIB_FUNC void sort_uint_ptrs(unsigned int **uint_ptrs, size_t size)
Definition: foundationallib.h:5387
FOUNDATIONAL_LIB_FUNC void frozen_set_destructor(struct FrozenSet *frozen_set)
The destructor for a Frozen Set.
Definition: foundationallib.h:11629
#define FOUNDATIONAL_LIB_POPEN
Definition: foundationallib.h:723
FOUNDATIONAL_LIB_FUNC int is_string_alpha(const char *string)
Check if all characters in a string are alphanumeric.
Definition: foundationallib.h:9378
FOUNDATIONAL_LIB_FUNC void set_destructor(struct Set *set)
The destructor for a Set.
Definition: foundationallib.h:11283
FOUNDATIONAL_LIB_FUNC void print_string(char *value)
Prints a string value to the standard output.
Definition: foundationallib.h:12600
FOUNDATIONAL_LIB_FUNC struct Set * set_new_instance(void)
Creates a new instance of a Set.
Definition: foundationallib.h:11309
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:1452
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:12583
FOUNDATIONAL_LIB_FUNC int set_add(struct Set *set, const char *key)
Adds a key pair to the set.
Definition: foundationallib.h:11468
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:10607
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:6196
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:12740
FOUNDATIONAL_LIB_FUNC void print_float_array(const float *array, size_t size)
Prints the elements of a float array.
Definition: foundationallib.h:1665
#define FOUNDATIONAL_LIB_FREAD
Definition: foundationallib.h:752
#define FOUNDATIONAL_LIB_die_aggressively_if_enabled()
Macro to die aggressively if enabled.
Definition: foundationallib.h:885
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:4817
FOUNDATIONAL_LIB_FUNC int is_string_alphanumeric(const char *str)
Determines whether a given string consists solely of alphanumeric characters.
Definition: foundationallib.h:4609
FOUNDATIONAL_LIB_FUNC int file_exists(const char *filename)
Checks if a file exists.
Definition: foundationallib.h:7164
FOUNDATIONAL_LIB_FUNC void print_size_t(const size_t value)
Prints a size_t value to the standard output.
Definition: foundationallib.h:12575
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:563
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:12520
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:10748
#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:5042
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:2144
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:2428
FOUNDATIONAL_LIB_FUNC void sort_ints(int *ints, size_t size)
Definition: foundationallib.h:5453
#define FOUNDATIONAL_LIB_FSEEKO
Definition: foundationallib.h:742
#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:2587
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:12030
FOUNDATIONAL_LIB_FUNC void dict_destructor(struct Dict *dict)
Deallocates memory associated with a dictionary, freeing resources.
Definition: foundationallib.h:10258
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:6018
Definition: foundationallib.h:8760
struct DictKeyValue ** table
Definition: foundationallib.h:8761
size_t size
Definition: foundationallib.h:8763
size_t capacity
Definition: foundationallib.h:8762
Definition: foundationallib.h:8775
void * value
Definition: foundationallib.h:8777
char * key
Definition: foundationallib.h:8776
struct DictKeyValue * next
Definition: foundationallib.h:8778
Definition: foundationallib.h:8782
size_t capacity
Definition: foundationallib.h:8784
struct DictKeyValue ** table
Definition: foundationallib.h:8783
size_t size
Definition: foundationallib.h:8785
Definition: foundationallib.h:8790
size_t capacity
Definition: foundationallib.h:8792
size_t size
Definition: foundationallib.h:8793
struct SetKey ** table
Definition: foundationallib.h:8791
Definition: foundationallib.h:8767
struct SetKey ** table
Definition: foundationallib.h:8768
size_t size
Definition: foundationallib.h:8770
size_t capacity
Definition: foundationallib.h:8769
Definition: foundationallib.h:8754
struct SetKey * next
Definition: foundationallib.h:8756
char * key
Definition: foundationallib.h:8755
Definition: foundationallib.h:8809
size_t elem_size
Definition: foundationallib.h:8812
size_t start_index
Definition: foundationallib.h:8817
size_t array_size
Definition: foundationallib.h:8811
void * result
Definition: foundationallib.h:8816
size_t end_index
Definition: foundationallib.h:8818
const void * input_array
Definition: foundationallib.h:8810
size_t * result_size
Definition: foundationallib.h:8815
void(* transform_func)(void *value)
Definition: foundationallib.h:8813
int(* filter_func)(void *value)
Definition: foundationallib.h:8814