Commit | Line | Data |
---|---|---|
f240aacb LC |
1 | /* A GNU-like <stdlib.h>. |
2 | ||
49114fd4 | 3 | Copyright (C) 1995, 2001-2004, 2006-2011 Free Software Foundation, Inc. |
f240aacb LC |
4 | |
5 | This program is free software: you can redistribute it and/or modify | |
6 | it under the terms of the GNU Lesser 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. | |
9 | ||
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 Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public License | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | #if __GNUC__ >= 3 | |
19 | @PRAGMA_SYSTEM_HEADER@ | |
20 | #endif | |
0f00f2c3 | 21 | @PRAGMA_COLUMNS@ |
f240aacb LC |
22 | |
23 | #if defined __need_malloc_and_calloc | |
24 | /* Special invocation convention inside glibc header files. */ | |
25 | ||
26 | #@INCLUDE_NEXT@ @NEXT_STDLIB_H@ | |
27 | ||
28 | #else | |
29 | /* Normal invocation convention. */ | |
30 | ||
31 | #ifndef _GL_STDLIB_H | |
32 | ||
33 | /* The include_next requires a split double-inclusion guard. */ | |
34 | #@INCLUDE_NEXT@ @NEXT_STDLIB_H@ | |
35 | ||
36 | #ifndef _GL_STDLIB_H | |
37 | #define _GL_STDLIB_H | |
38 | ||
8912421c LC |
39 | /* NetBSD 5.0 mis-defines NULL. */ |
40 | #include <stddef.h> | |
f240aacb | 41 | |
0f00f2c3 LC |
42 | /* MirBSD 10 defines WEXITSTATUS in <sys/wait.h>, not in <stdlib.h>. */ |
43 | #if @GNULIB_SYSTEM_POSIX@ && !defined WEXITSTATUS | |
44 | # include <sys/wait.h> | |
45 | #endif | |
46 | ||
f240aacb | 47 | /* Solaris declares getloadavg() in <sys/loadavg.h>. */ |
61cd9dc9 | 48 | #if (@GNULIB_GETLOADAVG@ || defined GNULIB_POSIXCHECK) && @HAVE_SYS_LOADAVG_H@ |
f240aacb LC |
49 | # include <sys/loadavg.h> |
50 | #endif | |
51 | ||
49114fd4 LC |
52 | #if @GNULIB_RANDOM_R@ |
53 | ||
f240aacb | 54 | /* OSF/1 5.1 declares 'struct random_data' in <random.h>, which is included |
49114fd4 LC |
55 | from <stdlib.h> if _REENTRANT is defined. Include it whenever we need |
56 | 'struct random_data'. */ | |
57 | # if @HAVE_RANDOM_H@ | |
58 | # include <random.h> | |
59 | # endif | |
f240aacb | 60 | |
49114fd4 LC |
61 | # if !@HAVE_STRUCT_RANDOM_DATA@ || !@HAVE_RANDOM_R@ |
62 | # include <stdint.h> | |
63 | # endif | |
f240aacb | 64 | |
49114fd4 | 65 | # if !@HAVE_STRUCT_RANDOM_DATA@ |
0f00f2c3 LC |
66 | /* Define 'struct random_data'. |
67 | But allow multiple gnulib generated <stdlib.h> replacements to coexist. */ | |
49114fd4 | 68 | # if !GNULIB_defined_struct_random_data |
f240aacb LC |
69 | struct random_data |
70 | { | |
1cd4fffc LC |
71 | int32_t *fptr; /* Front pointer. */ |
72 | int32_t *rptr; /* Rear pointer. */ | |
73 | int32_t *state; /* Array of state values. */ | |
74 | int rand_type; /* Type of random number generator. */ | |
75 | int rand_deg; /* Degree of random number generator. */ | |
76 | int rand_sep; /* Distance between front and rear. */ | |
77 | int32_t *end_ptr; /* Pointer behind state table. */ | |
f240aacb | 78 | }; |
49114fd4 LC |
79 | # define GNULIB_defined_struct_random_data 1 |
80 | # endif | |
0f00f2c3 | 81 | # endif |
f240aacb LC |
82 | #endif |
83 | ||
a927b6c1 | 84 | #if (@GNULIB_MKSTEMP@ || @GNULIB_GETSUBOPT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__ && !((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) |
61cd9dc9 LC |
85 | /* On MacOS X 10.3, only <unistd.h> declares mkstemp. */ |
86 | /* On Cygwin 1.7.1, only <unistd.h> declares getsubopt. */ | |
a927b6c1 | 87 | /* But avoid namespace pollution on glibc systems and native Windows. */ |
61cd9dc9 LC |
88 | # include <unistd.h> |
89 | #endif | |
f240aacb | 90 | |
49114fd4 LC |
91 | #if 3 <= __GNUC__ || __GNUC__ == 2 && 8 <= __GNUC_MINOR__ |
92 | # define _GL_ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | |
93 | #else | |
94 | # define _GL_ATTRIBUTE_NORETURN | |
9157d901 LC |
95 | #endif |
96 | ||
f4c79b3c LC |
97 | /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ |
98 | ||
1cd4fffc LC |
99 | /* The definition of _GL_ARG_NONNULL is copied here. */ |
100 | ||
61cd9dc9 LC |
101 | /* The definition of _GL_WARN_ON_USE is copied here. */ |
102 | ||
f240aacb LC |
103 | |
104 | /* Some systems do not define EXIT_*, despite otherwise supporting C89. */ | |
105 | #ifndef EXIT_SUCCESS | |
106 | # define EXIT_SUCCESS 0 | |
107 | #endif | |
108 | /* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere | |
109 | with proper operation of xargs. */ | |
110 | #ifndef EXIT_FAILURE | |
111 | # define EXIT_FAILURE 1 | |
112 | #elif EXIT_FAILURE != 1 | |
113 | # undef EXIT_FAILURE | |
114 | # define EXIT_FAILURE 1 | |
115 | #endif | |
116 | ||
117 | ||
9157d901 LC |
118 | #if @GNULIB__EXIT@ |
119 | /* Terminate the current process with the given return code, without running | |
120 | the 'atexit' handlers. */ | |
121 | # if !@HAVE__EXIT@ | |
49114fd4 | 122 | _GL_FUNCDECL_SYS (_Exit, void, (int status) _GL_ATTRIBUTE_NORETURN); |
9157d901 LC |
123 | # endif |
124 | _GL_CXXALIAS_SYS (_Exit, void, (int status)); | |
125 | _GL_CXXALIASWARN (_Exit); | |
126 | #elif defined GNULIB_POSIXCHECK | |
127 | # undef _Exit | |
128 | # if HAVE_RAW_DECL__EXIT | |
129 | _GL_WARN_ON_USE (_Exit, "_Exit is unportable - " | |
130 | "use gnulib module _Exit for portability"); | |
131 | # endif | |
132 | #endif | |
133 | ||
134 | ||
8912421c | 135 | #if @GNULIB_ATOLL@ |
8912421c LC |
136 | /* Parse a signed decimal integer. |
137 | Returns the value of the integer. Errors are not detected. */ | |
f4c79b3c LC |
138 | # if !@HAVE_ATOLL@ |
139 | _GL_FUNCDECL_SYS (atoll, long long, (const char *string) _GL_ARG_NONNULL ((1))); | |
f240aacb | 140 | # endif |
f4c79b3c LC |
141 | _GL_CXXALIAS_SYS (atoll, long long, (const char *string)); |
142 | _GL_CXXALIASWARN (atoll); | |
f240aacb | 143 | #elif defined GNULIB_POSIXCHECK |
8912421c | 144 | # undef atoll |
61cd9dc9 LC |
145 | # if HAVE_RAW_DECL_ATOLL |
146 | _GL_WARN_ON_USE (atoll, "atoll is unportable - " | |
147 | "use gnulib module atoll for portability"); | |
148 | # endif | |
f240aacb LC |
149 | #endif |
150 | ||
f240aacb | 151 | #if @GNULIB_CALLOC_POSIX@ |
9157d901 | 152 | # if @REPLACE_CALLOC@ |
f4c79b3c LC |
153 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
154 | # undef calloc | |
155 | # define calloc rpl_calloc | |
156 | # endif | |
157 | _GL_FUNCDECL_RPL (calloc, void *, (size_t nmemb, size_t size)); | |
158 | _GL_CXXALIAS_RPL (calloc, void *, (size_t nmemb, size_t size)); | |
159 | # else | |
160 | _GL_CXXALIAS_SYS (calloc, void *, (size_t nmemb, size_t size)); | |
f240aacb | 161 | # endif |
f4c79b3c | 162 | _GL_CXXALIASWARN (calloc); |
f240aacb LC |
163 | #elif defined GNULIB_POSIXCHECK |
164 | # undef calloc | |
61cd9dc9 LC |
165 | /* Assume calloc is always declared. */ |
166 | _GL_WARN_ON_USE (calloc, "calloc is not POSIX compliant everywhere - " | |
167 | "use gnulib module calloc-posix for portability"); | |
f240aacb LC |
168 | #endif |
169 | ||
8912421c LC |
170 | #if @GNULIB_CANONICALIZE_FILE_NAME@ |
171 | # if @REPLACE_CANONICALIZE_FILE_NAME@ | |
f4c79b3c LC |
172 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
173 | # define canonicalize_file_name rpl_canonicalize_file_name | |
174 | # endif | |
175 | _GL_FUNCDECL_RPL (canonicalize_file_name, char *, (const char *name) | |
176 | _GL_ARG_NONNULL ((1))); | |
177 | _GL_CXXALIAS_RPL (canonicalize_file_name, char *, (const char *name)); | |
178 | # else | |
179 | # if !@HAVE_CANONICALIZE_FILE_NAME@ | |
180 | _GL_FUNCDECL_SYS (canonicalize_file_name, char *, (const char *name) | |
181 | _GL_ARG_NONNULL ((1))); | |
182 | # endif | |
183 | _GL_CXXALIAS_SYS (canonicalize_file_name, char *, (const char *name)); | |
f240aacb | 184 | # endif |
f4c79b3c | 185 | _GL_CXXALIASWARN (canonicalize_file_name); |
f240aacb | 186 | #elif defined GNULIB_POSIXCHECK |
8912421c | 187 | # undef canonicalize_file_name |
61cd9dc9 | 188 | # if HAVE_RAW_DECL_CANONICALIZE_FILE_NAME |
0f00f2c3 LC |
189 | _GL_WARN_ON_USE (canonicalize_file_name, |
190 | "canonicalize_file_name is unportable - " | |
61cd9dc9 LC |
191 | "use gnulib module canonicalize-lgpl for portability"); |
192 | # endif | |
f240aacb LC |
193 | #endif |
194 | ||
f240aacb | 195 | #if @GNULIB_GETLOADAVG@ |
f240aacb LC |
196 | /* Store max(NELEM,3) load average numbers in LOADAVG[]. |
197 | The three numbers are the load average of the last 1 minute, the last 5 | |
198 | minutes, and the last 15 minutes, respectively. | |
199 | LOADAVG is an array of NELEM numbers. */ | |
f4c79b3c LC |
200 | # if !@HAVE_DECL_GETLOADAVG@ |
201 | _GL_FUNCDECL_SYS (getloadavg, int, (double loadavg[], int nelem) | |
202 | _GL_ARG_NONNULL ((1))); | |
f240aacb | 203 | # endif |
f4c79b3c LC |
204 | _GL_CXXALIAS_SYS (getloadavg, int, (double loadavg[], int nelem)); |
205 | _GL_CXXALIASWARN (getloadavg); | |
f240aacb LC |
206 | #elif defined GNULIB_POSIXCHECK |
207 | # undef getloadavg | |
61cd9dc9 LC |
208 | # if HAVE_RAW_DECL_GETLOADAVG |
209 | _GL_WARN_ON_USE (getloadavg, "getloadavg is not portable - " | |
210 | "use gnulib module getloadavg for portability"); | |
211 | # endif | |
f240aacb LC |
212 | #endif |
213 | ||
f240aacb LC |
214 | #if @GNULIB_GETSUBOPT@ |
215 | /* Assuming *OPTIONP is a comma separated list of elements of the form | |
216 | "token" or "token=value", getsubopt parses the first of these elements. | |
217 | If the first element refers to a "token" that is member of the given | |
218 | NULL-terminated array of tokens: | |
219 | - It replaces the comma with a NUL byte, updates *OPTIONP to point past | |
220 | the first option and the comma, sets *VALUEP to the value of the | |
221 | element (or NULL if it doesn't contain an "=" sign), | |
222 | - It returns the index of the "token" in the given array of tokens. | |
223 | Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined. | |
224 | For more details see the POSIX:2001 specification. | |
225 | http://www.opengroup.org/susv3xsh/getsubopt.html */ | |
226 | # if !@HAVE_GETSUBOPT@ | |
f4c79b3c LC |
227 | _GL_FUNCDECL_SYS (getsubopt, int, |
228 | (char **optionp, char *const *tokens, char **valuep) | |
229 | _GL_ARG_NONNULL ((1, 2, 3))); | |
f240aacb | 230 | # endif |
f4c79b3c LC |
231 | _GL_CXXALIAS_SYS (getsubopt, int, |
232 | (char **optionp, char *const *tokens, char **valuep)); | |
233 | _GL_CXXALIASWARN (getsubopt); | |
f240aacb LC |
234 | #elif defined GNULIB_POSIXCHECK |
235 | # undef getsubopt | |
61cd9dc9 LC |
236 | # if HAVE_RAW_DECL_GETSUBOPT |
237 | _GL_WARN_ON_USE (getsubopt, "getsubopt is unportable - " | |
238 | "use gnulib module getsubopt for portability"); | |
239 | # endif | |
f240aacb LC |
240 | #endif |
241 | ||
a927b6c1 LC |
242 | #if @GNULIB_GRANTPT@ |
243 | /* Change the ownership and access permission of the slave side of the | |
244 | pseudo-terminal whose master side is specified by FD. */ | |
245 | # if !@HAVE_GRANTPT@ | |
246 | _GL_FUNCDECL_SYS (grantpt, int, (int fd)); | |
247 | # endif | |
248 | _GL_CXXALIAS_SYS (grantpt, int, (int fd)); | |
249 | _GL_CXXALIASWARN (grantpt); | |
250 | #elif defined GNULIB_POSIXCHECK | |
251 | # undef grantpt | |
252 | # if HAVE_RAW_DECL_GRANTPT | |
253 | _GL_WARN_ON_USE (ptsname, "grantpt is not portable - " | |
254 | "use gnulib module grantpt for portability"); | |
255 | # endif | |
256 | #endif | |
257 | ||
8912421c | 258 | #if @GNULIB_MALLOC_POSIX@ |
9157d901 | 259 | # if @REPLACE_MALLOC@ |
f4c79b3c LC |
260 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
261 | # undef malloc | |
262 | # define malloc rpl_malloc | |
263 | # endif | |
264 | _GL_FUNCDECL_RPL (malloc, void *, (size_t size)); | |
265 | _GL_CXXALIAS_RPL (malloc, void *, (size_t size)); | |
266 | # else | |
267 | _GL_CXXALIAS_SYS (malloc, void *, (size_t size)); | |
8912421c | 268 | # endif |
f4c79b3c | 269 | _GL_CXXALIASWARN (malloc); |
8912421c LC |
270 | #elif defined GNULIB_POSIXCHECK |
271 | # undef malloc | |
61cd9dc9 LC |
272 | /* Assume malloc is always declared. */ |
273 | _GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - " | |
274 | "use gnulib module malloc-posix for portability"); | |
8912421c | 275 | #endif |
f240aacb | 276 | |
dd36ce77 MW |
277 | /* Convert a multibyte character to a wide character. */ |
278 | #if @GNULIB_MBTOWC@ | |
279 | # if @REPLACE_MBTOWC@ | |
280 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
281 | # undef mbtowc | |
282 | # define mbtowc rpl_mbtowc | |
283 | # endif | |
284 | _GL_FUNCDECL_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n)); | |
285 | _GL_CXXALIAS_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n)); | |
286 | # else | |
287 | _GL_CXXALIAS_SYS (mbtowc, int, (wchar_t *pwc, const char *s, size_t n)); | |
288 | # endif | |
289 | _GL_CXXALIASWARN (mbtowc); | |
290 | #endif | |
291 | ||
f240aacb | 292 | #if @GNULIB_MKDTEMP@ |
f240aacb LC |
293 | /* Create a unique temporary directory from TEMPLATE. |
294 | The last six characters of TEMPLATE must be "XXXXXX"; | |
295 | they are replaced with a string that makes the directory name unique. | |
296 | Returns TEMPLATE, or a null pointer if it cannot get a unique name. | |
297 | The directory is created mode 700. */ | |
f4c79b3c LC |
298 | # if !@HAVE_MKDTEMP@ |
299 | _GL_FUNCDECL_SYS (mkdtemp, char *, (char * /*template*/) _GL_ARG_NONNULL ((1))); | |
f240aacb | 300 | # endif |
f4c79b3c LC |
301 | _GL_CXXALIAS_SYS (mkdtemp, char *, (char * /*template*/)); |
302 | _GL_CXXALIASWARN (mkdtemp); | |
f240aacb LC |
303 | #elif defined GNULIB_POSIXCHECK |
304 | # undef mkdtemp | |
61cd9dc9 LC |
305 | # if HAVE_RAW_DECL_MKDTEMP |
306 | _GL_WARN_ON_USE (mkdtemp, "mkdtemp is unportable - " | |
307 | "use gnulib module mkdtemp for portability"); | |
308 | # endif | |
f240aacb LC |
309 | #endif |
310 | ||
8912421c | 311 | #if @GNULIB_MKOSTEMP@ |
8912421c LC |
312 | /* Create a unique temporary file from TEMPLATE. |
313 | The last six characters of TEMPLATE must be "XXXXXX"; | |
314 | they are replaced with a string that makes the file name unique. | |
315 | The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>) | |
316 | and O_TEXT, O_BINARY (defined in "binary-io.h"). | |
317 | The file is then created, with the specified flags, ensuring it didn't exist | |
318 | before. | |
319 | The file is created read-write (mask at least 0600 & ~umask), but it may be | |
320 | world-readable and world-writable (mask 0666 & ~umask), depending on the | |
321 | implementation. | |
322 | Returns the open file descriptor if successful, otherwise -1 and errno | |
323 | set. */ | |
f4c79b3c LC |
324 | # if !@HAVE_MKOSTEMP@ |
325 | _GL_FUNCDECL_SYS (mkostemp, int, (char * /*template*/, int /*flags*/) | |
326 | _GL_ARG_NONNULL ((1))); | |
8912421c | 327 | # endif |
f4c79b3c LC |
328 | _GL_CXXALIAS_SYS (mkostemp, int, (char * /*template*/, int /*flags*/)); |
329 | _GL_CXXALIASWARN (mkostemp); | |
8912421c LC |
330 | #elif defined GNULIB_POSIXCHECK |
331 | # undef mkostemp | |
61cd9dc9 LC |
332 | # if HAVE_RAW_DECL_MKOSTEMP |
333 | _GL_WARN_ON_USE (mkostemp, "mkostemp is unportable - " | |
334 | "use gnulib module mkostemp for portability"); | |
335 | # endif | |
8912421c | 336 | #endif |
f240aacb | 337 | |
f29ded4b | 338 | #if @GNULIB_MKOSTEMPS@ |
f29ded4b LC |
339 | /* Create a unique temporary file from TEMPLATE. |
340 | The last six characters of TEMPLATE before a suffix of length | |
341 | SUFFIXLEN must be "XXXXXX"; | |
342 | they are replaced with a string that makes the file name unique. | |
343 | The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>) | |
344 | and O_TEXT, O_BINARY (defined in "binary-io.h"). | |
345 | The file is then created, with the specified flags, ensuring it didn't exist | |
346 | before. | |
347 | The file is created read-write (mask at least 0600 & ~umask), but it may be | |
348 | world-readable and world-writable (mask 0666 & ~umask), depending on the | |
349 | implementation. | |
350 | Returns the open file descriptor if successful, otherwise -1 and errno | |
351 | set. */ | |
f4c79b3c LC |
352 | # if !@HAVE_MKOSTEMPS@ |
353 | _GL_FUNCDECL_SYS (mkostemps, int, | |
354 | (char * /*template*/, int /*suffixlen*/, int /*flags*/) | |
355 | _GL_ARG_NONNULL ((1))); | |
f29ded4b | 356 | # endif |
f4c79b3c LC |
357 | _GL_CXXALIAS_SYS (mkostemps, int, |
358 | (char * /*template*/, int /*suffixlen*/, int /*flags*/)); | |
359 | _GL_CXXALIASWARN (mkostemps); | |
f29ded4b LC |
360 | #elif defined GNULIB_POSIXCHECK |
361 | # undef mkostemps | |
61cd9dc9 LC |
362 | # if HAVE_RAW_DECL_MKOSTEMPS |
363 | _GL_WARN_ON_USE (mkostemps, "mkostemps is unportable - " | |
364 | "use gnulib module mkostemps for portability"); | |
365 | # endif | |
f29ded4b LC |
366 | #endif |
367 | ||
f240aacb | 368 | #if @GNULIB_MKSTEMP@ |
f240aacb LC |
369 | /* Create a unique temporary file from TEMPLATE. |
370 | The last six characters of TEMPLATE must be "XXXXXX"; | |
371 | they are replaced with a string that makes the file name unique. | |
372 | The file is then created, ensuring it didn't exist before. | |
373 | The file is created read-write (mask at least 0600 & ~umask), but it may be | |
374 | world-readable and world-writable (mask 0666 & ~umask), depending on the | |
375 | implementation. | |
376 | Returns the open file descriptor if successful, otherwise -1 and errno | |
377 | set. */ | |
f4c79b3c LC |
378 | # if @REPLACE_MKSTEMP@ |
379 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
380 | # define mkstemp rpl_mkstemp | |
381 | # endif | |
382 | _GL_FUNCDECL_RPL (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1))); | |
383 | _GL_CXXALIAS_RPL (mkstemp, int, (char * /*template*/)); | |
384 | # else | |
a927b6c1 LC |
385 | # if ! @HAVE_MKSTEMP@ |
386 | _GL_FUNCDECL_SYS (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1))); | |
387 | # endif | |
f4c79b3c | 388 | _GL_CXXALIAS_SYS (mkstemp, int, (char * /*template*/)); |
f240aacb | 389 | # endif |
f4c79b3c | 390 | _GL_CXXALIASWARN (mkstemp); |
f240aacb LC |
391 | #elif defined GNULIB_POSIXCHECK |
392 | # undef mkstemp | |
61cd9dc9 LC |
393 | # if HAVE_RAW_DECL_MKSTEMP |
394 | _GL_WARN_ON_USE (mkstemp, "mkstemp is unportable - " | |
395 | "use gnulib module mkstemp for portability"); | |
396 | # endif | |
f240aacb LC |
397 | #endif |
398 | ||
f29ded4b | 399 | #if @GNULIB_MKSTEMPS@ |
f29ded4b LC |
400 | /* Create a unique temporary file from TEMPLATE. |
401 | The last six characters of TEMPLATE prior to a suffix of length | |
402 | SUFFIXLEN must be "XXXXXX"; | |
403 | they are replaced with a string that makes the file name unique. | |
404 | The file is then created, ensuring it didn't exist before. | |
405 | The file is created read-write (mask at least 0600 & ~umask), but it may be | |
406 | world-readable and world-writable (mask 0666 & ~umask), depending on the | |
407 | implementation. | |
408 | Returns the open file descriptor if successful, otherwise -1 and errno | |
409 | set. */ | |
f4c79b3c LC |
410 | # if !@HAVE_MKSTEMPS@ |
411 | _GL_FUNCDECL_SYS (mkstemps, int, (char * /*template*/, int /*suffixlen*/) | |
412 | _GL_ARG_NONNULL ((1))); | |
f29ded4b | 413 | # endif |
f4c79b3c LC |
414 | _GL_CXXALIAS_SYS (mkstemps, int, (char * /*template*/, int /*suffixlen*/)); |
415 | _GL_CXXALIASWARN (mkstemps); | |
f29ded4b LC |
416 | #elif defined GNULIB_POSIXCHECK |
417 | # undef mkstemps | |
61cd9dc9 LC |
418 | # if HAVE_RAW_DECL_MKSTEMPS |
419 | _GL_WARN_ON_USE (mkstemps, "mkstemps is unportable - " | |
420 | "use gnulib module mkstemps for portability"); | |
421 | # endif | |
f29ded4b LC |
422 | #endif |
423 | ||
a927b6c1 LC |
424 | #if @GNULIB_PTSNAME@ |
425 | /* Return the pathname of the pseudo-terminal slave associated with | |
426 | the master FD is open on, or NULL on errors. */ | |
427 | # if !@HAVE_PTSNAME@ | |
428 | _GL_FUNCDECL_SYS (ptsname, char *, (int fd)); | |
429 | # endif | |
430 | _GL_CXXALIAS_SYS (ptsname, char *, (int fd)); | |
431 | _GL_CXXALIASWARN (ptsname); | |
432 | #elif defined GNULIB_POSIXCHECK | |
433 | # undef ptsname | |
434 | # if HAVE_RAW_DECL_PTSNAME | |
435 | _GL_WARN_ON_USE (ptsname, "ptsname is not portable - " | |
436 | "use gnulib module ptsname for portability"); | |
437 | # endif | |
438 | #endif | |
439 | ||
f240aacb LC |
440 | #if @GNULIB_PUTENV@ |
441 | # if @REPLACE_PUTENV@ | |
f4c79b3c LC |
442 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
443 | # undef putenv | |
444 | # define putenv rpl_putenv | |
445 | # endif | |
446 | _GL_FUNCDECL_RPL (putenv, int, (char *string) _GL_ARG_NONNULL ((1))); | |
447 | _GL_CXXALIAS_RPL (putenv, int, (char *string)); | |
448 | # else | |
449 | _GL_CXXALIAS_SYS (putenv, int, (char *string)); | |
f240aacb | 450 | # endif |
f4c79b3c | 451 | _GL_CXXALIASWARN (putenv); |
f240aacb LC |
452 | #endif |
453 | ||
f4c79b3c | 454 | |
f240aacb LC |
455 | #if @GNULIB_RANDOM_R@ |
456 | # if !@HAVE_RANDOM_R@ | |
f240aacb LC |
457 | # ifndef RAND_MAX |
458 | # define RAND_MAX 2147483647 | |
459 | # endif | |
f4c79b3c LC |
460 | # endif |
461 | #endif | |
f240aacb | 462 | |
f4c79b3c LC |
463 | #if @GNULIB_RANDOM_R@ |
464 | # if !@HAVE_RANDOM_R@ | |
465 | _GL_FUNCDECL_SYS (random_r, int, (struct random_data *buf, int32_t *result) | |
466 | _GL_ARG_NONNULL ((1, 2))); | |
f240aacb | 467 | # endif |
f4c79b3c LC |
468 | _GL_CXXALIAS_SYS (random_r, int, (struct random_data *buf, int32_t *result)); |
469 | _GL_CXXALIASWARN (random_r); | |
f240aacb LC |
470 | #elif defined GNULIB_POSIXCHECK |
471 | # undef random_r | |
61cd9dc9 LC |
472 | # if HAVE_RAW_DECL_RANDOM_R |
473 | _GL_WARN_ON_USE (random_r, "random_r is unportable - " | |
474 | "use gnulib module random_r for portability"); | |
475 | # endif | |
f4c79b3c LC |
476 | #endif |
477 | ||
478 | #if @GNULIB_RANDOM_R@ | |
479 | # if !@HAVE_RANDOM_R@ | |
480 | _GL_FUNCDECL_SYS (srandom_r, int, | |
481 | (unsigned int seed, struct random_data *rand_state) | |
482 | _GL_ARG_NONNULL ((2))); | |
61cd9dc9 | 483 | # endif |
f4c79b3c LC |
484 | _GL_CXXALIAS_SYS (srandom_r, int, |
485 | (unsigned int seed, struct random_data *rand_state)); | |
486 | _GL_CXXALIASWARN (srandom_r); | |
487 | #elif defined GNULIB_POSIXCHECK | |
f240aacb | 488 | # undef srandom_r |
61cd9dc9 LC |
489 | # if HAVE_RAW_DECL_SRANDOM_R |
490 | _GL_WARN_ON_USE (srandom_r, "srandom_r is unportable - " | |
491 | "use gnulib module random_r for portability"); | |
492 | # endif | |
f4c79b3c LC |
493 | #endif |
494 | ||
495 | #if @GNULIB_RANDOM_R@ | |
496 | # if !@HAVE_RANDOM_R@ | |
497 | _GL_FUNCDECL_SYS (initstate_r, int, | |
498 | (unsigned int seed, char *buf, size_t buf_size, | |
499 | struct random_data *rand_state) | |
500 | _GL_ARG_NONNULL ((2, 4))); | |
501 | # endif | |
502 | _GL_CXXALIAS_SYS (initstate_r, int, | |
503 | (unsigned int seed, char *buf, size_t buf_size, | |
504 | struct random_data *rand_state)); | |
505 | _GL_CXXALIASWARN (initstate_r); | |
506 | #elif defined GNULIB_POSIXCHECK | |
507 | # undef initstate_r | |
508 | # if HAVE_RAW_DECL_INITSTATE_R | |
509 | _GL_WARN_ON_USE (initstate_r, "initstate_r is unportable - " | |
510 | "use gnulib module random_r for portability"); | |
511 | # endif | |
512 | #endif | |
513 | ||
514 | #if @GNULIB_RANDOM_R@ | |
515 | # if !@HAVE_RANDOM_R@ | |
516 | _GL_FUNCDECL_SYS (setstate_r, int, | |
517 | (char *arg_state, struct random_data *rand_state) | |
518 | _GL_ARG_NONNULL ((1, 2))); | |
519 | # endif | |
520 | _GL_CXXALIAS_SYS (setstate_r, int, | |
521 | (char *arg_state, struct random_data *rand_state)); | |
522 | _GL_CXXALIASWARN (setstate_r); | |
523 | #elif defined GNULIB_POSIXCHECK | |
f240aacb | 524 | # undef setstate_r |
61cd9dc9 LC |
525 | # if HAVE_RAW_DECL_SETSTATE_R |
526 | _GL_WARN_ON_USE (setstate_r, "setstate_r is unportable - " | |
527 | "use gnulib module random_r for portability"); | |
528 | # endif | |
f240aacb LC |
529 | #endif |
530 | ||
f4c79b3c | 531 | |
8912421c | 532 | #if @GNULIB_REALLOC_POSIX@ |
9157d901 | 533 | # if @REPLACE_REALLOC@ |
f4c79b3c LC |
534 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
535 | # undef realloc | |
536 | # define realloc rpl_realloc | |
537 | # endif | |
538 | _GL_FUNCDECL_RPL (realloc, void *, (void *ptr, size_t size)); | |
539 | _GL_CXXALIAS_RPL (realloc, void *, (void *ptr, size_t size)); | |
540 | # else | |
541 | _GL_CXXALIAS_SYS (realloc, void *, (void *ptr, size_t size)); | |
8912421c | 542 | # endif |
f4c79b3c | 543 | _GL_CXXALIASWARN (realloc); |
8912421c LC |
544 | #elif defined GNULIB_POSIXCHECK |
545 | # undef realloc | |
61cd9dc9 LC |
546 | /* Assume realloc is always declared. */ |
547 | _GL_WARN_ON_USE (realloc, "realloc is not POSIX compliant everywhere - " | |
548 | "use gnulib module realloc-posix for portability"); | |
8912421c LC |
549 | #endif |
550 | ||
551 | #if @GNULIB_REALPATH@ | |
552 | # if @REPLACE_REALPATH@ | |
f4c79b3c LC |
553 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) |
554 | # define realpath rpl_realpath | |
555 | # endif | |
556 | _GL_FUNCDECL_RPL (realpath, char *, (const char *name, char *resolved) | |
557 | _GL_ARG_NONNULL ((1))); | |
558 | _GL_CXXALIAS_RPL (realpath, char *, (const char *name, char *resolved)); | |
559 | # else | |
560 | # if !@HAVE_REALPATH@ | |
561 | _GL_FUNCDECL_SYS (realpath, char *, (const char *name, char *resolved) | |
562 | _GL_ARG_NONNULL ((1))); | |
563 | # endif | |
564 | _GL_CXXALIAS_SYS (realpath, char *, (const char *name, char *resolved)); | |
8912421c | 565 | # endif |
f4c79b3c | 566 | _GL_CXXALIASWARN (realpath); |
8912421c LC |
567 | #elif defined GNULIB_POSIXCHECK |
568 | # undef realpath | |
61cd9dc9 LC |
569 | # if HAVE_RAW_DECL_REALPATH |
570 | _GL_WARN_ON_USE (realpath, "realpath is unportable - use gnulib module " | |
571 | "canonicalize or canonicalize-lgpl for portability"); | |
572 | # endif | |
8912421c | 573 | #endif |
f240aacb LC |
574 | |
575 | #if @GNULIB_RPMATCH@ | |
f240aacb LC |
576 | /* Test a user response to a question. |
577 | Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */ | |
f4c79b3c LC |
578 | # if !@HAVE_RPMATCH@ |
579 | _GL_FUNCDECL_SYS (rpmatch, int, (const char *response) _GL_ARG_NONNULL ((1))); | |
f240aacb | 580 | # endif |
f4c79b3c LC |
581 | _GL_CXXALIAS_SYS (rpmatch, int, (const char *response)); |
582 | _GL_CXXALIASWARN (rpmatch); | |
f240aacb LC |
583 | #elif defined GNULIB_POSIXCHECK |
584 | # undef rpmatch | |
61cd9dc9 LC |
585 | # if HAVE_RAW_DECL_RPMATCH |
586 | _GL_WARN_ON_USE (rpmatch, "rpmatch is unportable - " | |
587 | "use gnulib module rpmatch for portability"); | |
588 | # endif | |
f240aacb LC |
589 | #endif |
590 | ||
f240aacb | 591 | #if @GNULIB_SETENV@ |
f240aacb LC |
592 | /* Set NAME to VALUE in the environment. |
593 | If REPLACE is nonzero, overwrite an existing value. */ | |
f4c79b3c LC |
594 | # if @REPLACE_SETENV@ |
595 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
596 | # undef setenv | |
597 | # define setenv rpl_setenv | |
598 | # endif | |
599 | _GL_FUNCDECL_RPL (setenv, int, | |
600 | (const char *name, const char *value, int replace) | |
601 | _GL_ARG_NONNULL ((1))); | |
602 | _GL_CXXALIAS_RPL (setenv, int, | |
603 | (const char *name, const char *value, int replace)); | |
604 | # else | |
ab4d62ad | 605 | # if !@HAVE_DECL_SETENV@ |
f4c79b3c LC |
606 | _GL_FUNCDECL_SYS (setenv, int, |
607 | (const char *name, const char *value, int replace) | |
608 | _GL_ARG_NONNULL ((1))); | |
609 | # endif | |
610 | _GL_CXXALIAS_SYS (setenv, int, | |
611 | (const char *name, const char *value, int replace)); | |
f240aacb | 612 | # endif |
ab4d62ad | 613 | # if !(@REPLACE_SETENV@ && !@HAVE_DECL_SETENV@) |
f4c79b3c | 614 | _GL_CXXALIASWARN (setenv); |
ab4d62ad | 615 | # endif |
4f02b98d LC |
616 | #elif defined GNULIB_POSIXCHECK |
617 | # undef setenv | |
61cd9dc9 LC |
618 | # if HAVE_RAW_DECL_SETENV |
619 | _GL_WARN_ON_USE (setenv, "setenv is unportable - " | |
620 | "use gnulib module setenv for portability"); | |
621 | # endif | |
f240aacb LC |
622 | #endif |
623 | ||
f240aacb | 624 | #if @GNULIB_STRTOD@ |
f240aacb | 625 | /* Parse a double from STRING, updating ENDP if appropriate. */ |
f4c79b3c LC |
626 | # if @REPLACE_STRTOD@ |
627 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
628 | # define strtod rpl_strtod | |
629 | # endif | |
630 | _GL_FUNCDECL_RPL (strtod, double, (const char *str, char **endp) | |
631 | _GL_ARG_NONNULL ((1))); | |
632 | _GL_CXXALIAS_RPL (strtod, double, (const char *str, char **endp)); | |
633 | # else | |
634 | # if !@HAVE_STRTOD@ | |
635 | _GL_FUNCDECL_SYS (strtod, double, (const char *str, char **endp) | |
636 | _GL_ARG_NONNULL ((1))); | |
637 | # endif | |
638 | _GL_CXXALIAS_SYS (strtod, double, (const char *str, char **endp)); | |
f240aacb | 639 | # endif |
f4c79b3c | 640 | _GL_CXXALIASWARN (strtod); |
f240aacb LC |
641 | #elif defined GNULIB_POSIXCHECK |
642 | # undef strtod | |
61cd9dc9 LC |
643 | # if HAVE_RAW_DECL_STRTOD |
644 | _GL_WARN_ON_USE (strtod, "strtod is unportable - " | |
645 | "use gnulib module strtod for portability"); | |
646 | # endif | |
f240aacb LC |
647 | #endif |
648 | ||
f240aacb | 649 | #if @GNULIB_STRTOLL@ |
f240aacb LC |
650 | /* Parse a signed integer whose textual representation starts at STRING. |
651 | The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0, | |
652 | it may be decimal or octal (with prefix "0") or hexadecimal (with prefix | |
653 | "0x"). | |
654 | If ENDPTR is not NULL, the address of the first byte after the integer is | |
655 | stored in *ENDPTR. | |
656 | Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set | |
657 | to ERANGE. */ | |
f4c79b3c LC |
658 | # if !@HAVE_STRTOLL@ |
659 | _GL_FUNCDECL_SYS (strtoll, long long, | |
660 | (const char *string, char **endptr, int base) | |
661 | _GL_ARG_NONNULL ((1))); | |
f240aacb | 662 | # endif |
f4c79b3c LC |
663 | _GL_CXXALIAS_SYS (strtoll, long long, |
664 | (const char *string, char **endptr, int base)); | |
665 | _GL_CXXALIASWARN (strtoll); | |
f240aacb LC |
666 | #elif defined GNULIB_POSIXCHECK |
667 | # undef strtoll | |
61cd9dc9 LC |
668 | # if HAVE_RAW_DECL_STRTOLL |
669 | _GL_WARN_ON_USE (strtoll, "strtoll is unportable - " | |
670 | "use gnulib module strtoll for portability"); | |
671 | # endif | |
f240aacb LC |
672 | #endif |
673 | ||
f240aacb | 674 | #if @GNULIB_STRTOULL@ |
f240aacb LC |
675 | /* Parse an unsigned integer whose textual representation starts at STRING. |
676 | The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0, | |
677 | it may be decimal or octal (with prefix "0") or hexadecimal (with prefix | |
678 | "0x"). | |
679 | If ENDPTR is not NULL, the address of the first byte after the integer is | |
680 | stored in *ENDPTR. | |
681 | Upon overflow, the return value is ULLONG_MAX, and errno is set to | |
682 | ERANGE. */ | |
f4c79b3c LC |
683 | # if !@HAVE_STRTOULL@ |
684 | _GL_FUNCDECL_SYS (strtoull, unsigned long long, | |
685 | (const char *string, char **endptr, int base) | |
686 | _GL_ARG_NONNULL ((1))); | |
f240aacb | 687 | # endif |
f4c79b3c LC |
688 | _GL_CXXALIAS_SYS (strtoull, unsigned long long, |
689 | (const char *string, char **endptr, int base)); | |
690 | _GL_CXXALIASWARN (strtoull); | |
f240aacb LC |
691 | #elif defined GNULIB_POSIXCHECK |
692 | # undef strtoull | |
61cd9dc9 LC |
693 | # if HAVE_RAW_DECL_STRTOULL |
694 | _GL_WARN_ON_USE (strtoull, "strtoull is unportable - " | |
695 | "use gnulib module strtoull for portability"); | |
696 | # endif | |
f240aacb LC |
697 | #endif |
698 | ||
a927b6c1 LC |
699 | #if @GNULIB_UNLOCKPT@ |
700 | /* Unlock the slave side of the pseudo-terminal whose master side is specified | |
701 | by FD, so that it can be opened. */ | |
702 | # if !@HAVE_UNLOCKPT@ | |
703 | _GL_FUNCDECL_SYS (unlockpt, int, (int fd)); | |
704 | # endif | |
705 | _GL_CXXALIAS_SYS (unlockpt, int, (int fd)); | |
706 | _GL_CXXALIASWARN (unlockpt); | |
707 | #elif defined GNULIB_POSIXCHECK | |
708 | # undef unlockpt | |
709 | # if HAVE_RAW_DECL_UNLOCKPT | |
0f00f2c3 | 710 | _GL_WARN_ON_USE (unlockpt, "unlockpt is not portable - " |
a927b6c1 LC |
711 | "use gnulib module unlockpt for portability"); |
712 | # endif | |
713 | #endif | |
714 | ||
8912421c | 715 | #if @GNULIB_UNSETENV@ |
8912421c | 716 | /* Remove the variable NAME from the environment. */ |
f4c79b3c LC |
717 | # if @REPLACE_UNSETENV@ |
718 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
719 | # undef unsetenv | |
720 | # define unsetenv rpl_unsetenv | |
721 | # endif | |
722 | _GL_FUNCDECL_RPL (unsetenv, int, (const char *name) _GL_ARG_NONNULL ((1))); | |
723 | _GL_CXXALIAS_RPL (unsetenv, int, (const char *name)); | |
724 | # else | |
ab4d62ad | 725 | # if !@HAVE_DECL_UNSETENV@ |
f4c79b3c LC |
726 | _GL_FUNCDECL_SYS (unsetenv, int, (const char *name) _GL_ARG_NONNULL ((1))); |
727 | # endif | |
728 | _GL_CXXALIAS_SYS (unsetenv, int, (const char *name)); | |
8912421c | 729 | # endif |
ab4d62ad | 730 | # if !(@REPLACE_UNSETENV@ && !@HAVE_DECL_UNSETENV@) |
f4c79b3c | 731 | _GL_CXXALIASWARN (unsetenv); |
ab4d62ad | 732 | # endif |
4f02b98d LC |
733 | #elif defined GNULIB_POSIXCHECK |
734 | # undef unsetenv | |
61cd9dc9 LC |
735 | # if HAVE_RAW_DECL_UNSETENV |
736 | _GL_WARN_ON_USE (unsetenv, "unsetenv is unportable - " | |
737 | "use gnulib module unsetenv for portability"); | |
738 | # endif | |
8912421c | 739 | #endif |
f240aacb | 740 | |
dd36ce77 MW |
741 | /* Convert a wide character to a multibyte character. */ |
742 | #if @GNULIB_WCTOMB@ | |
743 | # if @REPLACE_WCTOMB@ | |
744 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
745 | # undef wctomb | |
746 | # define wctomb rpl_wctomb | |
747 | # endif | |
748 | _GL_FUNCDECL_RPL (wctomb, int, (char *s, wchar_t wc)); | |
749 | _GL_CXXALIAS_RPL (wctomb, int, (char *s, wchar_t wc)); | |
750 | # else | |
751 | _GL_CXXALIAS_SYS (wctomb, int, (char *s, wchar_t wc)); | |
752 | # endif | |
753 | _GL_CXXALIASWARN (wctomb); | |
754 | #endif | |
755 | ||
f240aacb LC |
756 | |
757 | #endif /* _GL_STDLIB_H */ | |
758 | #endif /* _GL_STDLIB_H */ | |
759 | #endif |