1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Substitute for and wrapper around <unistd.h>.
4 Copyright (C) 2003-2009 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
23 @PRAGMA_SYSTEM_HEADER@
26 /* The include_next requires a split double-inclusion guard. */
28 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
34 /* NetBSD 5.0 mis-defines NULL. Also get size_t. */
37 /* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */
38 #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
42 /* mingw fails to declare _exit in <unistd.h>. */
43 /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */
46 #if ((@GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@) \
47 || (@GNULIB_READLINK@ && (!@HAVE_READLINK@ || @REPLACE_READLINK@)) \
48 || (@GNULIB_READLINKAT@ && !@HAVE_READLINKAT@))
50 # include <sys/types.h>
53 /* Get getopt(), optarg, optind, opterr, optopt. */
54 #if @GNULIB_UNISTD_H_GETOPT@ && !defined _GL_SYSTEM_GETOPT
58 #if @GNULIB_GETHOSTNAME@
59 /* Get all possible declarations of gethostname(). */
60 # if @UNISTD_H_HAVE_WINSOCK2_H@
61 # include <winsock2.h>
62 # if !defined _GL_SYS_SOCKET_H
64 # define socket socket_used_without_including_sys_socket_h
66 # define connect connect_used_without_including_sys_socket_h
68 # define accept accept_used_without_including_sys_socket_h
70 # define bind bind_used_without_including_sys_socket_h
72 # define getpeername getpeername_used_without_including_sys_socket_h
74 # define getsockname getsockname_used_without_including_sys_socket_h
76 # define getsockopt getsockopt_used_without_including_sys_socket_h
78 # define listen listen_used_without_including_sys_socket_h
80 # define recv recv_used_without_including_sys_socket_h
82 # define send send_used_without_including_sys_socket_h
84 # define recvfrom recvfrom_used_without_including_sys_socket_h
86 # define sendto sendto_used_without_including_sys_socket_h
88 # define setsockopt setsockopt_used_without_including_sys_socket_h
90 # define shutdown shutdown_used_without_including_sys_socket_h
92 # if !defined _GL_SYS_SELECT_H
94 # define select select_used_without_including_sys_select_h
99 /* The definition of GL_LINK_WARNING is copied here. */
102 /* OS/2 EMX lacks these macros. */
104 # define STDIN_FILENO 0
106 #ifndef STDOUT_FILENO
107 # define STDOUT_FILENO 1
109 #ifndef STDERR_FILENO
110 # define STDERR_FILENO 2
113 /* Ensure *_OK macros exist. */
122 /* Declare overridden functions. */
131 # ifndef REPLACE_CHOWN
132 # define REPLACE_CHOWN 1
135 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
136 to GID (if GID is not -1). Follow symbolic links.
137 Return 0 if successful, otherwise -1 and errno set.
138 See the POSIX:2001 specification
139 <http://www.opengroup.org/susv3xsh/chown.html>. */
140 # define chown rpl_chown
141 extern int chown (const char *file, uid_t uid, gid_t gid);
144 #elif defined GNULIB_POSIXCHECK
146 # define chown(f,u,g) \
147 (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
148 "doesn't treat a uid or gid of -1 on some systems - " \
149 "use gnulib module chown for portability"), \
156 /* Automatically included by modules that need a replacement for close. */
158 # define close rpl_close
159 extern int close (int);
161 #elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
163 # define close close_used_without_requesting_gnulib_module_close
164 #elif defined GNULIB_POSIXCHECK
167 (GL_LINK_WARNING ("close does not portably work on sockets - " \
168 "use gnulib module close for portability"), \
175 extern int dup (int);
181 # define dup2 rpl_dup2
183 # if !@HAVE_DUP2@ || @REPLACE_DUP2@
184 /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
185 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
186 Return newfd if successful, otherwise -1 and errno set.
187 See the POSIX:2001 specification
188 <http://www.opengroup.org/susv3xsh/dup2.html>. */
189 extern int dup2 (int oldfd, int newfd);
191 #elif defined GNULIB_POSIXCHECK
194 (GL_LINK_WARNING ("dup2 is unportable - " \
195 "use gnulib module dup2 for portability"), \
201 /* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
203 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
204 and O_TEXT, O_BINARY (defined in "binary-io.h").
205 Close NEWFD first if it is open.
206 Return newfd if successful, otherwise -1 and errno set.
207 See the Linux man page at
208 <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */
210 # define dup3 rpl_dup3
212 extern int dup3 (int oldfd, int newfd, int flags);
213 #elif defined GNULIB_POSIXCHECK
215 # define dup3(o,n,f) \
216 (GL_LINK_WARNING ("dup3 is unportable - " \
217 "use gnulib module dup3 for portability"), \
223 # if !@HAVE_DECL_ENVIRON@
224 /* Set of environment variables and values. An array of strings of the form
225 "VARIABLE=VALUE", terminated with a NULL. */
226 # if defined __APPLE__ && defined __MACH__
227 # include <crt_externs.h>
228 # define environ (*_NSGetEnviron ())
230 extern char **environ;
233 #elif defined GNULIB_POSIXCHECK
236 (GL_LINK_WARNING ("environ is unportable - " \
237 "use gnulib module environ for portability"), \
242 #if @GNULIB_EUIDACCESS@
243 # if !@HAVE_EUIDACCESS@
244 /* Like access(), except that it uses the effective user id and group id of
245 the current process. */
246 extern int euidaccess (const char *filename, int mode);
248 #elif defined GNULIB_POSIXCHECK
250 # define euidaccess(f,m) \
251 (GL_LINK_WARNING ("euidaccess is unportable - " \
252 "use gnulib module euidaccess for portability"), \
257 #if @GNULIB_FACCESSAT@
258 # if !@HAVE_FACCESSAT@
259 int faccessat (int fd, char const *file, int mode, int flag);
261 #elif defined GNULIB_POSIXCHECK
263 # define faccessat(d,n,m,f) \
264 (GL_LINK_WARNING ("faccessat is not portable - " \
265 "use gnulib module faccessat for portability"), \
266 faccessat (d, n, m, f))
271 # if @REPLACE_FCHDIR@
272 /* Change the process' current working directory to the directory on which
273 the given file descriptor is open.
274 Return 0 if successful, otherwise -1 and errno set.
275 See the POSIX:2001 specification
276 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
277 extern int fchdir (int /*fd*/);
279 /* Gnulib internal hooks needed to maintain the fchdir metadata. */
280 extern int _gl_register_fd (int fd, const char *filename);
281 extern void _gl_unregister_fd (int fd);
282 extern int _gl_register_dup (int oldfd, int newfd);
283 extern const char *_gl_directory_name (int fd);
286 #elif defined GNULIB_POSIXCHECK
289 (GL_LINK_WARNING ("fchdir is unportable - " \
290 "use gnulib module fchdir for portability"), \
295 #if @GNULIB_FCHOWNAT@
296 # if @REPLACE_FCHOWNAT@
298 # define fchownat rpl_fchownat
300 # if !@HAVE_FCHOWNAT@ || @REPLACE_FCHOWNAT@
301 extern int fchownat (int fd, char const *file, uid_t owner, gid_t group, int flag);
303 #elif defined GNULIB_POSIXCHECK
305 # define fchownat(d,n,o,g,f) \
306 (GL_LINK_WARNING ("fchownat is not portable - " \
307 "use gnulib module openat for portability"), \
308 fchownat (d, n, o, g, f))
313 /* Synchronize changes to a file.
314 Return 0 if successful, otherwise -1 and errno set.
315 See POSIX:2001 specification
316 <http://www.opengroup.org/susv3xsh/fsync.html>. */
318 extern int fsync (int fd);
320 #elif defined GNULIB_POSIXCHECK
323 (GL_LINK_WARNING ("fsync is unportable - " \
324 "use gnulib module fsync for portability"), \
329 #if @GNULIB_FTRUNCATE@
330 # if !@HAVE_FTRUNCATE@
331 /* Change the size of the file to which FD is opened to become equal to LENGTH.
332 Return 0 if successful, otherwise -1 and errno set.
333 See the POSIX:2001 specification
334 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
335 extern int ftruncate (int fd, off_t length);
337 #elif defined GNULIB_POSIXCHECK
339 # define ftruncate(f,l) \
340 (GL_LINK_WARNING ("ftruncate is unportable - " \
341 "use gnulib module ftruncate for portability"), \
347 /* Include the headers that might declare getcwd so that they will not
348 cause confusion if included after this file. */
350 # if @REPLACE_GETCWD@
351 /* Get the name of the current working directory, and put it in SIZE bytes
353 Return BUF if successful, or NULL if the directory couldn't be determined
354 or SIZE was too small.
355 See the POSIX:2001 specification
356 <http://www.opengroup.org/susv3xsh/getcwd.html>.
357 Additionally, the gnulib module 'getcwd' guarantees the following GNU
358 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
359 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
361 # define getcwd rpl_getcwd
362 extern char * getcwd (char *buf, size_t size);
364 #elif defined GNULIB_POSIXCHECK
366 # define getcwd(b,s) \
367 (GL_LINK_WARNING ("getcwd is unportable - " \
368 "use gnulib module getcwd for portability"), \
373 #if @GNULIB_GETDOMAINNAME@
374 /* Return the NIS domain name of the machine.
375 WARNING! The NIS domain name is unrelated to the fully qualified host name
376 of the machine. It is also unrelated to email addresses.
377 WARNING! The NIS domain name is usually the empty string or "(none)" when
380 Put up to LEN bytes of the NIS domain name into NAME.
381 Null terminate it if the name is shorter than LEN.
382 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
383 Return 0 if successful, otherwise set errno and return -1. */
384 # if !@HAVE_GETDOMAINNAME@
385 extern int getdomainname(char *name, size_t len);
387 #elif defined GNULIB_POSIXCHECK
388 # undef getdomainname
389 # define getdomainname(n,l) \
390 (GL_LINK_WARNING ("getdomainname is unportable - " \
391 "use gnulib module getdomainname for portability"), \
392 getdomainname (n, l))
396 #if @GNULIB_GETDTABLESIZE@
397 # if !@HAVE_GETDTABLESIZE@
398 /* Return the maximum number of file descriptors in the current process.
399 In POSIX, this is same as sysconf (_SC_OPEN_MAX). */
400 extern int getdtablesize (void);
402 #elif defined GNULIB_POSIXCHECK
403 # undef getdtablesize
404 # define getdtablesize() \
405 (GL_LINK_WARNING ("getdtablesize is unportable - " \
406 "use gnulib module getdtablesize for portability"), \
411 #if @GNULIB_GETHOSTNAME@
412 /* Return the standard host name of the machine.
413 WARNING! The host name may or may not be fully qualified.
415 Put up to LEN bytes of the host name into NAME.
416 Null terminate it if the name is shorter than LEN.
417 If the host name is longer than LEN, set errno = EINVAL and return -1.
418 Return 0 if successful, otherwise set errno and return -1. */
419 # if @UNISTD_H_HAVE_WINSOCK2_H@
421 # define gethostname rpl_gethostname
423 # if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@
424 extern int gethostname(char *name, size_t len);
426 #elif @UNISTD_H_HAVE_WINSOCK2_H@
428 # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
429 #elif defined GNULIB_POSIXCHECK
431 # define gethostname(n,l) \
432 (GL_LINK_WARNING ("gethostname is unportable - " \
433 "use gnulib module gethostname for portability"), \
438 #if @GNULIB_GETLOGIN_R@
439 /* Copies the user's login name to NAME.
440 The array pointed to by NAME has room for SIZE bytes.
442 Returns 0 if successful. Upon error, an error number is returned, or -1 in
443 the case that the login name cannot be found but no specific error is
444 provided (this case is hopefully rare but is left open by the POSIX spec).
446 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
448 # if !@HAVE_DECL_GETLOGIN_R@
449 extern int getlogin_r (char *name, size_t size);
451 #elif defined GNULIB_POSIXCHECK
453 # define getlogin_r(n,s) \
454 (GL_LINK_WARNING ("getlogin_r is unportable - " \
455 "use gnulib module getlogin_r for portability"), \
460 #if @GNULIB_GETPAGESIZE@
461 # if @REPLACE_GETPAGESIZE@
462 # define getpagesize rpl_getpagesize
463 extern int getpagesize (void);
464 # elif !@HAVE_GETPAGESIZE@
465 /* This is for POSIX systems. */
466 # if !defined getpagesize && defined _SC_PAGESIZE
467 # if ! (defined __VMS && __VMS_VER < 70000000)
468 # define getpagesize() sysconf (_SC_PAGESIZE)
471 /* This is for older VMS. */
472 # if !defined getpagesize && defined __VMS
474 # define getpagesize() 8192
476 # define getpagesize() 512
479 /* This is for BeOS. */
480 # if !defined getpagesize && @HAVE_OS_H@
482 # if defined B_PAGE_SIZE
483 # define getpagesize() B_PAGE_SIZE
486 /* This is for AmigaOS4.0. */
487 # if !defined getpagesize && defined __amigaos4__
488 # define getpagesize() 2048
490 /* This is for older Unix systems. */
491 # if !defined getpagesize && @HAVE_SYS_PARAM_H@
492 # include <sys/param.h>
493 # ifdef EXEC_PAGESIZE
494 # define getpagesize() EXEC_PAGESIZE
500 # define getpagesize() (NBPG * CLSIZE)
503 # define getpagesize() NBPC
509 #elif defined GNULIB_POSIXCHECK
511 # define getpagesize() \
512 (GL_LINK_WARNING ("getpagesize is unportable - " \
513 "use gnulib module getpagesize for portability"), \
518 #if @GNULIB_GETUSERSHELL@
519 # if !@HAVE_GETUSERSHELL@
520 /* Return the next valid login shell on the system, or NULL when the end of
521 the list has been reached. */
522 extern char *getusershell (void);
523 /* Rewind to pointer that is advanced at each getusershell() call. */
524 extern void setusershell (void);
525 /* Free the pointer that is advanced at each getusershell() call and
526 associated resources. */
527 extern void endusershell (void);
529 #elif defined GNULIB_POSIXCHECK
531 # define getusershell() \
532 (GL_LINK_WARNING ("getusershell is unportable - " \
533 "use gnulib module getusershell for portability"), \
536 # define setusershell() \
537 (GL_LINK_WARNING ("setusershell is unportable - " \
538 "use gnulib module getusershell for portability"), \
541 # define endusershell() \
542 (GL_LINK_WARNING ("endusershell is unportable - " \
543 "use gnulib module getusershell for portability"), \
549 # if @REPLACE_LCHOWN@
550 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
551 to GID (if GID is not -1). Do not follow symbolic links.
552 Return 0 if successful, otherwise -1 and errno set.
553 See the POSIX:2001 specification
554 <http://www.opengroup.org/susv3xsh/lchown.html>. */
555 # define lchown rpl_lchown
556 extern int lchown (char const *file, uid_t owner, gid_t group);
558 #elif defined GNULIB_POSIXCHECK
560 # define lchown(f,u,g) \
561 (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
562 "systems - use gnulib module lchown for portability"), \
569 # define link rpl_link
571 /* Create a new hard link for an existing file.
572 Return 0 if successful, otherwise -1 and errno set.
573 See POSIX:2001 specification
574 <http://www.opengroup.org/susv3xsh/link.html>. */
575 # if !@HAVE_LINK@ || @REPLACE_LINK@
576 extern int link (const char *path1, const char *path2);
578 #elif defined GNULIB_POSIXCHECK
580 # define link(path1,path2) \
581 (GL_LINK_WARNING ("link is unportable - " \
582 "use gnulib module link for portability"), \
587 # if @REPLACE_LINKAT@
589 # define linkat rpl_linkat
591 /* Create a new hard link for an existing file, relative to two
592 directories. FLAG controls whether symlinks are followed.
593 Return 0 if successful, otherwise -1 and errno set. */
594 # if !@HAVE_LINKAT@ || @REPLACE_LINKAT@
595 extern int linkat (int fd1, const char *path1, int fd2, const char *path2,
598 #elif defined GNULIB_POSIXCHECK
600 # define link(f1,path1,f2,path2,f) \
601 (GL_LINK_WARNING ("linkat is unportable - " \
602 "use gnulib module linkat for portability"), \
603 linkat (f1, path1, f2, path2,f))
608 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
609 Return the new offset if successful, otherwise -1 and errno set.
610 See the POSIX:2001 specification
611 <http://www.opengroup.org/susv3xsh/lseek.html>. */
612 # define lseek rpl_lseek
613 extern off_t lseek (int fd, off_t offset, int whence);
615 #elif defined GNULIB_POSIXCHECK
617 # define lseek(f,o,w) \
618 (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
619 "systems - use gnulib module lseek for portability"), \
625 /* Create a pipe, applying the given flags when opening the read-end of the
626 pipe and the write-end of the pipe.
627 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
628 and O_TEXT, O_BINARY (defined in "binary-io.h").
629 Store the read-end as fd[0] and the write-end as fd[1].
630 Return 0 upon success, or -1 with errno set upon failure.
631 See also the Linux man page at
632 <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */
634 # define pipe2 rpl_pipe2
636 extern int pipe2 (int fd[2], int flags);
637 #elif defined GNULIB_POSIXCHECK
639 # define pipe2(f,o) \
640 (GL_LINK_WARNING ("pipe2 is unportable - " \
641 "use gnulib module pipe2 for portability"), \
646 #if @GNULIB_READLINK@
647 # if @REPLACE_READLINK@
648 # define readlink rpl_readlink
650 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
651 bytes of it into BUF. Return the number of bytes placed into BUF if
652 successful, otherwise -1 and errno set.
653 See the POSIX:2001 specification
654 <http://www.opengroup.org/susv3xsh/readlink.html>. */
655 # if !@HAVE_READLINK@ || @REPLACE_READLINK@
656 extern ssize_t readlink (const char *file, char *buf, size_t bufsize);
658 #elif defined GNULIB_POSIXCHECK
660 # define readlink(f,b,s) \
661 (GL_LINK_WARNING ("readlink is unportable - " \
662 "use gnulib module readlink for portability"), \
667 #if @GNULIB_READLINKAT@
668 # if !@HAVE_READLINKAT@
669 ssize_t readlinkat (int fd, char const *file, char *buf, size_t len);
671 #elif defined GNULIB_POSIXCHECK
673 # define readlinkat(d,n,b,l) \
674 (GL_LINK_WARNING ("readlinkat is not portable - " \
675 "use gnulib module symlinkat for portability"), \
676 readlinkat (d, n, b, l))
682 # define rmdir rpl_rmdir
683 /* Remove the directory DIR. */
684 extern int rmdir (char const *name);
686 #elif defined GNULIB_POSIXCHECK
689 (GL_LINK_WARNING ("rmdir is unportable - " \
690 "use gnulib module rmdir for portability"), \
696 /* Pause the execution of the current thread for N seconds.
697 Returns the number of seconds left to sleep.
698 See the POSIX:2001 specification
699 <http://www.opengroup.org/susv3xsh/sleep.html>. */
701 extern unsigned int sleep (unsigned int n);
703 #elif defined GNULIB_POSIXCHECK
706 (GL_LINK_WARNING ("sleep is unportable - " \
707 "use gnulib module sleep for portability"), \
713 # if @REPLACE_SYMLINK@
715 # define symlink rpl_symlink
717 # if !@HAVE_SYMLINK@ || @REPLACE_SYMLINK@
718 int symlink (char const *contents, char const *file);
720 #elif defined GNULIB_POSIXCHECK
722 # define symlink(c,n) \
723 (GL_LINK_WARNING ("symlink is not portable - " \
724 "use gnulib module symlink for portability"), \
729 #if @GNULIB_SYMLINKAT@
730 # if !@HAVE_SYMLINKAT@
731 int symlinkat (char const *contents, int fd, char const *file);
733 #elif defined GNULIB_POSIXCHECK
735 # define symlinkat(c,d,n) \
736 (GL_LINK_WARNING ("symlinkat is not portable - " \
737 "use gnulib module symlinkat for portability"), \
743 # if @REPLACE_UNLINK@
745 # define unlink rpl_unlink
746 extern int unlink (char const *file);
748 #elif defined GNULIB_POSIXCHECK
751 (GL_LINK_WARNING ("unlink is not portable - " \
752 "use gnulib module unlink for portability"), \
757 #if @GNULIB_UNLINKAT@
758 # if @REPLACE_UNLINKAT@
760 # define unlinkat rpl_unlinkat
762 # if !@HAVE_UNLINKAT@ || @REPLACE_UNLINKAT@
763 extern int unlinkat (int fd, char const *file, int flag);
765 #elif defined GNULIB_POSIXCHECK
767 # define unlinkat(d,n,f) \
768 (GL_LINK_WARNING ("unlinkat is not portable - " \
769 "use gnulib module openat for portability"), \
774 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
775 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
776 See the POSIX:2001 specification
777 <http://www.opengroup.org/susv3xsh/write.html>. */
779 # define write rpl_write
780 extern ssize_t write (int fd, const void *buf, size_t count);
789 #endif /* _GL_UNISTD_H */
790 #endif /* _GL_UNISTD_H */