2011-02-12 05:22:29 +00:00
|
|
|
#ifndef _STDLIB_H
|
|
|
|
#define _STDLIB_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-09-08 03:13:55 +00:00
|
|
|
#include <features.h>
|
2012-09-07 03:12:27 +00:00
|
|
|
|
2013-11-25 02:42:55 +00:00
|
|
|
#ifdef __cplusplus
|
use a common definition of NULL as 0L for C and C++
the historical mess of having different definitions for C and C++
comes from the historical C definition as (void *)0 and the fact that
(void *)0 can't be used in C++ because it does not convert to other
pointer types implicitly. however, using plain 0 in C++ exposed bugs
in C++ programs that call variadic functions with NULL as an argument
and (wrongly; this is UB) expect it to arrive as a null pointer. on
64-bit machines, the high bits end up containing junk. glibc dodges
the issue by using a GCC extension __null to define NULL; this is
observably non-conforming because a conforming application could
observe the definition of NULL via stringizing and see that it is
neither an integer constant expression with value zero nor such an
expression cast to void.
switching to 0L eliminates the issue and provides compatibility with
broken applications, since on all musl targets, long and pointers have
the same size, representation, and argument-passing convention. we
could maintain separate C and C++ definitions of NULL (i.e. just use
0L on C++ and use (void *)0 on C) but after careful analysis, it seems
extremely difficult for a C program to even determine whether NULL has
integer or pointer type, much less depend in subtle, unintentional
ways, on whether it does. C89 seems to have no way to make the
distinction. on C99, the fact that (int)(void *)0 is not an integer
constant expression, along with subtle VLA/sizeof semantics, can be
used to make the distinction, but many compilers are non-conforming
and give the wrong result to this test anyway. on C11, _Generic can
trivially make the distinction, but it seems unlikely that code
targetting C11 would be so backwards in caring which definition of
NULL an implementation uses.
as such, the simplest path of using the same definition for NULL in
both C and C++ was chosen. the #undef directive was also removed so
that the compiler can catch and give a warning or error on
redefinition if buggy programs have defined their own versions of
NULL prior to inclusion of standard headers.
2013-01-19 01:35:26 +00:00
|
|
|
#define NULL 0L
|
2013-11-25 02:42:55 +00:00
|
|
|
#else
|
|
|
|
#define NULL ((void*)0)
|
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
#define __NEED_size_t
|
|
|
|
#define __NEED_wchar_t
|
|
|
|
|
|
|
|
#include <bits/alltypes.h>
|
|
|
|
|
|
|
|
int atoi (const char *);
|
|
|
|
long atol (const char *);
|
|
|
|
long long atoll (const char *);
|
|
|
|
double atof (const char *);
|
|
|
|
|
2012-09-07 02:44:55 +00:00
|
|
|
float strtof (const char *__restrict, char **__restrict);
|
|
|
|
double strtod (const char *__restrict, char **__restrict);
|
|
|
|
long double strtold (const char *__restrict, char **__restrict);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2012-09-07 02:44:55 +00:00
|
|
|
long strtol (const char *__restrict, char **__restrict, int);
|
|
|
|
unsigned long strtoul (const char *__restrict, char **__restrict, int);
|
|
|
|
long long strtoll (const char *__restrict, char **__restrict, int);
|
|
|
|
unsigned long long strtoull (const char *__restrict, char **__restrict, int);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
int rand (void);
|
|
|
|
void srand (unsigned);
|
|
|
|
|
|
|
|
void *malloc (size_t);
|
|
|
|
void *calloc (size_t, size_t);
|
|
|
|
void *realloc (void *, size_t);
|
|
|
|
void free (void *);
|
2012-08-26 03:15:13 +00:00
|
|
|
void *aligned_alloc(size_t alignment, size_t size);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2012-09-07 03:12:27 +00:00
|
|
|
_Noreturn void abort (void);
|
2011-02-12 05:22:29 +00:00
|
|
|
int atexit (void (*) (void));
|
2012-09-07 03:12:27 +00:00
|
|
|
_Noreturn void exit (int);
|
|
|
|
_Noreturn void _Exit (int);
|
2012-08-26 02:49:47 +00:00
|
|
|
int at_quick_exit (void (*) (void));
|
2012-09-07 03:12:27 +00:00
|
|
|
_Noreturn void quick_exit (int);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
char *getenv (const char *);
|
|
|
|
|
|
|
|
int system (const char *);
|
|
|
|
|
|
|
|
void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
|
|
|
|
void qsort (void *, size_t, size_t, int (*)(const void *, const void *));
|
|
|
|
|
|
|
|
int abs (int);
|
|
|
|
long labs (long);
|
|
|
|
long long llabs (long long);
|
|
|
|
|
|
|
|
typedef struct { int quot, rem; } div_t;
|
|
|
|
typedef struct { long quot, rem; } ldiv_t;
|
|
|
|
typedef struct { long long quot, rem; } lldiv_t;
|
|
|
|
|
2011-02-14 10:10:10 +00:00
|
|
|
div_t div (int, int);
|
|
|
|
ldiv_t ldiv (long, long);
|
|
|
|
lldiv_t lldiv (long long, long long);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
int mblen (const char *, size_t);
|
2012-09-07 02:44:55 +00:00
|
|
|
int mbtowc (wchar_t *__restrict, const char *__restrict, size_t);
|
2011-02-12 05:22:29 +00:00
|
|
|
int wctomb (char *, wchar_t);
|
2012-09-07 02:44:55 +00:00
|
|
|
size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t);
|
|
|
|
size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2011-02-15 22:33:52 +00:00
|
|
|
#define EXIT_FAILURE 1
|
|
|
|
#define EXIT_SUCCESS 0
|
|
|
|
|
2011-02-16 00:15:45 +00:00
|
|
|
#define MB_CUR_MAX ((size_t)+4)
|
2011-02-14 10:10:10 +00:00
|
|
|
|
|
|
|
#define RAND_MAX (0x7fffffff)
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|
2012-05-23 01:52:08 +00:00
|
|
|
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|
|
|
|
|| defined(_BSD_SOURCE)
|
2011-02-14 10:10:10 +00:00
|
|
|
|
2012-10-21 23:15:11 +00:00
|
|
|
#define WNOHANG 1
|
|
|
|
#define WUNTRACED 2
|
|
|
|
|
2011-04-21 18:27:28 +00:00
|
|
|
#define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
|
|
|
|
#define WTERMSIG(s) ((s) & 0x7f)
|
|
|
|
#define WSTOPSIG(s) WEXITSTATUS(s)
|
|
|
|
#define WIFEXITED(s) (!WTERMSIG(s))
|
fix definitions of WIFSTOPPED and WIFSIGNALED to support up to signal 127
mips has signal numbers up to 127 (formerly, up to 128, but the last
one never worked right and caused kernel panic when used), so 127 in
the "signal number" field of the wait status is insufficient for
determining that the process was stopped. in addition, a nonzero value
in the upper bits must be present, indicating the signal number which
caused the process to be stopped.
details on this issue can be seen in the email with message id
CAAG0J9-d4BfEhbQovFqUAJ3QoOuXScrpsY1y95PrEPxA5DWedQ@mail.gmail.com on
the linux-mips mailing list, archived at:
http://www.linux-mips.org/archives/linux-mips/2013-06/msg00552.html
and in the associated thread about fixing the mips kernel bug.
commit 4a96b948687166da26a6c327e6c6733ad2336c5c fixed the
corresponding issue in uClibc, but introduced a multiple-evaluation
issue for the WIFSTOPPED macro.
for the most part, none of these issues affected pure musl systems,
since musl has up until now (incorrectly) defined SIGRTMAX as 64 on
all archs, even mips. however, interpreting status of non-musl
programs on mips may have caused problems. with this change, the full
range of signal numbers can be made available on mips.
2013-08-11 03:33:54 +00:00
|
|
|
#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00)
|
2014-02-11 09:51:16 +00:00
|
|
|
#define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu)
|
2011-02-14 10:10:10 +00:00
|
|
|
|
|
|
|
int posix_memalign (void **, size_t, size_t);
|
|
|
|
int setenv (const char *, const char *, int);
|
|
|
|
int unsetenv (const char *);
|
|
|
|
int mkstemp (char *);
|
2013-02-21 03:43:23 +00:00
|
|
|
int mkostemp (char *, int);
|
2011-02-14 10:10:10 +00:00
|
|
|
char *mkdtemp (char *);
|
2011-02-12 05:22:29 +00:00
|
|
|
int getsubopt (char **, char *const *, char **);
|
2011-02-14 10:10:10 +00:00
|
|
|
int rand_r (unsigned *);
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2011-02-14 10:10:10 +00:00
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2011-02-14 10:10:10 +00:00
|
|
|
|
2012-05-23 01:52:08 +00:00
|
|
|
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|
|
|
|
|| defined(_BSD_SOURCE)
|
2012-09-07 02:44:55 +00:00
|
|
|
char *realpath (const char *__restrict, char *__restrict);
|
2012-05-23 01:52:08 +00:00
|
|
|
long int random (void);
|
|
|
|
void srandom (unsigned int);
|
|
|
|
char *initstate (unsigned int, char *, size_t);
|
|
|
|
char *setstate (char *);
|
2011-02-14 10:10:10 +00:00
|
|
|
int putenv (char *);
|
2011-02-12 05:22:29 +00:00
|
|
|
int posix_openpt (int);
|
|
|
|
int grantpt (int);
|
|
|
|
int unlockpt (int);
|
|
|
|
char *ptsname (int);
|
2011-02-14 10:10:10 +00:00
|
|
|
char *l64a (long);
|
|
|
|
long a64l (const char *);
|
|
|
|
void setkey (const char *);
|
|
|
|
double drand48 (void);
|
|
|
|
double erand48 (unsigned short [3]);
|
|
|
|
long int lrand48 (void);
|
|
|
|
long int nrand48 (unsigned short [3]);
|
|
|
|
long mrand48 (void);
|
|
|
|
long jrand48 (unsigned short [3]);
|
|
|
|
void srand48 (long);
|
|
|
|
unsigned short *seed48 (unsigned short [3]);
|
|
|
|
void lcong48 (unsigned short [7]);
|
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2012-05-23 01:52:08 +00:00
|
|
|
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
2012-04-09 20:22:05 +00:00
|
|
|
#include <alloca.h>
|
2011-02-14 10:10:10 +00:00
|
|
|
char *mktemp (char *);
|
2013-02-21 03:43:23 +00:00
|
|
|
int mkstemps (char *, int);
|
|
|
|
int mkostemps (char *, int, int);
|
2011-02-14 10:10:10 +00:00
|
|
|
void *valloc (size_t);
|
|
|
|
void *memalign(size_t, size_t);
|
2013-11-21 01:59:43 +00:00
|
|
|
int getloadavg(double *, int);
|
2014-08-07 15:49:24 +00:00
|
|
|
int clearenv(void);
|
2012-10-21 23:15:11 +00:00
|
|
|
#define WCOREDUMP(s) ((s) & 0x80)
|
|
|
|
#define WIFCONTINUED(s) ((s) == 0xffff)
|
2012-05-23 01:52:08 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _GNU_SOURCE
|
2011-04-13 12:35:32 +00:00
|
|
|
int ptsname_r(int, char *, size_t);
|
2012-02-06 06:14:23 +00:00
|
|
|
char *ecvt(double, int, int *, int *);
|
|
|
|
char *fcvt(double, int, int *, int *);
|
|
|
|
char *gcvt(double, int, char *);
|
2013-08-13 22:18:44 +00:00
|
|
|
struct __locale_struct;
|
|
|
|
float strtof_l(const char *__restrict, char **__restrict, struct __locale_struct *);
|
|
|
|
double strtod_l(const char *__restrict, char **__restrict, struct __locale_struct *);
|
|
|
|
long double strtold_l(const char *__restrict, char **__restrict, struct __locale_struct *);
|
2011-02-14 10:10:10 +00:00
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
2012-06-04 12:03:56 +00:00
|
|
|
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
|
2012-05-04 04:13:23 +00:00
|
|
|
#define mkstemp64 mkstemp
|
2013-02-21 03:43:23 +00:00
|
|
|
#define mkostemp64 mkostemp
|
|
|
|
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
|
|
|
#define mkstemps64 mkstemps
|
|
|
|
#define mkostemps64 mkostemps
|
|
|
|
#endif
|
2012-05-04 04:13:23 +00:00
|
|
|
#endif
|
2011-02-12 05:22:29 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|