1 /* A GNU-like <stdlib.h>.
3 Copyright (C) 1995, 2001-2004, 2006-2008 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 @PRAGMA_SYSTEM_HEADER@
22 #if defined __need_malloc_and_calloc
23 /* Special invocation convention inside glibc header files. */
25 #@INCLUDE_NEXT@ @NEXT_STDLIB_H@
28 /* Normal invocation convention. */
32 /* The include_next requires a split double-inclusion guard. */
33 #@INCLUDE_NEXT@ @NEXT_STDLIB_H@
39 /* Solaris declares getloadavg() in <sys/loadavg.h>. */
40 #if @GNULIB_GETLOADAVG@ && @HAVE_SYS_LOADAVG_H@
41 # include <sys/loadavg.h>
44 #if @GNULIB_RANDOM_R@ || !@HAVE_STRUCT_RANDOM_DATA@
48 #if !@HAVE_STRUCT_RANDOM_DATA@
51 int32_t *fptr; /* Front pointer. */
52 int32_t *rptr; /* Rear pointer. */
53 int32_t *state; /* Array of state values. */
54 int rand_type; /* Type of random number generator. */
55 int rand_deg; /* Degree of random number generator. */
56 int rand_sep; /* Distance between front and rear. */
57 int32_t *end_ptr; /* Pointer behind state table. */
61 /* The definition of GL_LINK_WARNING is copied here. */
64 /* Some systems do not define EXIT_*, despite otherwise supporting C89. */
66 # define EXIT_SUCCESS 0
68 /* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
69 with proper operation of xargs. */
71 # define EXIT_FAILURE 1
72 #elif EXIT_FAILURE != 1
74 # define EXIT_FAILURE 1
83 #if @GNULIB_MALLOC_POSIX@
84 # if !@HAVE_MALLOC_POSIX@
86 # define malloc rpl_malloc
87 extern void * malloc (size_t size);
89 #elif defined GNULIB_POSIXCHECK
92 (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \
93 "use gnulib module malloc-posix for portability"), \
98 #if @GNULIB_REALLOC_POSIX@
99 # if !@HAVE_REALLOC_POSIX@
101 # define realloc rpl_realloc
102 extern void * realloc (void *ptr, size_t size);
104 #elif defined GNULIB_POSIXCHECK
106 # define realloc(p,s) \
107 (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \
108 "use gnulib module realloc-posix for portability"), \
113 #if @GNULIB_CALLOC_POSIX@
114 # if !@HAVE_CALLOC_POSIX@
116 # define calloc rpl_calloc
117 extern void * calloc (size_t nmemb, size_t size);
119 #elif defined GNULIB_POSIXCHECK
121 # define calloc(n,s) \
122 (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \
123 "use gnulib module calloc-posix for portability"), \
130 /* Parse a signed decimal integer.
131 Returns the value of the integer. Errors are not detected. */
132 extern long long atoll (const char *string);
134 #elif defined GNULIB_POSIXCHECK
137 (GL_LINK_WARNING ("atoll is unportable - " \
138 "use gnulib module atoll for portability"), \
143 #if @GNULIB_GETLOADAVG@
144 # if !@HAVE_DECL_GETLOADAVG@
145 /* Store max(NELEM,3) load average numbers in LOADAVG[].
146 The three numbers are the load average of the last 1 minute, the last 5
147 minutes, and the last 15 minutes, respectively.
148 LOADAVG is an array of NELEM numbers. */
149 extern int getloadavg (double loadavg[], int nelem);
151 #elif defined GNULIB_POSIXCHECK
153 # define getloadavg(l,n) \
154 (GL_LINK_WARNING ("getloadavg is not portable - " \
155 "use gnulib module getloadavg for portability"), \
160 #if @GNULIB_GETSUBOPT@
161 /* Assuming *OPTIONP is a comma separated list of elements of the form
162 "token" or "token=value", getsubopt parses the first of these elements.
163 If the first element refers to a "token" that is member of the given
164 NULL-terminated array of tokens:
165 - It replaces the comma with a NUL byte, updates *OPTIONP to point past
166 the first option and the comma, sets *VALUEP to the value of the
167 element (or NULL if it doesn't contain an "=" sign),
168 - It returns the index of the "token" in the given array of tokens.
169 Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
170 For more details see the POSIX:2001 specification.
171 http://www.opengroup.org/susv3xsh/getsubopt.html */
172 # if !@HAVE_GETSUBOPT@
173 extern int getsubopt (char **optionp, char *const *tokens, char **valuep);
175 #elif defined GNULIB_POSIXCHECK
177 # define getsubopt(o,t,v) \
178 (GL_LINK_WARNING ("getsubopt is unportable - " \
179 "use gnulib module getsubopt for portability"), \
186 /* Create a unique temporary directory from TEMPLATE.
187 The last six characters of TEMPLATE must be "XXXXXX";
188 they are replaced with a string that makes the directory name unique.
189 Returns TEMPLATE, or a null pointer if it cannot get a unique name.
190 The directory is created mode 700. */
191 extern char * mkdtemp (char * /*template*/);
193 #elif defined GNULIB_POSIXCHECK
195 # define mkdtemp(t) \
196 (GL_LINK_WARNING ("mkdtemp is unportable - " \
197 "use gnulib module mkdtemp for portability"), \
203 # if @REPLACE_MKSTEMP@
204 /* Create a unique temporary file from TEMPLATE.
205 The last six characters of TEMPLATE must be "XXXXXX";
206 they are replaced with a string that makes the file name unique.
207 The file is then created, ensuring it didn't exist before.
208 The file is created read-write (mask at least 0600 & ~umask), but it may be
209 world-readable and world-writable (mask 0666 & ~umask), depending on the
211 Returns the open file descriptor if successful, otherwise -1 and errno
213 # define mkstemp rpl_mkstemp
214 extern int mkstemp (char * /*template*/);
216 /* On MacOS X 10.3, only <unistd.h> declares mkstemp. */
219 #elif defined GNULIB_POSIXCHECK
221 # define mkstemp(t) \
222 (GL_LINK_WARNING ("mkstemp is unportable - " \
223 "use gnulib module mkstemp for portability"), \
229 # if @REPLACE_PUTENV@
231 # define putenv rpl_putenv
232 extern int putenv (char *string);
237 #if @GNULIB_RANDOM_R@
238 # if !@HAVE_RANDOM_R@
241 # define RAND_MAX 2147483647
244 int srandom_r (unsigned int seed, struct random_data *rand_state);
245 int initstate_r (unsigned int seed, char *buf, size_t buf_size,
246 struct random_data *rand_state);
247 int setstate_r (char *arg_state, struct random_data *rand_state);
248 int random_r (struct random_data *buf, int32_t *result);
250 #elif defined GNULIB_POSIXCHECK
252 # define random_r(b,r) \
253 (GL_LINK_WARNING ("random_r is unportable - " \
254 "use gnulib module random_r for portability"), \
257 # define initstate_r(s,b,sz,r) \
258 (GL_LINK_WARNING ("initstate_r is unportable - " \
259 "use gnulib module random_r for portability"), \
260 initstate_r (s,b,sz,r))
262 # define srandom_r(s,r) \
263 (GL_LINK_WARNING ("srandom_r is unportable - " \
264 "use gnulib module random_r for portability"), \
267 # define setstate_r(a,r) \
268 (GL_LINK_WARNING ("setstate_r is unportable - " \
269 "use gnulib module random_r for portability"), \
276 /* Test a user response to a question.
277 Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
278 extern int rpmatch (const char *response);
280 #elif defined GNULIB_POSIXCHECK
282 # define rpmatch(r) \
283 (GL_LINK_WARNING ("rpmatch is unportable - " \
284 "use gnulib module rpmatch for portability"), \
291 /* Set NAME to VALUE in the environment.
292 If REPLACE is nonzero, overwrite an existing value. */
293 extern int setenv (const char *name, const char *value, int replace);
298 #if @GNULIB_UNSETENV@
301 /* On some systems, unsetenv() returns void.
302 This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */
303 # define unsetenv(name) ((unsetenv)(name), 0)
306 /* Remove the variable NAME from the environment. */
307 extern int unsetenv (const char *name);
313 # if @REPLACE_STRTOD@
314 # define strtod rpl_strtod
316 # if !@HAVE_STRTOD@ || @REPLACE_STRTOD@
317 /* Parse a double from STRING, updating ENDP if appropriate. */
318 extern double strtod (const char *str, char **endp);
320 #elif defined GNULIB_POSIXCHECK
322 # define strtod(s, e) \
323 (GL_LINK_WARNING ("strtod is unportable - " \
324 "use gnulib module strtod for portability"), \
331 /* Parse a signed integer whose textual representation starts at STRING.
332 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
333 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
335 If ENDPTR is not NULL, the address of the first byte after the integer is
337 Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
339 extern long long strtoll (const char *string, char **endptr, int base);
341 #elif defined GNULIB_POSIXCHECK
343 # define strtoll(s,e,b) \
344 (GL_LINK_WARNING ("strtoll is unportable - " \
345 "use gnulib module strtoll for portability"), \
350 #if @GNULIB_STRTOULL@
351 # if !@HAVE_STRTOULL@
352 /* Parse an unsigned integer whose textual representation starts at STRING.
353 The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
354 it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
356 If ENDPTR is not NULL, the address of the first byte after the integer is
358 Upon overflow, the return value is ULLONG_MAX, and errno is set to
360 extern unsigned long long strtoull (const char *string, char **endptr, int base);
362 #elif defined GNULIB_POSIXCHECK
364 # define strtoull(s,e,b) \
365 (GL_LINK_WARNING ("strtoull is unportable - " \
366 "use gnulib module strtoull for portability"), \
375 #endif /* _GL_STDLIB_H */
376 #endif /* _GL_STDLIB_H */