4
0

unistd.in.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /* Substitute for and wrapper around <unistd.h>.
  2. Copyright (C) 2004-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, or (at your option)
  6. 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, write to the Free Software Foundation,
  13. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  14. #ifndef _GL_UNISTD_H
  15. /* The include_next requires a split double-inclusion guard. */
  16. #if @HAVE_UNISTD_H@
  17. # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
  18. #endif
  19. #ifndef _GL_UNISTD_H
  20. #define _GL_UNISTD_H
  21. /* mingw doesn't define the SEEK_* macros in <unistd.h>. */
  22. #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
  23. # include <stdio.h>
  24. #endif
  25. /* mingw fails to declare _exit in <unistd.h>. */
  26. #include <stdlib.h>
  27. /* The definition of GL_LINK_WARNING is copied here. */
  28. /* Declare overridden functions. */
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #if @GNULIB_CHOWN@
  33. # if @REPLACE_CHOWN@
  34. # ifndef REPLACE_CHOWN
  35. # define REPLACE_CHOWN 1
  36. # endif
  37. # if REPLACE_CHOWN
  38. /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
  39. to GID (if GID is not -1). Follow symbolic links.
  40. Return 0 if successful, otherwise -1 and errno set.
  41. See the POSIX:2001 specification
  42. <http://www.opengroup.org/susv3xsh/chown.html>. */
  43. # define chown rpl_chown
  44. extern int chown (const char *file, uid_t uid, gid_t gid);
  45. # endif
  46. # endif
  47. #elif defined GNULIB_POSIXCHECK
  48. # undef chown
  49. # define chown(f,u,g) \
  50. (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
  51. "doesn't treat a uid or gid of -1 on some systems - " \
  52. "use gnulib module chown for portability"), \
  53. chown (f, u, g))
  54. #endif
  55. #if @GNULIB_DUP2@
  56. # if !@HAVE_DUP2@
  57. /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
  58. NEWFD = OLDFD, otherwise close NEWFD first if it is open.
  59. Return 0 if successful, otherwise -1 and errno set.
  60. See the POSIX:2001 specification
  61. <http://www.opengroup.org/susv3xsh/dup2.html>. */
  62. extern int dup2 (int oldfd, int newfd);
  63. # endif
  64. #elif defined GNULIB_POSIXCHECK
  65. # undef dup2
  66. # define dup2(o,n) \
  67. (GL_LINK_WARNING ("dup2 is unportable - " \
  68. "use gnulib module dup2 for portability"), \
  69. dup2 (o, n))
  70. #endif
  71. #if @GNULIB_FCHDIR@
  72. # if @REPLACE_FCHDIR@
  73. /* Change the process' current working directory to the directory on which
  74. the given file descriptor is open.
  75. Return 0 if successful, otherwise -1 and errno set.
  76. See the POSIX:2001 specification
  77. <http://www.opengroup.org/susv3xsh/fchdir.html>. */
  78. extern int fchdir (int /*fd*/);
  79. # define close rpl_close
  80. extern int close (int);
  81. # define dup rpl_dup
  82. extern int dup (int);
  83. # define dup2 rpl_dup2
  84. extern int dup2 (int, int);
  85. # endif
  86. #elif defined GNULIB_POSIXCHECK
  87. # undef fchdir
  88. # define fchdir(f) \
  89. (GL_LINK_WARNING ("fchdir is unportable - " \
  90. "use gnulib module fchdir for portability"), \
  91. fchdir (f))
  92. #endif
  93. #if @GNULIB_FTRUNCATE@
  94. # if !@HAVE_FTRUNCATE@
  95. /* Change the size of the file to which FD is opened to become equal to LENGTH.
  96. Return 0 if successful, otherwise -1 and errno set.
  97. See the POSIX:2001 specification
  98. <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
  99. extern int ftruncate (int fd, off_t length);
  100. # endif
  101. #elif defined GNULIB_POSIXCHECK
  102. # undef ftruncate
  103. # define ftruncate(f,l) \
  104. (GL_LINK_WARNING ("ftruncate is unportable - " \
  105. "use gnulib module ftruncate for portability"), \
  106. ftruncate (f, l))
  107. #endif
  108. #if @GNULIB_GETCWD@
  109. /* Include the headers that might declare getcwd so that they will not
  110. cause confusion if included after this file. */
  111. # include <stdlib.h>
  112. # if @REPLACE_GETCWD@
  113. /* Get the name of the current working directory, and put it in SIZE bytes
  114. of BUF.
  115. Return BUF if successful, or NULL if the directory couldn't be determined
  116. or SIZE was too small.
  117. See the POSIX:2001 specification
  118. <http://www.opengroup.org/susv3xsh/getcwd.html>.
  119. Additionally, the gnulib module 'getcwd' guarantees the following GNU
  120. extension: If BUF is NULL, an array is allocated with 'malloc'; the array
  121. is SIZE bytes long, unless SIZE == 0, in which case it is as big as
  122. necessary. */
  123. # define getcwd rpl_getcwd
  124. extern char * getcwd (char *buf, size_t size);
  125. # endif
  126. #elif defined GNULIB_POSIXCHECK
  127. # undef getcwd
  128. # define getcwd(b,s) \
  129. (GL_LINK_WARNING ("getcwd is unportable - " \
  130. "use gnulib module getcwd for portability"), \
  131. getcwd (b, s))
  132. #endif
  133. #if @GNULIB_GETLOGIN_R@
  134. /* Copies the user's login name to NAME.
  135. The array pointed to by NAME has room for SIZE bytes.
  136. Returns 0 if successful. Upon error, an error number is returned, or -1 in
  137. the case that the login name cannot be found but no specific error is
  138. provided (this case is hopefully rare but is left open by the POSIX spec).
  139. See <http://www.opengroup.org/susv3xsh/getlogin.html>.
  140. */
  141. # if !@HAVE_DECL_GETLOGIN_R@
  142. # include <stddef.h>
  143. extern int getlogin_r (char *name, size_t size);
  144. # endif
  145. #elif defined GNULIB_POSIXCHECK
  146. # undef getlogin_r
  147. # define getlogin_r(n,s) \
  148. (GL_LINK_WARNING ("getlogin_r is unportable - " \
  149. "use gnulib module getlogin_r for portability"), \
  150. getlogin_r (n, s))
  151. #endif
  152. #if @GNULIB_GETPAGESIZE@
  153. # if @REPLACE_GETPAGESIZE@
  154. # define getpagesize rpl_getpagesize
  155. extern int getpagesize (void);
  156. # elif !@HAVE_GETPAGESIZE@
  157. /* This is for POSIX systems. */
  158. # if !defined getpagesize && defined _SC_PAGESIZE
  159. # if ! (defined __VMS && __VMS_VER < 70000000)
  160. # define getpagesize() sysconf (_SC_PAGESIZE)
  161. # endif
  162. # endif
  163. /* This is for older VMS. */
  164. # if !defined getpagesize && defined __VMS
  165. # ifdef __ALPHA
  166. # define getpagesize() 8192
  167. # else
  168. # define getpagesize() 512
  169. # endif
  170. # endif
  171. /* This is for BeOS. */
  172. # if !defined getpagesize && @HAVE_OS_H@
  173. # include <OS.h>
  174. # if defined B_PAGE_SIZE
  175. # define getpagesize() B_PAGE_SIZE
  176. # endif
  177. # endif
  178. /* This is for AmigaOS4.0. */
  179. # if !defined getpagesize && defined __amigaos4__
  180. # define getpagesize() 2048
  181. # endif
  182. /* This is for older Unix systems. */
  183. # if !defined getpagesize && @HAVE_SYS_PARAM_H@
  184. # include <sys/param.h>
  185. # ifdef EXEC_PAGESIZE
  186. # define getpagesize() EXEC_PAGESIZE
  187. # else
  188. # ifdef NBPG
  189. # ifndef CLSIZE
  190. # define CLSIZE 1
  191. # endif
  192. # define getpagesize() (NBPG * CLSIZE)
  193. # else
  194. # ifdef NBPC
  195. # define getpagesize() NBPC
  196. # endif
  197. # endif
  198. # endif
  199. # endif
  200. # endif
  201. #elif defined GNULIB_POSIXCHECK
  202. # undef getpagesize
  203. # define getpagesize() \
  204. (GL_LINK_WARNING ("getpagesize is unportable - " \
  205. "use gnulib module getpagesize for portability"), \
  206. getpagesize ())
  207. #endif
  208. #if @GNULIB_LCHOWN@
  209. # if @REPLACE_LCHOWN@
  210. /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
  211. to GID (if GID is not -1). Do not follow symbolic links.
  212. Return 0 if successful, otherwise -1 and errno set.
  213. See the POSIX:2001 specification
  214. <http://www.opengroup.org/susv3xsh/lchown.html>. */
  215. # define lchown rpl_lchown
  216. extern int lchown (char const *file, uid_t owner, gid_t group);
  217. # endif
  218. #elif defined GNULIB_POSIXCHECK
  219. # undef lchown
  220. # define lchown(f,u,g) \
  221. (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
  222. "systems - use gnulib module lchown for portability"), \
  223. lchown (f, u, g))
  224. #endif
  225. #if @GNULIB_LSEEK@
  226. # if @REPLACE_LSEEK@
  227. /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
  228. Return the new offset if successful, otherwise -1 and errno set.
  229. See the POSIX:2001 specification
  230. <http://www.opengroup.org/susv3xsh/lseek.html>. */
  231. # define lseek rpl_lseek
  232. extern off_t lseek (int fd, off_t offset, int whence);
  233. # endif
  234. #elif defined GNULIB_POSIXCHECK
  235. # undef lseek
  236. # define lseek(f,o,w) \
  237. (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
  238. "systems - use gnulib module lseek for portability"), \
  239. lseek (f, o, w))
  240. #endif
  241. #if @GNULIB_READLINK@
  242. /* Read the contents of the symbolic link FILE and place the first BUFSIZE
  243. bytes of it into BUF. Return the number of bytes placed into BUF if
  244. successful, otherwise -1 and errno set.
  245. See the POSIX:2001 specification
  246. <http://www.opengroup.org/susv3xsh/readlink.html>. */
  247. # if !@HAVE_READLINK@
  248. # include <stddef.h>
  249. extern int readlink (const char *file, char *buf, size_t bufsize);
  250. # endif
  251. #elif defined GNULIB_POSIXCHECK
  252. # undef readlink
  253. # define readlink(f,b,s) \
  254. (GL_LINK_WARNING ("readlink is unportable - " \
  255. "use gnulib module readlink for portability"), \
  256. readlink (f, b, s))
  257. #endif
  258. #if @GNULIB_SLEEP@
  259. /* Pause the execution of the current thread for N seconds.
  260. Returns the number of seconds left to sleep.
  261. See the POSIX:2001 specification
  262. <http://www.opengroup.org/susv3xsh/sleep.html>. */
  263. # if !@HAVE_SLEEP@
  264. extern unsigned int sleep (unsigned int n);
  265. # endif
  266. #elif defined GNULIB_POSIXCHECK
  267. # undef sleep
  268. # define sleep(n) \
  269. (GL_LINK_WARNING ("sleep is unportable - " \
  270. "use gnulib module sleep for portability"), \
  271. sleep (n))
  272. #endif
  273. #ifdef __cplusplus
  274. }
  275. #endif
  276. #endif /* _GL_UNISTD_H */
  277. #endif /* _GL_UNISTD_H */