stdlib.in.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /* A GNU-like <stdlib.h>.
  2. Copyright (C) 1995, 2001-2004, 2006-2009 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #if __GNUC__ >= 3
  14. @PRAGMA_SYSTEM_HEADER@
  15. #endif
  16. #if defined __need_malloc_and_calloc
  17. /* Special invocation convention inside glibc header files. */
  18. #@INCLUDE_NEXT@ @NEXT_STDLIB_H@
  19. #else
  20. /* Normal invocation convention. */
  21. #ifndef _GL_STDLIB_H
  22. /* The include_next requires a split double-inclusion guard. */
  23. #@INCLUDE_NEXT@ @NEXT_STDLIB_H@
  24. #ifndef _GL_STDLIB_H
  25. #define _GL_STDLIB_H
  26. /* Solaris declares getloadavg() in <sys/loadavg.h>. */
  27. #if @GNULIB_GETLOADAVG@ && @HAVE_SYS_LOADAVG_H@
  28. # include <sys/loadavg.h>
  29. #endif
  30. /* OSF/1 5.1 declares 'struct random_data' in <random.h>, which is included
  31. from <stdlib.h> if _REENTRANT is defined. Include it always. */
  32. #if @HAVE_RANDOM_H@
  33. # include <random.h>
  34. #endif
  35. #if @GNULIB_RANDOM_R@ || !@HAVE_STRUCT_RANDOM_DATA@
  36. # include <stdint.h>
  37. #endif
  38. #if !@HAVE_STRUCT_RANDOM_DATA@
  39. struct random_data
  40. {
  41. int32_t *fptr; /* Front pointer. */
  42. int32_t *rptr; /* Rear pointer. */
  43. int32_t *state; /* Array of state values. */
  44. int rand_type; /* Type of random number generator. */
  45. int rand_deg; /* Degree of random number generator. */
  46. int rand_sep; /* Distance between front and rear. */
  47. int32_t *end_ptr; /* Pointer behind state table. */
  48. };
  49. #endif
  50. /* The definition of GL_LINK_WARNING is copied here. */
  51. /* Some systems do not define EXIT_*, despite otherwise supporting C89. */
  52. #ifndef EXIT_SUCCESS
  53. # define EXIT_SUCCESS 0
  54. #endif
  55. /* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
  56. with proper operation of xargs. */
  57. #ifndef EXIT_FAILURE
  58. # define EXIT_FAILURE 1
  59. #elif EXIT_FAILURE != 1
  60. # undef EXIT_FAILURE
  61. # define EXIT_FAILURE 1
  62. #endif
  63. #ifdef __cplusplus
  64. extern "C" {
  65. #endif
  66. #if @GNULIB_MALLOC_POSIX@
  67. # if !@HAVE_MALLOC_POSIX@
  68. # undef malloc
  69. # define malloc rpl_malloc
  70. extern void * malloc (size_t size);
  71. # endif
  72. #elif defined GNULIB_POSIXCHECK
  73. # undef malloc
  74. # define malloc(s) \
  75. (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \
  76. "use gnulib module malloc-posix for portability"), \
  77. malloc (s))
  78. #endif
  79. #if @GNULIB_REALLOC_POSIX@
  80. # if !@HAVE_REALLOC_POSIX@
  81. # undef realloc
  82. # define realloc rpl_realloc
  83. extern void * realloc (void *ptr, size_t size);
  84. # endif
  85. #elif defined GNULIB_POSIXCHECK
  86. # undef realloc
  87. # define realloc(p,s) \
  88. (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \
  89. "use gnulib module realloc-posix for portability"), \
  90. realloc (p, s))
  91. #endif
  92. #if @GNULIB_CALLOC_POSIX@
  93. # if !@HAVE_CALLOC_POSIX@
  94. # undef calloc
  95. # define calloc rpl_calloc
  96. extern void * calloc (size_t nmemb, size_t size);
  97. # endif
  98. #elif defined GNULIB_POSIXCHECK
  99. # undef calloc
  100. # define calloc(n,s) \
  101. (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \
  102. "use gnulib module calloc-posix for portability"), \
  103. calloc (n, s))
  104. #endif
  105. #if @GNULIB_ATOLL@
  106. # if !@HAVE_ATOLL@
  107. /* Parse a signed decimal integer.
  108. Returns the value of the integer. Errors are not detected. */
  109. extern long long atoll (const char *string);
  110. # endif
  111. #elif defined GNULIB_POSIXCHECK
  112. # undef atoll
  113. # define atoll(s) \
  114. (GL_LINK_WARNING ("atoll is unportable - " \
  115. "use gnulib module atoll for portability"), \
  116. atoll (s))
  117. #endif
  118. #if @GNULIB_GETLOADAVG@
  119. # if !@HAVE_DECL_GETLOADAVG@
  120. /* Store max(NELEM,3) load average numbers in LOADAVG[].
  121. The three numbers are the load average of the last 1 minute, the last 5
  122. minutes, and the last 15 minutes, respectively.
  123. LOADAVG is an array of NELEM numbers. */
  124. extern int getloadavg (double loadavg[], int nelem);
  125. # endif
  126. #elif defined GNULIB_POSIXCHECK
  127. # undef getloadavg
  128. # define getloadavg(l,n) \
  129. (GL_LINK_WARNING ("getloadavg is not portable - " \
  130. "use gnulib module getloadavg for portability"), \
  131. getloadavg (l, n))
  132. #endif
  133. #if @GNULIB_GETSUBOPT@
  134. /* Assuming *OPTIONP is a comma separated list of elements of the form
  135. "token" or "token=value", getsubopt parses the first of these elements.
  136. If the first element refers to a "token" that is member of the given
  137. NULL-terminated array of tokens:
  138. - It replaces the comma with a NUL byte, updates *OPTIONP to point past
  139. the first option and the comma, sets *VALUEP to the value of the
  140. element (or NULL if it doesn't contain an "=" sign),
  141. - It returns the index of the "token" in the given array of tokens.
  142. Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
  143. For more details see the POSIX:2001 specification.
  144. http://www.opengroup.org/susv3xsh/getsubopt.html */
  145. # if !@HAVE_GETSUBOPT@
  146. extern int getsubopt (char **optionp, char *const *tokens, char **valuep);
  147. # endif
  148. #elif defined GNULIB_POSIXCHECK
  149. # undef getsubopt
  150. # define getsubopt(o,t,v) \
  151. (GL_LINK_WARNING ("getsubopt is unportable - " \
  152. "use gnulib module getsubopt for portability"), \
  153. getsubopt (o, t, v))
  154. #endif
  155. #if @GNULIB_MKDTEMP@
  156. # if !@HAVE_MKDTEMP@
  157. /* Create a unique temporary directory from TEMPLATE.
  158. The last six characters of TEMPLATE must be "XXXXXX";
  159. they are replaced with a string that makes the directory name unique.
  160. Returns TEMPLATE, or a null pointer if it cannot get a unique name.
  161. The directory is created mode 700. */
  162. extern char * mkdtemp (char * /*template*/);
  163. # endif
  164. #elif defined GNULIB_POSIXCHECK
  165. # undef mkdtemp
  166. # define mkdtemp(t) \
  167. (GL_LINK_WARNING ("mkdtemp is unportable - " \
  168. "use gnulib module mkdtemp for portability"), \
  169. mkdtemp (t))
  170. #endif
  171. #if @GNULIB_MKSTEMP@
  172. # if @REPLACE_MKSTEMP@
  173. /* Create a unique temporary file from TEMPLATE.
  174. The last six characters of TEMPLATE must be "XXXXXX";
  175. they are replaced with a string that makes the file name unique.
  176. The file is then created, ensuring it didn't exist before.
  177. The file is created read-write (mask at least 0600 & ~umask), but it may be
  178. world-readable and world-writable (mask 0666 & ~umask), depending on the
  179. implementation.
  180. Returns the open file descriptor if successful, otherwise -1 and errno
  181. set. */
  182. # define mkstemp rpl_mkstemp
  183. extern int mkstemp (char * /*template*/);
  184. # else
  185. /* On MacOS X 10.3, only <unistd.h> declares mkstemp. */
  186. # include <unistd.h>
  187. # endif
  188. #elif defined GNULIB_POSIXCHECK
  189. # undef mkstemp
  190. # define mkstemp(t) \
  191. (GL_LINK_WARNING ("mkstemp is unportable - " \
  192. "use gnulib module mkstemp for portability"), \
  193. mkstemp (t))
  194. #endif
  195. #if @GNULIB_PUTENV@
  196. # if @REPLACE_PUTENV@
  197. # undef putenv
  198. # define putenv rpl_putenv
  199. extern int putenv (char *string);
  200. # endif
  201. #endif
  202. #if @GNULIB_RANDOM_R@
  203. # if !@HAVE_RANDOM_R@
  204. # ifndef RAND_MAX
  205. # define RAND_MAX 2147483647
  206. # endif
  207. int srandom_r (unsigned int seed, struct random_data *rand_state);
  208. int initstate_r (unsigned int seed, char *buf, size_t buf_size,
  209. struct random_data *rand_state);
  210. int setstate_r (char *arg_state, struct random_data *rand_state);
  211. int random_r (struct random_data *buf, int32_t *result);
  212. # endif
  213. #elif defined GNULIB_POSIXCHECK
  214. # undef random_r
  215. # define random_r(b,r) \
  216. (GL_LINK_WARNING ("random_r is unportable - " \
  217. "use gnulib module random_r for portability"), \
  218. random_r (b,r))
  219. # undef initstate_r
  220. # define initstate_r(s,b,sz,r) \
  221. (GL_LINK_WARNING ("initstate_r is unportable - " \
  222. "use gnulib module random_r for portability"), \
  223. initstate_r (s,b,sz,r))
  224. # undef srandom_r
  225. # define srandom_r(s,r) \
  226. (GL_LINK_WARNING ("srandom_r is unportable - " \
  227. "use gnulib module random_r for portability"), \
  228. srandom_r (s,r))
  229. # undef setstate_r
  230. # define setstate_r(a,r) \
  231. (GL_LINK_WARNING ("setstate_r is unportable - " \
  232. "use gnulib module random_r for portability"), \
  233. setstate_r (a,r))
  234. #endif
  235. #if @GNULIB_RPMATCH@
  236. # if !@HAVE_RPMATCH@
  237. /* Test a user response to a question.
  238. Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
  239. extern int rpmatch (const char *response);
  240. # endif
  241. #elif defined GNULIB_POSIXCHECK
  242. # undef rpmatch
  243. # define rpmatch(r) \
  244. (GL_LINK_WARNING ("rpmatch is unportable - " \
  245. "use gnulib module rpmatch for portability"), \
  246. rpmatch (r))
  247. #endif
  248. #if @GNULIB_SETENV@
  249. # if !@HAVE_SETENV@
  250. /* Set NAME to VALUE in the environment.
  251. If REPLACE is nonzero, overwrite an existing value. */
  252. extern int setenv (const char *name, const char *value, int replace);
  253. # endif
  254. #endif
  255. #if @GNULIB_UNSETENV@
  256. # if @HAVE_UNSETENV@
  257. # if @VOID_UNSETENV@
  258. /* On some systems, unsetenv() returns void.
  259. This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */
  260. # define unsetenv(name) ((unsetenv)(name), 0)
  261. # endif
  262. # else
  263. /* Remove the variable NAME from the environment. */
  264. extern int unsetenv (const char *name);
  265. # endif
  266. #endif
  267. #if @GNULIB_STRTOD@
  268. # if @REPLACE_STRTOD@
  269. # define strtod rpl_strtod
  270. # endif
  271. # if !@HAVE_STRTOD@ || @REPLACE_STRTOD@
  272. /* Parse a double from STRING, updating ENDP if appropriate. */
  273. extern double strtod (const char *str, char **endp);
  274. # endif
  275. #elif defined GNULIB_POSIXCHECK
  276. # undef strtod
  277. # define strtod(s, e) \
  278. (GL_LINK_WARNING ("strtod is unportable - " \
  279. "use gnulib module strtod for portability"), \
  280. strtod (s, e))
  281. #endif
  282. #if @GNULIB_STRTOLL@
  283. # if !@HAVE_STRTOLL@
  284. /* Parse a signed integer whose textual representation starts at STRING.
  285. The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
  286. it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
  287. "0x").
  288. If ENDPTR is not NULL, the address of the first byte after the integer is
  289. stored in *ENDPTR.
  290. Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
  291. to ERANGE. */
  292. extern long long strtoll (const char *string, char **endptr, int base);
  293. # endif
  294. #elif defined GNULIB_POSIXCHECK
  295. # undef strtoll
  296. # define strtoll(s,e,b) \
  297. (GL_LINK_WARNING ("strtoll is unportable - " \
  298. "use gnulib module strtoll for portability"), \
  299. strtoll (s, e, b))
  300. #endif
  301. #if @GNULIB_STRTOULL@
  302. # if !@HAVE_STRTOULL@
  303. /* Parse an unsigned integer whose textual representation starts at STRING.
  304. The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
  305. it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
  306. "0x").
  307. If ENDPTR is not NULL, the address of the first byte after the integer is
  308. stored in *ENDPTR.
  309. Upon overflow, the return value is ULLONG_MAX, and errno is set to
  310. ERANGE. */
  311. extern unsigned long long strtoull (const char *string, char **endptr, int base);
  312. # endif
  313. #elif defined GNULIB_POSIXCHECK
  314. # undef strtoull
  315. # define strtoull(s,e,b) \
  316. (GL_LINK_WARNING ("strtoull is unportable - " \
  317. "use gnulib module strtoull for portability"), \
  318. strtoull (s, e, b))
  319. #endif
  320. #ifdef __cplusplus
  321. }
  322. #endif
  323. #endif /* _GL_STDLIB_H */
  324. #endif /* _GL_STDLIB_H */
  325. #endif