unistd.in.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. /* Substitute for and wrapper around <unistd.h>.
  2. Copyright (C) 2003-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, 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. #if __GNUC__ >= 3
  16. @PRAGMA_SYSTEM_HEADER@
  17. #endif
  18. /* The include_next requires a split double-inclusion guard. */
  19. #if @HAVE_UNISTD_H@
  20. # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
  21. #endif
  22. #ifndef _GL_UNISTD_H
  23. #define _GL_UNISTD_H
  24. /* mingw doesn't define the SEEK_* macros in <unistd.h>. */
  25. #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
  26. # include <stdio.h>
  27. #endif
  28. /* mingw fails to declare _exit in <unistd.h>. */
  29. /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */
  30. #include <stdlib.h>
  31. #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
  32. /* Get ssize_t. */
  33. # include <sys/types.h>
  34. #endif
  35. #if @GNULIB_GETHOSTNAME@
  36. /* Get all possible declarations of gethostname(). */
  37. # if @UNISTD_H_HAVE_WINSOCK2_H@
  38. # include <winsock2.h>
  39. # if !defined _GL_SYS_SOCKET_H
  40. # undef socket
  41. # define socket socket_used_without_including_sys_socket_h
  42. # undef connect
  43. # define connect connect_used_without_including_sys_socket_h
  44. # undef accept
  45. # define accept accept_used_without_including_sys_socket_h
  46. # undef bind
  47. # define bind bind_used_without_including_sys_socket_h
  48. # undef getpeername
  49. # define getpeername getpeername_used_without_including_sys_socket_h
  50. # undef getsockname
  51. # define getsockname getsockname_used_without_including_sys_socket_h
  52. # undef getsockopt
  53. # define getsockopt getsockopt_used_without_including_sys_socket_h
  54. # undef listen
  55. # define listen listen_used_without_including_sys_socket_h
  56. # undef recv
  57. # define recv recv_used_without_including_sys_socket_h
  58. # undef send
  59. # define send send_used_without_including_sys_socket_h
  60. # undef recvfrom
  61. # define recvfrom recvfrom_used_without_including_sys_socket_h
  62. # undef sendto
  63. # define sendto sendto_used_without_including_sys_socket_h
  64. # undef setsockopt
  65. # define setsockopt setsockopt_used_without_including_sys_socket_h
  66. # undef shutdown
  67. # define shutdown shutdown_used_without_including_sys_socket_h
  68. # endif
  69. # if !defined _GL_SYS_SELECT_H
  70. # undef select
  71. # define select select_used_without_including_sys_select_h
  72. # endif
  73. # endif
  74. #endif
  75. /* The definition of GL_LINK_WARNING is copied here. */
  76. /* Declare overridden functions. */
  77. #ifdef __cplusplus
  78. extern "C" {
  79. #endif
  80. #if @GNULIB_CHOWN@
  81. # if @REPLACE_CHOWN@
  82. # ifndef REPLACE_CHOWN
  83. # define REPLACE_CHOWN 1
  84. # endif
  85. # if REPLACE_CHOWN
  86. /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
  87. to GID (if GID is not -1). Follow symbolic links.
  88. Return 0 if successful, otherwise -1 and errno set.
  89. See the POSIX:2001 specification
  90. <http://www.opengroup.org/susv3xsh/chown.html>. */
  91. # define chown rpl_chown
  92. extern int chown (const char *file, uid_t uid, gid_t gid);
  93. # endif
  94. # endif
  95. #elif defined GNULIB_POSIXCHECK
  96. # undef chown
  97. # define chown(f,u,g) \
  98. (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
  99. "doesn't treat a uid or gid of -1 on some systems - " \
  100. "use gnulib module chown for portability"), \
  101. chown (f, u, g))
  102. #endif
  103. #if @GNULIB_CLOSE@
  104. # if @UNISTD_H_HAVE_WINSOCK2_H@
  105. /* Need a gnulib internal function. */
  106. # define HAVE__GL_CLOSE_FD_MAYBE_SOCKET 1
  107. # endif
  108. # if @REPLACE_CLOSE@
  109. /* Automatically included by modules that need a replacement for close. */
  110. # undef close
  111. # define close rpl_close
  112. extern int close (int);
  113. # endif
  114. #elif @UNISTD_H_HAVE_WINSOCK2_H@
  115. # undef close
  116. # define close close_used_without_requesting_gnulib_module_close
  117. #elif defined GNULIB_POSIXCHECK
  118. # undef close
  119. # define close(f) \
  120. (GL_LINK_WARNING ("close does not portably work on sockets - " \
  121. "use gnulib module close for portability"), \
  122. close (f))
  123. #endif
  124. #if @GNULIB_DUP2@
  125. # if !@HAVE_DUP2@
  126. /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
  127. NEWFD = OLDFD, otherwise close NEWFD first if it is open.
  128. Return 0 if successful, otherwise -1 and errno set.
  129. See the POSIX:2001 specification
  130. <http://www.opengroup.org/susv3xsh/dup2.html>. */
  131. extern int dup2 (int oldfd, int newfd);
  132. # endif
  133. #elif defined GNULIB_POSIXCHECK
  134. # undef dup2
  135. # define dup2(o,n) \
  136. (GL_LINK_WARNING ("dup2 is unportable - " \
  137. "use gnulib module dup2 for portability"), \
  138. dup2 (o, n))
  139. #endif
  140. #if @GNULIB_ENVIRON@
  141. # if !@HAVE_DECL_ENVIRON@
  142. /* Set of environment variables and values. An array of strings of the form
  143. "VARIABLE=VALUE", terminated with a NULL. */
  144. # if defined __APPLE__ && defined __MACH__
  145. # include <crt_externs.h>
  146. # define environ (*_NSGetEnviron ())
  147. # else
  148. extern char **environ;
  149. # endif
  150. # endif
  151. #elif defined GNULIB_POSIXCHECK
  152. # undef environ
  153. # define environ \
  154. (GL_LINK_WARNING ("environ is unportable - " \
  155. "use gnulib module environ for portability"), \
  156. environ)
  157. #endif
  158. #if @GNULIB_EUIDACCESS@
  159. # if !@HAVE_EUIDACCESS@
  160. /* Like access(), except that is uses the effective user id and group id of
  161. the current process. */
  162. extern int euidaccess (const char *filename, int mode);
  163. # endif
  164. #elif defined GNULIB_POSIXCHECK
  165. # undef euidaccess
  166. # define euidaccess(f,m) \
  167. (GL_LINK_WARNING ("euidaccess is unportable - " \
  168. "use gnulib module euidaccess for portability"), \
  169. euidaccess (f, m))
  170. #endif
  171. #if @GNULIB_FCHDIR@
  172. # if @REPLACE_FCHDIR@
  173. /* Change the process' current working directory to the directory on which
  174. the given file descriptor is open.
  175. Return 0 if successful, otherwise -1 and errno set.
  176. See the POSIX:2001 specification
  177. <http://www.opengroup.org/susv3xsh/fchdir.html>. */
  178. extern int fchdir (int /*fd*/);
  179. # define dup rpl_dup
  180. extern int dup (int);
  181. # define dup2 rpl_dup2
  182. extern int dup2 (int, int);
  183. # endif
  184. #elif defined GNULIB_POSIXCHECK
  185. # undef fchdir
  186. # define fchdir(f) \
  187. (GL_LINK_WARNING ("fchdir is unportable - " \
  188. "use gnulib module fchdir for portability"), \
  189. fchdir (f))
  190. #endif
  191. #if @GNULIB_FSYNC@
  192. /* Synchronize changes to a file.
  193. Return 0 if successful, otherwise -1 and errno set.
  194. See POSIX:2001 specification
  195. <http://www.opengroup.org/susv3xsh/fsync.html>. */
  196. # if !@HAVE_FSYNC@
  197. extern int fsync (int fd);
  198. # endif
  199. #elif defined GNULIB_POSIXCHECK
  200. # undef fsync
  201. # define fsync(fd) \
  202. (GL_LINK_WARNING ("fsync is unportable - " \
  203. "use gnulib module fsync for portability"), \
  204. fsync (fd))
  205. #endif
  206. #if @GNULIB_FTRUNCATE@
  207. # if !@HAVE_FTRUNCATE@
  208. /* Change the size of the file to which FD is opened to become equal to LENGTH.
  209. Return 0 if successful, otherwise -1 and errno set.
  210. See the POSIX:2001 specification
  211. <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
  212. extern int ftruncate (int fd, off_t length);
  213. # endif
  214. #elif defined GNULIB_POSIXCHECK
  215. # undef ftruncate
  216. # define ftruncate(f,l) \
  217. (GL_LINK_WARNING ("ftruncate is unportable - " \
  218. "use gnulib module ftruncate for portability"), \
  219. ftruncate (f, l))
  220. #endif
  221. #if @GNULIB_GETCWD@
  222. /* Include the headers that might declare getcwd so that they will not
  223. cause confusion if included after this file. */
  224. # include <stdlib.h>
  225. # if @REPLACE_GETCWD@
  226. /* Get the name of the current working directory, and put it in SIZE bytes
  227. of BUF.
  228. Return BUF if successful, or NULL if the directory couldn't be determined
  229. or SIZE was too small.
  230. See the POSIX:2001 specification
  231. <http://www.opengroup.org/susv3xsh/getcwd.html>.
  232. Additionally, the gnulib module 'getcwd' guarantees the following GNU
  233. extension: If BUF is NULL, an array is allocated with 'malloc'; the array
  234. is SIZE bytes long, unless SIZE == 0, in which case it is as big as
  235. necessary. */
  236. # define getcwd rpl_getcwd
  237. extern char * getcwd (char *buf, size_t size);
  238. # endif
  239. #elif defined GNULIB_POSIXCHECK
  240. # undef getcwd
  241. # define getcwd(b,s) \
  242. (GL_LINK_WARNING ("getcwd is unportable - " \
  243. "use gnulib module getcwd for portability"), \
  244. getcwd (b, s))
  245. #endif
  246. #if @GNULIB_GETDOMAINNAME@
  247. /* Return the NIS domain name of the machine.
  248. WARNING! The NIS domain name is unrelated to the fully qualified host name
  249. of the machine. It is also unrelated to email addresses.
  250. WARNING! The NIS domain name is usually the empty string or "(none)" when
  251. not using NIS.
  252. Put up to LEN bytes of the NIS domain name into NAME.
  253. Null terminate it if the name is shorter than LEN.
  254. If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
  255. Return 0 if successful, otherwise set errno and return -1. */
  256. # if !@HAVE_GETDOMAINNAME@
  257. extern int getdomainname(char *name, size_t len);
  258. # endif
  259. #elif defined GNULIB_POSIXCHECK
  260. # undef getdomainname
  261. # define getdomainname(n,l) \
  262. (GL_LINK_WARNING ("getdomainname is unportable - " \
  263. "use gnulib module getdomainname for portability"), \
  264. getdomainname (n, l))
  265. #endif
  266. #if @GNULIB_GETDTABLESIZE@
  267. # if !@HAVE_GETDTABLESIZE@
  268. /* Return the maximum number of file descriptors in the current process. */
  269. extern int getdtablesize (void);
  270. # endif
  271. #elif defined GNULIB_POSIXCHECK
  272. # undef getdtablesize
  273. # define getdtablesize() \
  274. (GL_LINK_WARNING ("getdtablesize is unportable - " \
  275. "use gnulib module getdtablesize for portability"), \
  276. getdtablesize ())
  277. #endif
  278. #if @GNULIB_GETHOSTNAME@
  279. /* Return the standard host name of the machine.
  280. WARNING! The host name may or may not be fully qualified.
  281. Put up to LEN bytes of the host name into NAME.
  282. Null terminate it if the name is shorter than LEN.
  283. If the host name is longer than LEN, set errno = EINVAL and return -1.
  284. Return 0 if successful, otherwise set errno and return -1. */
  285. # if @UNISTD_H_HAVE_WINSOCK2_H@
  286. # undef gethostname
  287. # define gethostname rpl_gethostname
  288. # endif
  289. # if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@
  290. extern int gethostname(char *name, size_t len);
  291. # endif
  292. #elif @UNISTD_H_HAVE_WINSOCK2_H@
  293. # undef gethostname
  294. # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
  295. #elif defined GNULIB_POSIXCHECK
  296. # undef gethostname
  297. # define gethostname(n,l) \
  298. (GL_LINK_WARNING ("gethostname is unportable - " \
  299. "use gnulib module gethostname for portability"), \
  300. gethostname (n, l))
  301. #endif
  302. #if @GNULIB_GETLOGIN_R@
  303. /* Copies the user's login name to NAME.
  304. The array pointed to by NAME has room for SIZE bytes.
  305. Returns 0 if successful. Upon error, an error number is returned, or -1 in
  306. the case that the login name cannot be found but no specific error is
  307. provided (this case is hopefully rare but is left open by the POSIX spec).
  308. See <http://www.opengroup.org/susv3xsh/getlogin.html>.
  309. */
  310. # if !@HAVE_DECL_GETLOGIN_R@
  311. # include <stddef.h>
  312. extern int getlogin_r (char *name, size_t size);
  313. # endif
  314. #elif defined GNULIB_POSIXCHECK
  315. # undef getlogin_r
  316. # define getlogin_r(n,s) \
  317. (GL_LINK_WARNING ("getlogin_r is unportable - " \
  318. "use gnulib module getlogin_r for portability"), \
  319. getlogin_r (n, s))
  320. #endif
  321. #if @GNULIB_GETPAGESIZE@
  322. # if @REPLACE_GETPAGESIZE@
  323. # define getpagesize rpl_getpagesize
  324. extern int getpagesize (void);
  325. # elif !@HAVE_GETPAGESIZE@
  326. /* This is for POSIX systems. */
  327. # if !defined getpagesize && defined _SC_PAGESIZE
  328. # if ! (defined __VMS && __VMS_VER < 70000000)
  329. # define getpagesize() sysconf (_SC_PAGESIZE)
  330. # endif
  331. # endif
  332. /* This is for older VMS. */
  333. # if !defined getpagesize && defined __VMS
  334. # ifdef __ALPHA
  335. # define getpagesize() 8192
  336. # else
  337. # define getpagesize() 512
  338. # endif
  339. # endif
  340. /* This is for BeOS. */
  341. # if !defined getpagesize && @HAVE_OS_H@
  342. # include <OS.h>
  343. # if defined B_PAGE_SIZE
  344. # define getpagesize() B_PAGE_SIZE
  345. # endif
  346. # endif
  347. /* This is for AmigaOS4.0. */
  348. # if !defined getpagesize && defined __amigaos4__
  349. # define getpagesize() 2048
  350. # endif
  351. /* This is for older Unix systems. */
  352. # if !defined getpagesize && @HAVE_SYS_PARAM_H@
  353. # include <sys/param.h>
  354. # ifdef EXEC_PAGESIZE
  355. # define getpagesize() EXEC_PAGESIZE
  356. # else
  357. # ifdef NBPG
  358. # ifndef CLSIZE
  359. # define CLSIZE 1
  360. # endif
  361. # define getpagesize() (NBPG * CLSIZE)
  362. # else
  363. # ifdef NBPC
  364. # define getpagesize() NBPC
  365. # endif
  366. # endif
  367. # endif
  368. # endif
  369. # endif
  370. #elif defined GNULIB_POSIXCHECK
  371. # undef getpagesize
  372. # define getpagesize() \
  373. (GL_LINK_WARNING ("getpagesize is unportable - " \
  374. "use gnulib module getpagesize for portability"), \
  375. getpagesize ())
  376. #endif
  377. #if @GNULIB_GETUSERSHELL@
  378. # if !@HAVE_GETUSERSHELL@
  379. /* Return the next valid login shell on the system, or NULL when the end of
  380. the list has been reached. */
  381. extern char *getusershell (void);
  382. /* Rewind to pointer that is advanced at each getusershell() call. */
  383. extern void setusershell (void);
  384. /* Free the pointer that is advanced at each getusershell() call and
  385. associated resources. */
  386. extern void endusershell (void);
  387. # endif
  388. #elif defined GNULIB_POSIXCHECK
  389. # undef getusershell
  390. # define getusershell() \
  391. (GL_LINK_WARNING ("getusershell is unportable - " \
  392. "use gnulib module getusershell for portability"), \
  393. getusershell ())
  394. # undef setusershell
  395. # define setusershell() \
  396. (GL_LINK_WARNING ("setusershell is unportable - " \
  397. "use gnulib module getusershell for portability"), \
  398. setusershell ())
  399. # undef endusershell
  400. # define endusershell() \
  401. (GL_LINK_WARNING ("endusershell is unportable - " \
  402. "use gnulib module getusershell for portability"), \
  403. endusershell ())
  404. #endif
  405. #if @GNULIB_LCHOWN@
  406. # if @REPLACE_LCHOWN@
  407. /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
  408. to GID (if GID is not -1). Do not follow symbolic links.
  409. Return 0 if successful, otherwise -1 and errno set.
  410. See the POSIX:2001 specification
  411. <http://www.opengroup.org/susv3xsh/lchown.html>. */
  412. # define lchown rpl_lchown
  413. extern int lchown (char const *file, uid_t owner, gid_t group);
  414. # endif
  415. #elif defined GNULIB_POSIXCHECK
  416. # undef lchown
  417. # define lchown(f,u,g) \
  418. (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
  419. "systems - use gnulib module lchown for portability"), \
  420. lchown (f, u, g))
  421. #endif
  422. #if @GNULIB_LSEEK@
  423. # if @REPLACE_LSEEK@
  424. /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
  425. Return the new offset if successful, otherwise -1 and errno set.
  426. See the POSIX:2001 specification
  427. <http://www.opengroup.org/susv3xsh/lseek.html>. */
  428. # define lseek rpl_lseek
  429. extern off_t lseek (int fd, off_t offset, int whence);
  430. # endif
  431. #elif defined GNULIB_POSIXCHECK
  432. # undef lseek
  433. # define lseek(f,o,w) \
  434. (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
  435. "systems - use gnulib module lseek for portability"), \
  436. lseek (f, o, w))
  437. #endif
  438. #if @GNULIB_READLINK@
  439. /* Read the contents of the symbolic link FILE and place the first BUFSIZE
  440. bytes of it into BUF. Return the number of bytes placed into BUF if
  441. successful, otherwise -1 and errno set.
  442. See the POSIX:2001 specification
  443. <http://www.opengroup.org/susv3xsh/readlink.html>. */
  444. # if !@HAVE_READLINK@
  445. # include <stddef.h>
  446. extern int readlink (const char *file, char *buf, size_t bufsize);
  447. # endif
  448. #elif defined GNULIB_POSIXCHECK
  449. # undef readlink
  450. # define readlink(f,b,s) \
  451. (GL_LINK_WARNING ("readlink is unportable - " \
  452. "use gnulib module readlink for portability"), \
  453. readlink (f, b, s))
  454. #endif
  455. #if @GNULIB_SLEEP@
  456. /* Pause the execution of the current thread for N seconds.
  457. Returns the number of seconds left to sleep.
  458. See the POSIX:2001 specification
  459. <http://www.opengroup.org/susv3xsh/sleep.html>. */
  460. # if !@HAVE_SLEEP@
  461. extern unsigned int sleep (unsigned int n);
  462. # endif
  463. #elif defined GNULIB_POSIXCHECK
  464. # undef sleep
  465. # define sleep(n) \
  466. (GL_LINK_WARNING ("sleep is unportable - " \
  467. "use gnulib module sleep for portability"), \
  468. sleep (n))
  469. #endif
  470. #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
  471. /* Write up to COUNT bytes starting at BUF to file descriptor FD.
  472. See the POSIX:2001 specification
  473. <http://www.opengroup.org/susv3xsh/write.html>. */
  474. # undef write
  475. # define write rpl_write
  476. extern ssize_t write (int fd, const void *buf, size_t count);
  477. #endif
  478. #ifdef FCHDIR_REPLACEMENT
  479. /* gnulib internal function. */
  480. extern void _gl_unregister_fd (int fd);
  481. #endif
  482. #ifdef __cplusplus
  483. }
  484. #endif
  485. #endif /* _GL_UNISTD_H */
  486. #endif /* _GL_UNISTD_H */