26 #if !(__STDC_VERSION__ >= 201112L)
28 #ifndef LELY_HAVE_POSIX_MEMALIGN
29 #if _POSIX_C_SOURCE >= 200112L
30 #define LELY_HAVE_POSIX_MEMALIGN 1
31 #if defined(__NEWLIB__) && !defined(__rtems__)
32 #undef LELY_HAVE_POSIX_MEMALIGN
39 #elif defined(LELY_HAVE_POSIX_MEMALIGN)
51 return _aligned_malloc(size, alignment);
52 #elif LELY_HAVE_POSIX_MEMALIGN
54 int errnum = posix_memalign(&ptr, alignment, size);
61 #else // !_WIN32 && !LELY_HAVE_POSIX_MEMALIGN
64 if ((alignment & (alignment - 1)) || alignment <
sizeof(
void *))
73 void *ptr = malloc(size + alignment);
77 void *aligned_ptr = (
void *)(((uintptr_t)(
char *)ptr + alignment - 1)
78 & ~(uintptr_t)(alignment - 1));
81 ((
void **)aligned_ptr)[-1] = ptr;
84 #endif // !_WIN32 && !LELY_HAVE_POSIX_MEMALIGN
94 #elif LELY_HAVE_POSIX_MEMALIGN
98 free(((
void **)ptr)[-1]);
102 #endif // !__USE_ISOC11
104 #endif // !(__STDC_VERSION__ >= 201112L)
113 setenv(
const char *envname,
const char *envval,
int overwrite)
120 if (!overwrite && getenv(envname))
123 for (
const char *cp = envname; *cp; cp++) {
131 if (
asprintf(&
string,
"%s=%s", envname, envval) < 0)
134 if (_putenv(
string)) {