Feature test macros overhaul: stdlib.h

Throughout, simplify the C99/C11 conditionals, and replace
__STRICT_ANSI__ with the proper internal POSIX macros.  The _*_r
reentrant functions need not be guarded (and most haven't been) because
such names in the global scope are reserved to the implementation.

atoff is unique to newlib.

dtoa is not actually exported (_dtoa_r is used internally), is
nonstandard, and the declaration conflicts with the code included in
MySQL, NSPR, and SpiderMonkey.

mktemp was removed in POSIX.1-2001.

The qsort_r declarations are reordered so that the GNU version retains
precedence.

Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
This commit is contained in:
Yaakov Selkowitz 2016-03-14 16:55:26 -05:00
parent feec81e571
commit 84ba25226c
5 changed files with 74 additions and 55 deletions

View File

@ -40,9 +40,7 @@ typedef struct
long rem; /* remainder */
} ldiv_t;
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#if __ISO_C_VISIBLE >= 1999
typedef struct
{
long long int quot; /* quotient */
@ -68,7 +66,7 @@ _VOID _EXFUN(abort,(_VOID) _ATTRIBUTE ((__noreturn__)));
int _EXFUN(abs,(int));
int _EXFUN(atexit,(_VOID (*__func)(_VOID)));
double _EXFUN(atof,(const char *__nptr));
#ifndef __STRICT_ANSI__
#if __MISC_VISIBLE
float _EXFUN(atoff,(const char *__nptr));
#endif
int _EXFUN(atoi,(const char *__nptr));
@ -88,7 +86,7 @@ char * _EXFUN(getenv,(const char *__string));
char * _EXFUN(_getenv_r,(struct _reent *, const char *__string));
char * _EXFUN(_findenv,(_CONST char *, int *));
char * _EXFUN(_findenv_r,(struct _reent *, _CONST char *, int *));
#ifndef __STRICT_ANSI__
#if __POSIX_VISIBLE >= 200809
extern char *suboptarg; /* getsubopt(3) external variable */
int _EXFUN(getsubopt,(char **, char * const *, char **));
#endif
@ -105,41 +103,51 @@ size_t _EXFUN(mbstowcs,(wchar_t *__restrict, const char *__restrict, size_t));
size_t _EXFUN(_mbstowcs_r,(struct _reent *, wchar_t *__restrict, const char *__restrict, size_t, _mbstate_t *));
size_t _EXFUN(wcstombs,(char *__restrict, const wchar_t *__restrict, size_t));
size_t _EXFUN(_wcstombs_r,(struct _reent *, char *__restrict, const wchar_t *__restrict, size_t, _mbstate_t *));
#ifndef __STRICT_ANSI__
#ifndef _REENT_ONLY
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
char * _EXFUN(mkdtemp,(char *));
#endif
#if __GNU_VISIBLE
int _EXFUN(mkostemp,(char *, int));
int _EXFUN(mkostemps,(char *, int, int));
#endif
#if __MISC_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE >= 4
int _EXFUN(mkstemp,(char *));
#endif
#if __MISC_VISIBLE
int _EXFUN(mkstemps,(char *, int));
#endif
#if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112)
char * _EXFUN(mktemp,(char *) _ATTRIBUTE ((__deprecated__("the use of `mktemp' is dangerous; use `mkstemp' instead"))));
#endif
#endif /* !_REENT_ONLY */
char * _EXFUN(_mkdtemp_r, (struct _reent *, char *));
int _EXFUN(_mkostemp_r, (struct _reent *, char *, int));
int _EXFUN(_mkostemps_r, (struct _reent *, char *, int, int));
int _EXFUN(_mkstemp_r, (struct _reent *, char *));
int _EXFUN(_mkstemps_r, (struct _reent *, char *, int));
char * _EXFUN(_mktemp_r, (struct _reent *, char *) _ATTRIBUTE ((__deprecated__("the use of `mktemp' is dangerous; use `mkstemp' instead"))));
#endif
_VOID _EXFUN(qsort,(_PTR __base, size_t __nmemb, size_t __size, __compar_fn_t _compar));
int _EXFUN(rand,(_VOID));
_PTR _EXFUN_NOTHROW(realloc,(_PTR __r, size_t __size));
#ifndef __STRICT_ANSI__
#if __BSD_VISIBLE
_PTR _EXFUN(reallocf,(_PTR __r, size_t __size));
#endif
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4
char * _EXFUN(realpath, (const char *__restrict path, char *__restrict resolved_path));
#endif
#if __BSD_VISIBLE
int _EXFUN(rpmatch, (const char *response));
#endif
_VOID _EXFUN(srand,(unsigned __seed));
double _EXFUN(strtod,(const char *__restrict __n, char **__restrict __end_PTR));
double _EXFUN(_strtod_r,(struct _reent *,const char *__restrict __n, char **__restrict __end_PTR));
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#if __ISO_C_VISIBLE >= 1999
float _EXFUN(strtof,(const char *__restrict __n, char **__restrict __end_PTR));
#endif
#ifndef __STRICT_ANSI__
#if __MISC_VISIBLE
/* the following strtodf interface is deprecated...use strtof instead */
# ifndef strtodf
# ifndef strtodf
# define strtodf strtof
# endif
#endif
@ -150,24 +158,28 @@ unsigned long _EXFUN(_strtoul_r,(struct _reent *,const char *__restrict __n, cha
int _EXFUN(system,(const char *__string));
#ifndef __STRICT_ANSI__
#if __SVID_VISIBLE || __XSI_VISIBLE >= 4
long _EXFUN(a64l,(const char *__input));
char * _EXFUN(l64a,(long __input));
char * _EXFUN(_l64a_r,(struct _reent *,long __input));
#endif
#if __MISC_VISIBLE
int _EXFUN(on_exit,(_VOID (*__func)(int, _PTR),_PTR __arg));
#endif /* ! __STRICT_ANSI__ */
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#endif
#if __ISO_C_VISIBLE >= 1999
_VOID _EXFUN(_Exit,(int __status) _ATTRIBUTE ((__noreturn__)));
#endif
#ifndef __STRICT_ANSI__
#if __SVID_VISIBLE || __XSI_VISIBLE
int _EXFUN(putenv,(char *__string));
#endif
int _EXFUN(_putenv_r,(struct _reent *, char *__string));
_PTR _EXFUN(_reallocf_r,(struct _reent *, _PTR, size_t));
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
int _EXFUN(setenv,(const char *__string, const char *__value, int __overwrite));
#endif
int _EXFUN(_setenv_r,(struct _reent *, const char *__string, const char *__value, int __overwrite));
#if __XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112
char * _EXFUN(gcvt,(double,int,char *));
char * _EXFUN(gcvtf,(float,int,char *));
char * _EXFUN(fcvt,(double,int,int *,int *));
@ -176,15 +188,18 @@ char * _EXFUN(ecvt,(double,int,int *,int *));
char * _EXFUN(ecvtbuf,(double, int, int*, int*, char *));
char * _EXFUN(fcvtbuf,(double, int, int*, int*, char *));
char * _EXFUN(ecvtf,(float,int,int *,int *));
char * _EXFUN(dtoa,(double, int, int, int *, int*, char**));
#endif
char * _EXFUN(__itoa,(int, char *, int));
char * _EXFUN(__utoa,(unsigned, char *, int));
#ifndef __STRICT_ANSI__
#if __MISC_VISIBLE
char * _EXFUN(itoa,(int, char *, int));
char * _EXFUN(utoa,(unsigned, char *, int));
#endif
#if __POSIX_VISIBLE
int _EXFUN(rand_r,(unsigned *__seed));
#endif
#if __SVID_VISIBLE || __XSI_VISIBLE
double _EXFUN(drand48,(_VOID));
double _EXFUN(_drand48_r,(struct _reent *));
double _EXFUN(erand48,(unsigned short [3]));
@ -205,44 +220,37 @@ unsigned short *
_EXFUN(_seed48_r,(struct _reent *, unsigned short [3]));
_VOID _EXFUN(srand48,(long));
_VOID _EXFUN(_srand48_r,(struct _reent *, long));
#endif /* ! __STRICT_ANSI__ */
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#endif /* __SVID_VISIBLE || __XSI_VISIBLE */
#if __ISO_C_VISIBLE >= 1999
long long _EXFUN(atoll,(const char *__nptr));
#endif
#ifndef __STRICT_ANSI__
long long _EXFUN(_atoll_r,(struct _reent *, const char *__nptr));
#endif /* ! __STRICT_ANSI__ */
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#if __ISO_C_VISIBLE >= 1999
long long _EXFUN(llabs,(long long));
lldiv_t _EXFUN(lldiv,(long long __numer, long long __denom));
long long _EXFUN(strtoll,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
#endif
#ifndef __STRICT_ANSI__
long long _EXFUN(_strtoll_r,(struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base));
#endif /* ! __STRICT_ANSI__ */
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#if __ISO_C_VISIBLE >= 1999
unsigned long long _EXFUN(strtoull,(const char *__restrict __n, char **__restrict __end_PTR, int __base));
#endif
#ifndef __STRICT_ANSI__
unsigned long long _EXFUN(_strtoull_r,(struct _reent *, const char *__restrict __n, char **__restrict __end_PTR, int __base));
#ifndef __CYGWIN__
#if __MISC_VISIBLE
_VOID _EXFUN(cfree,(_PTR));
int _EXFUN(unsetenv,(const char *__string));
int _EXFUN(_unsetenv_r,(struct _reent *, const char *__string));
#endif
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
int _EXFUN(unsetenv,(const char *__string));
#endif
int _EXFUN(_unsetenv_r,(struct _reent *, const char *__string));
#endif /* !__CYGWIN__ */
#ifdef __rtems__
#if __POSIX_VISIBLE >= 200112
int _EXFUN(posix_memalign,(void **, size_t, size_t));
#endif
#endif /* ! __STRICT_ANSI__ */
#endif
char * _EXFUN(_dtoa_r,(struct _reent *, double, int, int, int *, int*, char**));
#ifndef __CYGWIN__
@ -260,7 +268,9 @@ _VOID _EXFUN(__eprintf,(const char *, const char *, unsigned int, const char *))
_BSD_SOURCE, you get the BSD version; otherwise you get the GNU
version. We want that #undef qsort_r will still let you
invoke the underlying function, but that requires gcc support. */
#ifdef _BSD_SOURCE
#if __GNU_VISIBLE
_VOID _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, int (*_compar)(const _PTR, const _PTR, _PTR), _PTR __thunk));
#elif __BSD_VISIBLE
# ifdef __GNUC__
_VOID _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, _PTR __thunk, int (*_compar)(_PTR, const _PTR, const _PTR)))
__asm__ (__ASMNAME ("__bsd_qsort_r"));
@ -268,16 +278,12 @@ _VOID _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, _PTR __thunk,
_VOID _EXFUN(__bsd_qsort_r,(_PTR __base, size_t __nmemb, size_t __size, _PTR __thunk, int (*_compar)(_PTR, const _PTR, const _PTR)));
# define qsort_r __bsd_qsort_r
# endif
#elif __GNU_VISIBLE
_VOID _EXFUN(qsort_r,(_PTR __base, size_t __nmemb, size_t __size, int (*_compar)(const _PTR, const _PTR, _PTR), _PTR __thunk));
#endif
/* On platforms where long double equals double. */
#ifdef _HAVE_LONG_DOUBLE
extern long double _strtold_r (struct _reent *, const char *__restrict, char **__restrict);
#if !defined(__STRICT_ANSI__) || \
(defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
(defined(__cplusplus) && __cplusplus >= 201103L)
#if __ISO_C_VISIBLE >= 1999
extern long double strtold (const char *__restrict, char **__restrict);
#endif
#endif /* _HAVE_LONG_DOUBLE */
@ -285,7 +291,7 @@ extern long double strtold (const char *__restrict, char **__restrict);
/*
* If we're in a mode greater than C99, expose C11 functions.
*/
#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
#if __ISO_C_VISIBLE >= 2011
void * aligned_alloc(size_t, size_t) __malloc_like __alloc_align(1)
__alloc_size(2);
int at_quick_exit(void (*)(void));

View File

@ -52,5 +52,6 @@ PORTABILITY
<<qsort_r>>, in various forms, appears in both BSD and glibc.
*/
#define _GNU_SOURCE
#define I_AM_GNU_QSORT_R
#include "qsort.c"

View File

@ -131,6 +131,8 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
*/
#define _XOPEN_SOURCE
#define _XOPEN_SOURCE_EXTENDED
#include <_ansi.h>
#include <reent.h>
#include <stdio.h>

View File

@ -28,26 +28,34 @@ __uint32_t arc4random_uniform(__uint32_t);
const char *getprogname (void);
void setprogname (const char *);
#ifndef __STRICT_ANSI__
#if __GNU_VISIBLE
char *canonicalize_file_name (const char *);
#endif
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
int unsetenv (const char *);
#endif /*__STRICT_ANSI__*/
#if !defined(__STRICT_ANSI__) || (__XSI_VISIBLE >= 500)
#endif
#if __BSD_VISIBLE || __SVID_SOURCE || __XSI_VISIBLE >= 4
char *initstate (unsigned seed, char *state, size_t size);
long random (void);
char *setstate (const char *state);
void srandom (unsigned);
#endif
#ifndef __STRICT_ANSI__
#if __XSI_VISIBLE
char *ptsname (int);
int ptsname_r(int, char *, size_t);
int getpt (void);
int grantpt (int);
int unlockpt (int);
#endif /*__STRICT_ANSI__*/
#endif
#if __GNU_VISIBLE
int ptsname_r(int, char *, size_t);
int getpt (void);
#endif
#if __XSI_VISIBLE >= 600
int posix_openpt (int);
#endif
#if __POSIX_VISIBLE >= 200112
int posix_memalign (void **, size_t, size_t);
#endif
#ifdef _COMPILING_NEWLIB
#define unsetenv UNUSED_unsetenv
@ -55,7 +63,9 @@ int posix_memalign (void **, size_t, size_t);
#endif
extern _PTR memalign _PARAMS ((size_t, size_t));
#if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112)
extern _PTR valloc _PARAMS ((size_t));
#endif
#undef _malloc_r
#define _malloc_r(r, s) malloc (s)

View File

@ -25,12 +25,12 @@
*
*/
#include <sys/cdefs.h>
#if 0
__FBSDID("$FreeBSD: src/lib/libc/stdlib/strfmon.c,v 1.19 2008/04/24 07:49:00 ru Exp $");
#endif
#include "winsup.h"
#include <sys/cdefs.h>
#include <sys/types.h>
#include <ctype.h>
#include <errno.h>