aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2015-10-12 00:00:00 +0200
committerMattias Andrée <maandree@operamail.com>2015-10-12 00:00:00 +0200
commit7389b031ee054699e2df35cee82af1997321d7d7 (patch)
tree39e410b8a0b448c8294d35e8e3ebb0c0d8eb055d
parentadd zalloc (diff)
downloadslibc-7389b031ee054699e2df35cee82af1997321d7d7.tar.gz
slibc-7389b031ee054699e2df35cee82af1997321d7d7.tar.bz2
slibc-7389b031ee054699e2df35cee82af1997321d7d7.tar.xz
simplified feature-test macros
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--include/assert.h2
-rw-r--r--include/ctype.h4
-rw-r--r--include/errno.h9
-rw-r--r--include/error.h4
-rw-r--r--include/malloc.h16
-rw-r--r--include/slibc/features.h31
-rw-r--r--include/stdio.h34
-rw-r--r--include/string.h68
-rw-r--r--include/strings.h2
-rw-r--r--include/unistd.h10
-rw-r--r--include/wchar.h56
11 files changed, 131 insertions, 105 deletions
diff --git a/include/assert.h b/include/assert.h
index dad6042..bf99258 100644
--- a/include/assert.h
+++ b/include/assert.h
@@ -56,7 +56,7 @@
#define static_assert _Static_assert
-#if (defined(_SLIBC_SOURCE) || defined(_GNU_SOURCE)) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE) || defined(__GNU_SOURCE)
/**
* Unless `NDEBUG` is defined, print an error message
* and abort the process, if `errnum` is non-zero.
diff --git a/include/ctype.h b/include/ctype.h
index eeff9ce..20fbb4a 100644
--- a/include/ctype.h
+++ b/include/ctype.h
@@ -55,7 +55,7 @@ int (isalpha)(int) /* [0x41, 0x5A], [0x61, 0x7A] */
#define isalpha(c) (islower(tolower(c)))
-#if defined(_GNU_SOURCE) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE)
/**
* Check whether a character is a regular blank space
* or a horizontal tabulation.
@@ -305,7 +305,7 @@ int isalpha_l(int, locale_t)
__warning("This function is dangerous, use 'iswalpha_l' instead.")
__GCC_ONLY(__attribute__((const)));
-#if defined(_GNU_SOURCE) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE)
/**
* Check whether a character is a regular blank space
* or a horizontal tabulation.
diff --git a/include/errno.h b/include/errno.h
index fc36695..fde5329 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -39,10 +39,10 @@
* assured that the value is thread-dependent
* and supported on all revisions of C.
*/
-volatile int* __errno(void) __GCC_ONLY(__attribute__((const))); /* TODO not implemented */
+volatile int* __errno(void) /* TODO not implemented */
+ __GCC_ONLY(__attribute__((const)));
-#ifndef __PORTABLE
/**
* This is the name that was used to invoke the program
* running in the current process. This is the value
@@ -60,7 +60,7 @@ volatile int* __errno(void) __GCC_ONLY(__attribute__((const))); /* TODO not impl
*
* This is a GNU and slibc extension.
*/
-#if defined(_GNU_SOURCE) || defined(_SLIBC_SOURCE)
+#if defined(__GNU_SOURCE) || defined(__SLIBC_SOURCE)
extern char* program_invocation_name; /* TODO not implemented */
#endif
@@ -73,10 +73,9 @@ extern char* program_invocation_name; /* TODO not implemented */
*
* This is a GNU extension.
*/
-#if defined(_GNU_SOURCE)
+#if defined(__GNU_SOURCE)
extern char* program_invocation_short_name; /* TODO not implemented */
#endif
-#endif
diff --git a/include/error.h b/include/error.h
index 0716530..8cce80c 100644
--- a/include/error.h
+++ b/include/error.h
@@ -60,7 +60,7 @@ void error(int, int, const char*, ...)
* @param format Formatting-string for a detailed description of what happend.
* @param args Formatting-arguments for `format`.
*/
-#if defined(_SLIBC_SOURCE)
+#if defined(__SLIBC_SOURCE)
void verror(int, int, const char*, va_list);
#endif
@@ -100,7 +100,7 @@ void error_at_line(int, int, const char*, unsigned int, const char*, ...)
* @param format Formatting-string for a detailed description of what happend.
* @param args Formatting-arguments for `format`.
*/
-#if defined(_SLIBC_SOURCE)
+#if defined(__SLIBC_SOURCE)
void verror_at_line(int, int, const char*, unsigned int, const char*, va_list);
#endif
diff --git a/include/malloc.h b/include/malloc.h
index 0b619c7..6373668 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -135,13 +135,13 @@ void free(void*)
* beginning of a memory allocation on the heap.
* However, if it is `NULL`, nothing will happen.
*/
-#ifndef __PORTABLE
+#if !defined(__PORTABLE)
void cfree(void*, ...)
__deprecated("'cfree' is deprecated and not portable, use 'free' instead.");
#endif
-#ifndef __PORTABLE
+#if !defined(__PORTABLE)
/**
* Variant of `malloc` that returns an address with a
* specified alignment.
@@ -166,9 +166,9 @@ void cfree(void*, ...)
* @throws EINVAL If `boundary` is not a power of two.
*/
void* memalign(size_t, size_t)
-#ifdef __C11__
+# ifdef __C11__
__deprecated("'memalign' has be deprecated by 'aligned_alloc' in C11.")
-#endif
+# endif
__GCC_ONLY(__attribute__((malloc, warn_unused_result)));
#endif
@@ -192,7 +192,7 @@ void* memalign(size_t, size_t)
int posix_memalign(void**, size_t, size_t)
__GCC_ONLY(__attribute__((nonnull)));
-#ifndef __PORTABLE
+#if !defined(__PORTABLE)
/**
* `valloc(n)` is equivalent to `memalign(sysconf(_SC_PAGESIZE), n)`.
*
@@ -212,8 +212,9 @@ int posix_memalign(void**, size_t, size_t)
void* valloc(size_t)
__GCC_ONLY(__attribute__((malloc, warn_unused_result)))
__deprecated("'valloc' is deprecated, use 'memalign' or 'posix_memalign' instead.");
+#endif
-#ifdef _GNU_SOURCE
+#if defined(__GNU_SOURCE)
/**
* This function works like `valloc`, except the allocation size,
* including auxiliary space, is rounded up to the next multiple
@@ -233,7 +234,6 @@ void* pvalloc(size_t)
__GCC_ONLY(__attribute__((malloc, warn_unused_result)))
__deprecated("'pvalloc' is deprecated, use 'memalign' or 'posix_memalign' instead.");
#endif
-#endif
#ifdef __C11__
/**
@@ -264,7 +264,7 @@ void* aligned_alloc(size_t, size_t)
#endif
-#if defined(_GNU_SOURCE) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE)
/**
* This function returns the allocation size of
* a memory segment.
diff --git a/include/slibc/features.h b/include/slibc/features.h
index b36fbb2..0527a60 100644
--- a/include/slibc/features.h
+++ b/include/slibc/features.h
@@ -54,6 +54,37 @@
/**
+ * Feature-test macros that also change that
+ * `_PORTABLE_SOURCE` and `_LIBRARY_HEADER`
+ * is not defined.
+ */
+#if !defined(__PORTABLE)
+# if defined(_GNU_SOURCE)
+# define __GNU_SOURCE _GNU_SOURCE
+# endif
+# if defined(_SLIBC_SOURCE)
+# define __SLIBC_SOURCE _SLIBC_SOURCE
+# endif
+# if defined(_BSD_SOURCE)
+# define __BSD_SOURCE _BSD_SOURCE
+# endif
+# if defined(_POSIX_SOURCE)
+# define __POSIX_SOURCE _POSIX_SOURCE
+# endif
+# if defined(_POSIX_C_SOURCE)
+# define __POSIX_C_SOURCE _POSIX_C_SOURCE
+# endif
+# if defined(_XOPEN_SOURCE)
+# define __XOPEN_SOURCE _XOPEN_SOURCE
+# endif
+# if defined(_ISOC11_SOURCE)
+# define __ISOC11_SOURCE _ISOC11_SOURCE
+# endif
+#endif
+
+
+
+/**
* Macro used to exclude code unless GCC is used.
*/
#if defined(__GNUC__)
diff --git a/include/stdio.h b/include/stdio.h
index 0929fd5..db4d97e 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -88,7 +88,7 @@ int printf(const char* restrict, ...)
int fprintf(FILE* restrict, const char* restrict, ...)
__GCC_ONLY(__attribute__((nonnull(1, 2), format(slibc_printf, 2, 3))));
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* This function is identical to `fprintf`,
* except it does not lock the stream.
@@ -186,7 +186,7 @@ int sprintf(char* restrict, const char* restrict, ...)
int snprintf(char* restrict, size_t, const char* restrict, ...)
__GCC_ONLY(__attribute__((nonnull(3), format(slibc_printf, 3, 4))));
-#if defined(_GNU_SOURCE) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE)
/**
* This function is identical to `sprintf`,
* except it allocates a sufficiently large
@@ -215,7 +215,7 @@ int asprintf(char** restrict, const char* restrict, ...)
__GCC_ONLY(__attribute__((nonnull(1, 2), format(slibc_printf, 2, 3), warn_unused_result)));
#endif
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* This function is identical to `asprintf`,
* except it can reuse allocated buffers.
@@ -305,7 +305,7 @@ int vprintf(const char* restrict, va_list)
int vfprintf(FILE* restrict, const char* restrict, va_list)
__GCC_ONLY(__attribute__((nonnull(1, 2))));
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* This function is identical to `fprintf_unlocked`,
* except it uses `va_list` instead of variadic argument.
@@ -398,7 +398,7 @@ int vsprintf(char* restrict, const char* restrict, va_list)
int vsnprintf(char* restrict, size_t, const char* restrict, va_list)
__GCC_ONLY(__attribute__((nonnull(1, 3))));
-#if defined(_GNU_SOURCE) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE)
/**
* This function is identical to `asprintf`,
* except it uses `va_list` instead of variadic argument.
@@ -426,7 +426,7 @@ int vasprintf(char** restrict, const char* restrict, va_list)
__GCC_ONLY(__attribute__((nonnull(1, 2), warn_unused_result)));
#endif
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* This function is identical to `bprintf`,
* except it uses `va_list` instead of variadic argument.
@@ -517,7 +517,7 @@ int wprintf(const wchar_t* restrict, ...)
int fwprintf(FILE* restrict, const wchar_t* restrict, ...)
__GCC_ONLY(__attribute__((nonnull(1, 2))));
-# if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+# if defined(__SLIBC_SOURCE)
/**
* This function is identical to `fprintf_unlocked` except
* it uses wide characters.
@@ -591,7 +591,7 @@ int dwprintf(int, const wchar_t* restrict, ...)
int swprintf(wchar_t* restrict, size_t, const wchar_t* restrict, ...)
__GCC_ONLY(__attribute__((nonnull(3))));
-# if defined(_GNU_SOURCE) && defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+# if defined(__GNU_SOURCE) && defined(__SLIBC_SOURCE)
/**
* This function is identical to `aswprintf` except
* it uses wide characters.
@@ -620,7 +620,7 @@ int aswprintf(wchar_t** restrict, const wchar_t* restrict, ...)
__GCC_ONLY(__attribute__((nonnull(1, 2), warn_unused_result)));
# endif
-# if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+# if defined(__SLIBC_SOURCE)
/**
* This function is identical to `bprintf` except
* it uses wide characters.
@@ -711,7 +711,7 @@ int vwprintf(const wchar_t* restrict, va_list)
int vfwprintf(FILE* restrict, const wchar_t* restrict, va_list)
__GCC_ONLY(__attribute__((nonnull(1, 2))));
-# if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+# if defined(__SLIBC_SOURCE)
/**
* This function is identical to `fwprintf_unlocked`,
* except it uses `va_list` instead of variadic argument.
@@ -785,7 +785,7 @@ int vdwprintf(int, const wchar_t* restrict, va_list)
int vswprintf(wchar_t* restrict, size_t, const wchar_t* restrict, va_list)
__GCC_ONLY(__attribute__((nonnull(3))));
-# if defined(_GNU_SOURCE) && defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+# if defined(__GNU_SOURCE) && defined(__SLIBC_SOURCE)
/**
* This function is identical to `aswprintf`,
* except it uses `va_list` instead of variadic argument.
@@ -814,7 +814,7 @@ int vaswprintf(wchar_t** restrict, const wchar_t* restrict, va_list)
__GCC_ONLY(__attribute__((nonnull(1, 2), warn_unused_result)));
# endif
-# if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+# if defined(__SLIBC_SOURCE)
/**
* This function is identical to `bwprintf`,
* except it uses `va_list` instead of variadic argument.
@@ -913,7 +913,7 @@ int fscanf(FILE* restrict, const char* restrict, ...)
int sscanf(const char* restrict, const char* restrict, ...)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull(1, 2), format(slibc_scanf, 2, 3))));
-#if defined (_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* This function is identical to `fscanf`,
* except it does not lock the stream.
@@ -1022,7 +1022,7 @@ int vfscanf(FILE* restrict, const char* restrict, va_list)
int vsscanf(const char* restrict, const char* restrict, va_list)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull(1, 2))));
-#if defined (_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* This function is identical to `fscanf_unlocked`,
* except it uses `va_list` instead of variadic arguments.
@@ -1127,7 +1127,7 @@ int fwscanf(FILE* restrict, const wchar_t* restrict, ...)
int swscanf(const wchar_t* restrict, const wchar_t* restrict, ...)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull(1, 2))));
-#if defined (_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* This function is identical to `fscanf_unlocked`,
* except it uses `wchar_t` instead of `char`.
@@ -1232,7 +1232,7 @@ int vfwscanf(FILE* restrict, const wchar_t* restrict, va_list)
int vswscanf(const wchar_t* restrict, const wchar_t* restrict, va_list)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull(1, 2))));
-#if defined (_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* This function is identical to `fwscanf_unlocked`,
* except it uses `va_list` instead of variadic arguments.
@@ -1291,7 +1291,7 @@ int vdwscanf(int, const wchar_t* restrict, va_list)
-#if !defined(__PORTABLE_SOURCE)
+#if !defined(__PORTABLE)
/**
* This function is identical to `scanf`.
*/
diff --git a/include/string.h b/include/string.h
index 1c47efe..047542b 100644
--- a/include/string.h
+++ b/include/string.h
@@ -21,7 +21,7 @@
#include <slibc/features.h>
-#if (defined(_BSD_SOURCE) || defined(_GNU_SOURCE)) && !defined(__PORTABLE)
+#if defined(__BSD_SOURCE) || defined(__GNU_SOURCE)
# include <strings.h>
#endif
@@ -139,9 +139,9 @@ char* __gnu_strerror_r(int, char*, size_t); /* GNU-specific strerror_r */
size_t strlen(const char*)
__GCC_ONLY(__attribute__((nonnull, warn_unused_result, pure)));
-#if (defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) || \
- defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || \
- defined(_BSD_SOURCE)) && !defined(__PORTABLE)
+#if defined(__POSIX_SOURCE) || defined(__POSIX_C_SOURCE) || \
+ defined(__XOPEN_SOURCE) || defined(__GNU_SOURCE) || \
+ defined(__BSD_SOURCE)
/**
* Variant of `strlen` that only inspects the
* beginning of s string.
@@ -177,7 +177,7 @@ void* memset(void*, int, size_t);
*/
void* memcpy(void* restrict, const void* restrict, size_t);
-#if defined(_GNU_SOURCE) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE)
/**
* Copy a memory segment to another, non-overlapping, segment.
*
@@ -201,7 +201,7 @@ void* mempcpy(void* restrict, const void* restrict, size_t);
*/
void* memmove(void*, const void*, size_t);
-#if defined(_SLIBC_SOURCE) && defined(_GNU_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE) && defined(__GNU_SOURCE)
/**
* Copy a memory segment to another, possibly overlapping, segment.
*
@@ -232,7 +232,7 @@ void* mempmove(void*, const void*, size_t);
*/
void* memccpy(void* restrict, const void* restrict, int, size_t);
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Copy a memory segment to another, possibly overlapping, segment,
* but stop if a specific byte is encountered.
@@ -274,7 +274,7 @@ char* strcpy(char* restrict, const char* restrict)
char* stpcpy(char* restrict, const char* restrict)
__GCC_ONLY(__attribute__((returns_nonnull, nonnull)));
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Copy a memory segment to another, non-overlapping, segment,
* stop when a NUL byte or a specified byte is encountered.
@@ -331,7 +331,7 @@ char* strstrcpy(char* restrict, const char* restrict, const char* restrict)
char* strncpy(char* restrict, const char* restrict, size_t)
__GCC_ONLY(__attribute__((returns_nonnull, nonnull)));
-#if defined(_GNU_SOURCE) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE)
/**
* Copy a memory segment to another, non-overlapping, segment,
* stop when a NUL byte is encountered.
@@ -352,7 +352,7 @@ char* strncpy(char* restrict, const char* restrict, size_t)
char* stpncpy(char* restrict, const char* restrict, size_t)
__GCC_ONLY(__attribute__((returns_nonnull, nonnull)));
-# if defined(_SLIBC_SOURCE)
+# if defined(__SLIBC_SOURCE)
/**
* Copy a memory segment to another, non-overlapping, segment,
* stop when a NUL byte or a specified byte is encountered.
@@ -407,7 +407,7 @@ char* strstrncpy(char* restrict, const char* restrict, const char* restrict, siz
# endif
#endif
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Copy a memory segment to another, possibly overlapping, segment,
* stop when a NUL byte is encountered.
@@ -489,7 +489,7 @@ char* strstrmove(char*, const char*, const char* restrict)
char* strnmove(char*, const char*, size_t)
__GCC_ONLY(__attribute__((returns_nonnull, nonnull)));
-# if defined(_GNU_SOURCE)
+# if defined(__GNU_SOURCE)
/**
* Copy a memory segment to another, possibly overlapping, segment,
* stop when a NUL byte is encountered.
@@ -614,8 +614,7 @@ char* strncat(char* restrict, const char* restrict, size_t)
char* strdup(const char*)
__GCC_ONLY(__attribute__((malloc, nonnull, warn_unused_result)));
-#if !defined(__PORTABLE)
-# if defined(_GNU_SOURCE)
+#if defined(__GNU_SOURCE)
/**
* Duplicate a string.
*
@@ -632,9 +631,9 @@ char* strdup(const char*)
*/
char* strndup(const char*, size_t)
__GCC_ONLY(__attribute__((malloc, nonnull, warn_unused_result)));
-# endif
+#endif
-# if defined(_SLIBC_SOURCE)
+#if defined(__SLIBC_SOURCE)
/**
* Duplicate a memory segment.
*
@@ -649,10 +648,10 @@ char* strndup(const char*, size_t)
*/
void* memdup(const void*, size_t)
__GCC_ONLY(__attribute__((malloc, nonnull, warn_unused_result)));
-# endif
+#endif
-# if defined (__GNUC__)
-# if defined(_GNU_SOURCE) || defined(_SLIBC_SOURCE)
+#if defined (__GNUC__)
+# if defined(__GNU_SOURCE) || defined(__SLIBC_SOURCE)
/**
* Duplicate a string, using dymanic stack allocation (`alloca`).
*
@@ -663,16 +662,16 @@ void* memdup(const void*, size_t)
* @return :size_t The new string. There is no way to
* detect whether the allocation failed.
*/
-# define strdupa(string) \
+# define strdupa(string) \
({ \
const char* __s = (string); \
size_t __n = strlen(__s) + 1; \
char* __r = __builtin_alloca(__n * sizeof(char)); \
memcpy(__r, __s, __n * sizeof(char)); \
})
-# endif
+# endif
-# if defined(_GNU_SOURCE)
+# if defined(__GNU_SOURCE)
/**
* Duplicate a string, using dymanic stack allocation (`alloca`).
*
@@ -685,16 +684,16 @@ void* memdup(const void*, size_t)
* @return :size_t The new string. There is no way to
* detect whether the allocation failed.
*/
-# define strndupa(string, maxlen) \
+# define strndupa(string, maxlen) \
({ \
const char* __s = (string); \
size_t __n = strnlen(__s, (maxlen)) + 1; \
char* __r = __builtin_alloca(__n * sizeof(char)); \
memcpy(__r, __s, __n * sizeof(char)); \
})
-# endif
+# endif
-# if defined(_SLIBC_SOURCE)
+# if defined(__SLIBC_SOURCE)
/**
* Duplicate a memory segment, using dymanic stack allocation (`alloca`).
*
@@ -706,13 +705,12 @@ void* memdup(const void*, size_t)
* @return :size_t The new segment. There is no way to
* detect whether the allocation failed.
*/
-# define memdupa(segment, size) \
+# define memdupa(segment, size) \
({ \
size_t __n = (size); \
void* __r = __builtin_alloca(__n); \
memcpy(__r, (segment), __n); \
})
-# endif
# endif
#endif
@@ -730,7 +728,7 @@ void* memdup(const void*, size_t)
int memcmp(const void*, const void*, size_t)
__GCC_ONLY(__attribute__((warn_unused_result, pure)));
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Compare two memory segments alphabetically in a case insensitive manner.
*
@@ -771,7 +769,7 @@ int strncmp(const char*, const char*, size_t)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure)));
-#if defined(_GNU_SOURCE) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE)
int strverscmp(const char*, const char*)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure)));
/* TODO document and implement strverscmp */
@@ -790,7 +788,7 @@ int strverscmp(const char*, const char*)
void* memchr(const void*, int, size_t)
__GCC_ONLY(__attribute__((warn_unused_result, pure)));
-#if (defined(_GNU_SOURCE) || defined(_SLIBC_SOURCE)) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE) || defined(__SLIBC_SOURCE)
/**
* Find the first occurrence of a byte in a memory segment.
* The memory segment must be known to contain the sought after byte.
@@ -837,7 +835,7 @@ void* memrchr(const void*, int, size_t)
char* strchr(const char*, int)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure)));
-#if (defined(_GNU_SOURCE) || defined(_SLIBC_SOURCE)) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE) || defined(__SLIBC_SOURCE)
/**
* Find the first occurrence of a byte in a string, or
* if there is no such byte, the end of the string.
@@ -898,7 +896,7 @@ char* strstr(const char*, const char*)
char* strcasestr(const char*, const char*)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure)));
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Finds the first occurrence of a substring.
* This search is case sensitive.
@@ -1032,7 +1030,7 @@ char* strcaseends(const char*, const char*)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure)));
#endif
-#if (defined(_GNU_SOURCE) || defined(_SLIBC_SOURCE)) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE) || defined(__SLIBC_SOURCE)
/**
* Finds the first occurrence of a substring.
* This search is case sensitive.
@@ -1154,7 +1152,7 @@ char* strsep(char** restrict, const char* restrict)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull)));
-#if defined(_GNU_SOURCE) && !defined(__PORTABLE) && !defined(basename)
+#if defined(__GNU_SOURCE) && !defined(basename)
/**
* Get the basename of a filename.
*
@@ -1173,7 +1171,7 @@ char* __gnu_basename(const char*)
#endif
-#if defined(_GNU_SOURCE) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE)
/**
* Shuffles all bytes in a string.
*
diff --git a/include/strings.h b/include/strings.h
index 7a02d1e..433cd99 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -37,7 +37,7 @@
void bzero(void*, size_t)
__deprecated("Use 'memset', 'explicit_bzero' or 'secure_free' instead.");
-#if !defined(__PORTABLE) && (defined(_SLIBC_SOURCE) || defined(_BSD_SOURCE))
+#if defined(__SLIBC_SOURCE) || defined(__BSD_SOURCE)
/**
* Override a memory segment with zeroes.
*
diff --git a/include/unistd.h b/include/unistd.h
index 9c2b419..6402c27 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -202,7 +202,7 @@ int execlp(const char*, ... /*, NULL */)
int execle(const char*, ... /*, NULL, char* const[] */)
__GCC_ONLY(__attribute__((sentinel(1), nonnull(1))));
-#if (defined(_SLIBC_SOURCE) && !defined(__PORTABLE))
+#if defined(__SLIBC_SOURCE)
/**
* Replace the current process image with a new process image.
*
@@ -302,7 +302,7 @@ int execvp(const char*, char* const[])
int execve(const char*, char* const[], char* const[])
__GCC_ONLY(__attribute__((nonnull(1))));
-#if (defined(_GNU_SOURCE) || defined(_SLIBC_SOURCE)) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE) || defined(__SLIBC_SOURCE)
/**
* Replace the current process image with a new process image.
*
@@ -336,7 +336,7 @@ int execvpe(const char*, char* const[], char* const[])
#endif
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Replace the current process image with a new process image.
*
@@ -596,7 +596,7 @@ int execvpat(int, const char*, char* const[], int)
int execveat(int, const char*, char* const[], char* const[], int)
__GCC_ONLY(__attribute__((nonnull(2))));
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Replace the current process image with a new process image.
*
@@ -643,7 +643,7 @@ int execvpeat(int, const char*, char* const[], char* const[], int)
#endif
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Replace the current process image with a new process image.
*
diff --git a/include/wchar.h b/include/wchar.h
index e9d2daa..b83f70f 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -90,7 +90,7 @@ wchar_t* wmemset(wchar_t*, wchar_t, size_t);
*/
wchar_t* wmemcpy(wchar_t* restrict, const wchar_t* restrict, size_t);
-#if defined(_GNU_SOURCE) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE)
/**
* Copy a memory segment to another, non-overlapping, segment.
*
@@ -115,7 +115,7 @@ wchar_t* wmempcpy(wchar_t* restrict, const wchar_t* restrict, size_t);
*/
wchar_t* wmemmove(wchar_t*, const wchar_t*, size_t);
-# if defined(_SLIBC_SOURCE)
+# if defined(__SLIBC_SOURCE)
/**
* Copy a memory segment to another, possibly overlapping, segment.
*
@@ -131,7 +131,7 @@ wchar_t* wmempmove(wchar_t*, const wchar_t*, size_t);
# endif
#endif
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Copy a memory segment to another, non-overlapping, segment,
* but stop if a specific character is encountered.
@@ -180,7 +180,7 @@ wchar_t* wmemcmove(wchar_t*, const wchar_t*, wchar_t, size_t);
wchar_t* wcscpy(wchar_t* restrict, const wchar_t* restrict)
__GCC_ONLY(__attribute__((returns_nonnull, nonnull)));
-#if (defined(_SLIBC_SOURCE) || defined(_GNU_SOURCE)) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE) || defined(__GNU_SOURCE)
/**
* Copy a memory segment to another, non-overlapping, segment,
* stop when a NUL wide character is encountered.
@@ -195,7 +195,7 @@ wchar_t* wcpcpy(wchar_t* restrict, const wchar_t* restrict)
__GCC_ONLY(__attribute__((returns_nonnull, nonnull)));
#endif
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Copy a memory segment to another, non-overlapping, segment,
* stop when a NUL wide character or a specified wide character
@@ -253,7 +253,7 @@ wchar_t* wcsstrcpy(wchar_t* restrict, const wchar_t* restrict, const wchar_t* re
wchar_t* wcsncpy(wchar_t* restrict, const wchar_t* restrict, size_t)
__GCC_ONLY(__attribute__((returns_nonnull, nonnull)));
-#if defined(_GNU_SOURCE) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE)
/**
* Copy a memory segment to another, non-overlapping, segment,
* stop when a NUL wide character is encountered.
@@ -274,7 +274,7 @@ wchar_t* wcsncpy(wchar_t* restrict, const wchar_t* restrict, size_t)
wchar_t* wcpncpy(wchar_t* restrict, const wchar_t* restrict, size_t)
__GCC_ONLY(__attribute__((returns_nonnull, nonnull)));
-# if defined(_SLIBC_SOURCE)
+# if defined(__SLIBC_SOURCE)
/**
* Copy a memory segment to another, non-overlapping, segment,
* stop when a NUL wide character or a specified wide character
@@ -330,7 +330,7 @@ wchar_t* wcsstrncpy(wchar_t* restrict, const wchar_t* restrict, const wchar_t* r
# endif
#endif
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Copy a memory segment to another, possibly overlapping, segment,
* stop when a NUL wide character is encountered.
@@ -413,7 +413,7 @@ wchar_t* wcsstrmove(wchar_t*, const wchar_t*, const wchar_t* restrict)
wchar_t* wcsnmove(wchar_t*, const wchar_t*, size_t)
__GCC_ONLY(__attribute__((returns_nonnull, nonnull)));
-# if defined(_GNU_SOURCE)
+# if defined(__GNU_SOURCE)
/**
* Copy a memory segment to another, possibly overlapping, segment,
* stop when a NUL wide character is encountered.
@@ -527,8 +527,7 @@ wchar_t* wcsncat(wchar_t* restrict whither, const wchar_t* restrict whence, size
/* wcpncat does not exsits because use of it would be very inefficient. */
-#if !defined(__PORTABLE)
-# if defined(_SLIBC_SOURCE) || defined(_GNU_SOURCE)
+#if defined(__SLIBC_SOURCE) || defined(__GNU_SOURCE)
/**
* Duplicate a string.
*
@@ -542,10 +541,10 @@ wchar_t* wcsncat(wchar_t* restrict whither, const wchar_t* restrict whence, size
*/
wchar_t* wcsdup(const wchar_t*)
__GCC_ONLY(__attribute__((malloc, nonnull, warn_unused_result)));
-# endif
+#endif
-# if defined(_SLIBC_SOURCE)
-# if defined(_GNU_SOURCE)
+#if defined(__SLIBC_SOURCE)
+# if defined(__GNU_SOURCE)
/**
* Duplicate a string.
*
@@ -563,7 +562,7 @@ wchar_t* wcsdup(const wchar_t*)
*/
wchar_t* wcsndup(const wchar_t*, size_t)
__GCC_ONLY(__attribute__((malloc, nonnull, warn_unused_result)));
-# endif
+# endif
/**
* Duplicate a memory segment.
@@ -580,8 +579,8 @@ wchar_t* wcsndup(const wchar_t*, size_t)
wchar_t* wmemdup(const wchar_t*, size_t)
__GCC_ONLY(__attribute__((malloc, nonnull, warn_unused_result)));
-# if defined(__GNUC__)
-# if defined(_GNU_SOURCE)
+# if defined(__GNUC__)
+# if defined(__GNU_SOURCE)
/**
* Duplicate a string, using dymanic stack allocation (`alloca`).
*
@@ -593,7 +592,7 @@ wchar_t* wmemdup(const wchar_t*, size_t)
* @return :size_t The new string. There is no way to
* detect whether the allocation failed.
*/
-# define wcsdupa(string) \
+# define wcsdupa(string) \
({ \
const char* __s = (string); \
size_t __n = wcslen(__s) + 1; \
@@ -614,14 +613,14 @@ wchar_t* wmemdup(const wchar_t*, size_t)
* @return :size_t The new string. There is no way to
* detect whether the allocation failed.
*/
-# define wstrndupa(string, maxlen) \
+# define wstrndupa(string, maxlen) \
({ \
const char* __s = (string); \
size_t __n = wcsnlen(__s, (maxlen)) + 1; \
wchar_t* __r = __builtin_alloca(__n * sizeof(wchar_t)); \
wmemcpy(__r, __s, __n); \
})
-# endif
+# endif
/**
* Duplicate a memory segment, using dymanic stack allocation (`alloca`).
@@ -634,13 +633,12 @@ wchar_t* wmemdup(const wchar_t*, size_t)
* @return :size_t The new segment. There is no way to
* detect whether the allocation failed.
*/
-# define wmemdupa(segment, size) \
+# define wmemdupa(segment, size) \
({ \
size_t __n = (size); \
wchar_t* __r = __builtin_alloca(__n * sizeof(wchar_t)); \
wmemcpy(__r, (segmetn), __n); \
})
-# endif
# endif
#endif
@@ -658,7 +656,7 @@ wchar_t* wmemdup(const wchar_t*, size_t)
int wmemcmp(const wchar_t*, const wchar_t*, size_t)
__GCC_ONLY(__attribute__((warn_unused_result, pure)));
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Compare two memory segments alphabetically in a case insensitive manner.
*
@@ -686,7 +684,7 @@ int wmemcasecmp(const wchar_t*, const wchar_t*, size_t)
int wcscmp(const wchar_t*, const wchar_t*)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure)));
-#if (defined(_GNU_SOURCE) || defined(_SLIBC_SOURCE)) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE) || defined(__SLIBC_SOURCE)
/**
* Compare two strings alphabetically in a case insensitive manner.
* Be aware, only ASCII characters are case insensitive, non-ASCII
@@ -747,7 +745,7 @@ int wcsncasecmp(const wchar_t*, const wchar_t*, size_t)
wchar_t* wmemchr(const wchar_t*, wchar_t, size_t)
__GCC_ONLY(__attribute__((warn_unused_result, pure)));
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Find the first occurrence of a wide character in a
* memory segment. The memory segment must be known to
@@ -795,7 +793,7 @@ wchar_t* wmemrchr(const wchar_t*, wchar_t, size_t)
wchar_t* wcschr(const wchar_t*, wchar_t)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure)));
-#if (defined(_GNU_SOURCE) || defined(_SLIBC_SOURCE)) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE)
/**
* Find the first occurrence of a wide character in a
* string, or if there is no such character, the end of
@@ -852,7 +850,7 @@ wchar_t* wcswcs(const wchar_t*, const wchar_t*)
wchar_t* wcsstr(const wchar_t*, const wchar_t*)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure)));
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Finds the first occurrence of a substring.
* This search is case insensitive.
@@ -1000,7 +998,7 @@ wchar_t* wcscaseends(const wchar_t*, const wchar_t*)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure)));
#endif
-#if (defined(_GNU_SOURCE) || defined(_SLIBC_SOURCE)) && !defined(__PORTABLE)
+#if defined(__GNU_SOURCE) || defined(__SLIBC_SOURCE)
/**
* Finds the first occurrence of a substring.
* This search is case sensitive.
@@ -1086,7 +1084,7 @@ wchar_t* wcspbrk(const wchar_t*, const wchar_t*)
wchar_t* wcstok(wchar_t* restrict, const wchar_t* restrict, wchar_t** restrict)
__GCC_ONLY(__attribute__((warn_unused_result, nonnull(2, 3))));
-#if defined(_SLIBC_SOURCE) && !defined(__PORTABLE)
+#if defined(__SLIBC_SOURCE)
/**
* Tokenise a string.
*