stdlib.in.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* A GNU-like <stdlib.h>.
  2. Copyright (C) 1995, 2001-2004, 2006-2007 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 defined __need_malloc_and_calloc
  14. /* Special invocation convention inside glibc header files. */
  15. #@INCLUDE_NEXT@ @NEXT_STDLIB_H@
  16. #else
  17. /* Normal invocation convention. */
  18. #ifndef _GL_STDLIB_H
  19. /* The include_next requires a split double-inclusion guard. */
  20. #@INCLUDE_NEXT@ @NEXT_STDLIB_H@
  21. #ifndef _GL_STDLIB_H
  22. #define _GL_STDLIB_H
  23. /* The definition of GL_LINK_WARNING is copied here. */
  24. /* Some systems do not define EXIT_*, despite otherwise supporting C89. */
  25. #ifndef EXIT_SUCCESS
  26. # define EXIT_SUCCESS 0
  27. #endif
  28. /* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
  29. with proper operation of xargs. */
  30. #ifndef EXIT_FAILURE
  31. # define EXIT_FAILURE 1
  32. #elif EXIT_FAILURE != 1
  33. # undef EXIT_FAILURE
  34. # define EXIT_FAILURE 1
  35. #endif
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. #if @GNULIB_MALLOC_POSIX@
  40. # if !@HAVE_MALLOC_POSIX@
  41. # undef malloc
  42. # define malloc rpl_malloc
  43. extern void * malloc (size_t size);
  44. # endif
  45. #elif defined GNULIB_POSIXCHECK
  46. # undef malloc
  47. # define malloc(s) \
  48. (GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \
  49. "use gnulib module malloc-posix for portability"), \
  50. malloc (s))
  51. #endif
  52. #if @GNULIB_REALLOC_POSIX@
  53. # if !@HAVE_REALLOC_POSIX@
  54. # undef realloc
  55. # define realloc rpl_realloc
  56. extern void * realloc (void *ptr, size_t size);
  57. # endif
  58. #elif defined GNULIB_POSIXCHECK
  59. # undef realloc
  60. # define realloc(p,s) \
  61. (GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \
  62. "use gnulib module realloc-posix for portability"), \
  63. realloc (p, s))
  64. #endif
  65. #if @GNULIB_CALLOC_POSIX@
  66. # if !@HAVE_CALLOC_POSIX@
  67. # undef calloc
  68. # define calloc rpl_calloc
  69. extern void * calloc (size_t nmemb, size_t size);
  70. # endif
  71. #elif defined GNULIB_POSIXCHECK
  72. # undef calloc
  73. # define calloc(n,s) \
  74. (GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \
  75. "use gnulib module calloc-posix for portability"), \
  76. calloc (n, s))
  77. #endif
  78. #if @GNULIB_GETSUBOPT@
  79. /* Assuming *OPTIONP is a comma separated list of elements of the form
  80. "token" or "token=value", getsubopt parses the first of these elements.
  81. If the first element refers to a "token" that is member of the given
  82. NULL-terminated array of tokens:
  83. - It replaces the comma with a NUL byte, updates *OPTIONP to point past
  84. the first option and the comma, sets *VALUEP to the value of the
  85. element (or NULL if it doesn't contain an "=" sign),
  86. - It returns the index of the "token" in the given array of tokens.
  87. Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
  88. For more details see the POSIX:2001 specification.
  89. http://www.opengroup.org/susv3xsh/getsubopt.html */
  90. # if !@HAVE_GETSUBOPT@
  91. extern int getsubopt (char **optionp, char *const *tokens, char **valuep);
  92. # endif
  93. #elif defined GNULIB_POSIXCHECK
  94. # undef getsubopt
  95. # define getsubopt(o,t,v) \
  96. (GL_LINK_WARNING ("getsubopt is unportable - " \
  97. "use gnulib module getsubopt for portability"), \
  98. getsubopt (o, t, v))
  99. #endif
  100. #if @GNULIB_MKDTEMP@
  101. # if !@HAVE_MKDTEMP@
  102. /* Create a unique temporary directory from TEMPLATE.
  103. The last six characters of TEMPLATE must be "XXXXXX";
  104. they are replaced with a string that makes the directory name unique.
  105. Returns TEMPLATE, or a null pointer if it cannot get a unique name.
  106. The directory is created mode 700. */
  107. extern char * mkdtemp (char * /*template*/);
  108. # endif
  109. #elif defined GNULIB_POSIXCHECK
  110. # undef mkdtemp
  111. # define mkdtemp(t) \
  112. (GL_LINK_WARNING ("mkdtemp is unportable - " \
  113. "use gnulib module mkdtemp for portability"), \
  114. mkdtemp (t))
  115. #endif
  116. #if @GNULIB_MKSTEMP@
  117. # if @REPLACE_MKSTEMP@
  118. /* Create a unique temporary file from TEMPLATE.
  119. The last six characters of TEMPLATE must be "XXXXXX";
  120. they are replaced with a string that makes the file name unique.
  121. The file is then created, ensuring it didn't exist before.
  122. The file is created read-write (mask at least 0600 & ~umask), but it may be
  123. world-readable and world-writable (mask 0666 & ~umask), depending on the
  124. implementation.
  125. Returns the open file descriptor if successful, otherwise -1 and errno
  126. set. */
  127. # define mkstemp rpl_mkstemp
  128. extern int mkstemp (char * /*template*/);
  129. # else
  130. /* On MacOS X 10.3, only <unistd.h> declares mkstemp. */
  131. # include <unistd.h>
  132. # endif
  133. #elif defined GNULIB_POSIXCHECK
  134. # undef mkstemp
  135. # define mkstemp(t) \
  136. (GL_LINK_WARNING ("mkstemp is unportable - " \
  137. "use gnulib module mkstemp for portability"), \
  138. mkstemp (t))
  139. #endif
  140. #if @GNULIB_PUTENV@
  141. # if @REPLACE_PUTENV@
  142. # undef putenv
  143. # define putenv rpl_putenv
  144. extern int putenv (char *string);
  145. # endif
  146. #endif
  147. #if @GNULIB_SETENV@
  148. # if !@HAVE_SETENV@
  149. /* Set NAME to VALUE in the environment.
  150. If REPLACE is nonzero, overwrite an existing value. */
  151. extern int setenv (const char *name, const char *value, int replace);
  152. # endif
  153. #endif
  154. #if @GNULIB_UNSETENV@
  155. # if @HAVE_UNSETENV@
  156. # if @VOID_UNSETENV@
  157. /* On some systems, unsetenv() returns void.
  158. This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */
  159. # define unsetenv(name) ((unsetenv)(name), 0)
  160. # endif
  161. # else
  162. /* Remove the variable NAME from the environment. */
  163. extern int unsetenv (const char *name);
  164. # endif
  165. #endif
  166. #ifdef __cplusplus
  167. }
  168. #endif
  169. #endif /* _GL_STDLIB_H */
  170. #endif /* _GL_STDLIB_H */
  171. #endif