stdlib.in.h 11 KB

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