26#if !(__STDC_VERSION__ >= 201112L) && !LELY_NO_MALLOC
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 LELY_HAVE_POSIX_MEMALIGN
53 return _aligned_malloc(size, alignment);
54#elif LELY_HAVE_POSIX_MEMALIGN
56 int errc = posix_memalign(&ptr, alignment, size);
68 if ((alignment & (alignment - 1)) || alignment <
sizeof(
void *))
77 void *ptr = malloc(size + alignment);
81 void *aligned_ptr = (
void *)(((uintptr_t)(
char *)ptr + alignment - 1)
82 & ~(uintptr_t)(alignment - 1));
85 ((
void **)aligned_ptr)[-1] = ptr;
98#elif LELY_HAVE_POSIX_MEMALIGN
102 free(((
void **)ptr)[-1]);
110#if _WIN32 && !LELY_NO_STDIO
117setenv(
const char *envname,
const char *envval,
int overwrite)
124 if (!overwrite && getenv(envname))
127 for (
const char *cp = envname; *cp; cp++) {
135 if (
asprintf(&
string,
"%s=%s", envname, envval) < 0)
138 if (_putenv(
string)) {
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,...
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib....
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...