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);
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;
94 #elif LELY_HAVE_POSIX_MEMALIGN
98 free(((
void **)ptr)[-1]);
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)) {
errnum
The platform-independent error numbers.
This is the internal header file of the C11 and POSIX compatibility library.
This header file is part of the C11 and POSIX compatibility library; it includes <stdint....
This header file is part of the C11 and POSIX compatibility library; it includes <stdio....
int asprintf(char **strp, const char *fmt,...)
Equivalent to sprintf(), except that it allocates a string large enough to hold the output,...
void aligned_free(void *ptr)
Causes the space at ptr to be deallocated, that is, made available for further allocation.
void * aligned_alloc(size_t alignment, size_t size)
Allocates space for an object whose alignment is specified by alignment, whose size is specified by s...
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib....