1 /* Substitute for and wrapper around <unistd.h>.
2 Copyright (C) 2003-2010 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 /* Special invocation convention:
19 - On mingw, several headers, including <winsock2.h>, include <unistd.h>,
20 but we need to ensure that both the system <unistd.h> and <winsock2.h>
21 are completely included before we replace gethostname. */
22 #if @UNISTD_H_HAVE_WINSOCK2_H@ && !defined _GL_WINSOCK2_H_WITNESS \
23 && defined _WINSOCK2_H
24 /* <unistd.h> is being indirectly included for the first time from
25 <winsock2.h>; avoid declaring any overrides. */
27 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
29 # error unexpected; report this to bug-gnulib@gnu.org
31 # define _GL_WINSOCK2_H_WITNESS
33 /* Normal invocation. */
34 #elif !defined _GL_UNISTD_H
37 @PRAGMA_SYSTEM_HEADER@
40 /* The include_next requires a split double-inclusion guard. */
42 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
45 /* Get all possible declarations of gethostname(). */
46 #if @UNISTD_H_HAVE_WINSOCK2_H@ && !defined _GL_INCLUDING_WINSOCK2_H
47 # define _GL_INCLUDING_WINSOCK2_H
48 # include <winsock2.h>
49 # undef _GL_INCLUDING_WINSOCK2_H
52 #if !defined _GL_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H
55 /* NetBSD 5.0 mis-defines NULL. Also get size_t. */
58 /* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */
59 /* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>. */
60 /* But avoid namespace pollution on glibc systems. */
61 #if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
62 || (@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK)) \
63 && ! defined __GLIBC__
67 /* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>. */
68 /* But avoid namespace pollution on glibc systems. */
69 #if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__
73 /* mingw fails to declare _exit in <unistd.h>. */
74 /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */
75 /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */
76 /* But avoid namespace pollution on glibc systems. */
81 /* mingw declares getcwd in <io.h>, not in <unistd.h>. */
82 #if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \
83 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
87 #if (@GNULIB_WRITE@ || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \
88 || @GNULIB_PREAD@ || defined GNULIB_POSIXCHECK)
90 # include <sys/types.h>
93 /* Get getopt(), optarg, optind, opterr, optopt.
94 But avoid namespace pollution on glibc systems. */
95 #if @GNULIB_UNISTD_H_GETOPT@ && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT
99 #if @GNULIB_GETHOSTNAME@
100 /* Get all possible declarations of gethostname(). */
101 # if @UNISTD_H_HAVE_WINSOCK2_H@
102 # if !defined _GL_SYS_SOCKET_H
104 # define socket socket_used_without_including_sys_socket_h
106 # define connect connect_used_without_including_sys_socket_h
108 # define accept accept_used_without_including_sys_socket_h
110 # define bind bind_used_without_including_sys_socket_h
112 # define getpeername getpeername_used_without_including_sys_socket_h
114 # define getsockname getsockname_used_without_including_sys_socket_h
116 # define getsockopt getsockopt_used_without_including_sys_socket_h
118 # define listen listen_used_without_including_sys_socket_h
120 # define recv recv_used_without_including_sys_socket_h
122 # define send send_used_without_including_sys_socket_h
124 # define recvfrom recvfrom_used_without_including_sys_socket_h
126 # define sendto sendto_used_without_including_sys_socket_h
128 # define setsockopt setsockopt_used_without_including_sys_socket_h
130 # define shutdown shutdown_used_without_including_sys_socket_h
132 # if !defined _GL_SYS_SELECT_H
134 # define select select_used_without_including_sys_select_h
139 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
141 /* The definition of _GL_ARG_NONNULL is copied here. */
143 /* The definition of _GL_WARN_ON_USE is copied here. */
146 /* OS/2 EMX lacks these macros. */
148 # define STDIN_FILENO 0
150 #ifndef STDOUT_FILENO
151 # define STDOUT_FILENO 1
153 #ifndef STDERR_FILENO
154 # define STDERR_FILENO 2
157 /* Ensure *_OK macros exist. */
166 /* Declare overridden functions. */
169 #if defined GNULIB_POSIXCHECK
170 /* The access() function is a security risk. */
171 _GL_WARN_ON_USE (access, "the access function is a security risk - "
172 "use the gnulib module faccessat instead");
177 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
178 to GID (if GID is not -1). Follow symbolic links.
179 Return 0 if successful, otherwise -1 and errno set.
180 See the POSIX:2001 specification
181 <http://www.opengroup.org/susv3xsh/chown.html>. */
183 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
185 # define chown rpl_chown
187 _GL_FUNCDECL_RPL (chown, int, (const char *file, uid_t uid, gid_t gid)
188 _GL_ARG_NONNULL ((1)));
189 _GL_CXXALIAS_RPL (chown, int, (const char *file, uid_t uid, gid_t gid));
192 _GL_FUNCDECL_SYS (chown, int, (const char *file, uid_t uid, gid_t gid)
193 _GL_ARG_NONNULL ((1)));
195 _GL_CXXALIAS_SYS (chown, int, (const char *file, uid_t uid, gid_t gid));
197 _GL_CXXALIASWARN (chown);
198 #elif defined GNULIB_POSIXCHECK
200 # if HAVE_RAW_DECL_CHOWN
201 _GL_WARN_ON_USE (chown, "chown fails to follow symlinks on some systems and "
202 "doesn't treat a uid or gid of -1 on some systems - "
203 "use gnulib module chown for portability");
210 /* Automatically included by modules that need a replacement for close. */
211 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
213 # define close rpl_close
215 _GL_FUNCDECL_RPL (close, int, (int fd));
216 _GL_CXXALIAS_RPL (close, int, (int fd));
218 _GL_CXXALIAS_SYS (close, int, (int fd));
220 _GL_CXXALIASWARN (close);
221 #elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
223 # define close close_used_without_requesting_gnulib_module_close
224 #elif defined GNULIB_POSIXCHECK
226 /* Assume close is always declared. */
227 _GL_WARN_ON_USE (close, "close does not portably work on sockets - "
228 "use gnulib module close for portability");
233 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
236 _GL_FUNCDECL_RPL (dup, int, (int oldfd));
237 _GL_CXXALIAS_RPL (dup, int, (int oldfd));
239 _GL_CXXALIAS_SYS (dup, int, (int oldfd));
241 _GL_CXXALIASWARN (dup);
245 /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
246 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
247 Return newfd if successful, otherwise -1 and errno set.
248 See the POSIX:2001 specification
249 <http://www.opengroup.org/susv3xsh/dup2.html>. */
251 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
252 # define dup2 rpl_dup2
254 _GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd));
255 _GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd));
258 _GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd));
260 _GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
262 _GL_CXXALIASWARN (dup2);
263 #elif defined GNULIB_POSIXCHECK
265 # if HAVE_RAW_DECL_DUP2
266 _GL_WARN_ON_USE (dup2, "dup2 is unportable - "
267 "use gnulib module dup2 for portability");
273 /* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
275 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
276 and O_TEXT, O_BINARY (defined in "binary-io.h").
277 Close NEWFD first if it is open.
278 Return newfd if successful, otherwise -1 and errno set.
279 See the Linux man page at
280 <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */
282 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
283 # define dup3 rpl_dup3
285 _GL_FUNCDECL_RPL (dup3, int, (int oldfd, int newfd, int flags));
286 _GL_CXXALIAS_RPL (dup3, int, (int oldfd, int newfd, int flags));
288 _GL_FUNCDECL_SYS (dup3, int, (int oldfd, int newfd, int flags));
289 _GL_CXXALIAS_SYS (dup3, int, (int oldfd, int newfd, int flags));
291 _GL_CXXALIASWARN (dup3);
292 #elif defined GNULIB_POSIXCHECK
294 # if HAVE_RAW_DECL_DUP3
295 _GL_WARN_ON_USE (dup3, "dup3 is unportable - "
296 "use gnulib module dup3 for portability");
302 # if !@HAVE_DECL_ENVIRON@
303 /* Set of environment variables and values. An array of strings of the form
304 "VARIABLE=VALUE", terminated with a NULL. */
305 # if defined __APPLE__ && defined __MACH__
306 # include <crt_externs.h>
307 # define environ (*_NSGetEnviron ())
312 extern char **environ;
318 #elif defined GNULIB_POSIXCHECK
319 # if HAVE_RAW_DECL_ENVIRON
320 static inline char ***
325 _GL_WARN_ON_USE (rpl_environ, "environ is unportable - "
326 "use gnulib module environ for portability");
328 # define environ (*rpl_environ ())
333 #if @GNULIB_EUIDACCESS@
334 /* Like access(), except that it uses the effective user id and group id of
335 the current process. */
336 # if !@HAVE_EUIDACCESS@
337 _GL_FUNCDECL_SYS (euidaccess, int, (const char *filename, int mode)
338 _GL_ARG_NONNULL ((1)));
340 _GL_CXXALIAS_SYS (euidaccess, int, (const char *filename, int mode));
341 _GL_CXXALIASWARN (euidaccess);
342 # if defined GNULIB_POSIXCHECK
343 /* Like access(), this function is a security risk. */
344 _GL_WARN_ON_USE (euidaccess, "the euidaccess function is a security risk - "
345 "use the gnulib module faccessat instead");
347 #elif defined GNULIB_POSIXCHECK
349 # if HAVE_RAW_DECL_EUIDACCESS
350 _GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - "
351 "use gnulib module euidaccess for portability");
356 #if @GNULIB_FACCESSAT@
357 # if !@HAVE_FACCESSAT@
358 _GL_FUNCDECL_SYS (faccessat, int,
359 (int fd, char const *file, int mode, int flag)
360 _GL_ARG_NONNULL ((2)));
362 _GL_CXXALIAS_SYS (faccessat, int,
363 (int fd, char const *file, int mode, int flag));
364 _GL_CXXALIASWARN (faccessat);
365 #elif defined GNULIB_POSIXCHECK
367 # if HAVE_RAW_DECL_FACCESSAT
368 _GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
369 "use gnulib module faccessat for portability");
375 /* Change the process' current working directory to the directory on which
376 the given file descriptor is open.
377 Return 0 if successful, otherwise -1 and errno set.
378 See the POSIX:2001 specification
379 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
380 # if @REPLACE_FCHDIR@
381 _GL_FUNCDECL_RPL (fchdir, int, (int /*fd*/));
382 _GL_CXXALIAS_RPL (fchdir, int, (int /*fd*/));
384 /* Gnulib internal hooks needed to maintain the fchdir metadata. */
385 _GL_EXTERN_C int _gl_register_fd (int fd, const char *filename)
386 _GL_ARG_NONNULL ((2));
387 _GL_EXTERN_C void _gl_unregister_fd (int fd);
388 _GL_EXTERN_C int _gl_register_dup (int oldfd, int newfd);
389 _GL_EXTERN_C const char *_gl_directory_name (int fd);
392 _GL_CXXALIAS_SYS (fchdir, int, (int /*fd*/));
394 _GL_CXXALIASWARN (fchdir);
395 #elif defined GNULIB_POSIXCHECK
397 # if HAVE_RAW_DECL_FCHDIR
398 _GL_WARN_ON_USE (fchdir, "fchdir is unportable - "
399 "use gnulib module fchdir for portability");
404 #if @GNULIB_FCHOWNAT@
405 # if @REPLACE_FCHOWNAT@
406 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
408 # define fchownat rpl_fchownat
410 _GL_FUNCDECL_RPL (fchownat, int, (int fd, char const *file,
411 uid_t owner, gid_t group, int flag)
412 _GL_ARG_NONNULL ((2)));
413 _GL_CXXALIAS_RPL (fchownat, int, (int fd, char const *file,
414 uid_t owner, gid_t group, int flag));
416 # if !@HAVE_FCHOWNAT@
417 _GL_FUNCDECL_SYS (fchownat, int, (int fd, char const *file,
418 uid_t owner, gid_t group, int flag)
419 _GL_ARG_NONNULL ((2)));
421 _GL_CXXALIAS_SYS (fchownat, int, (int fd, char const *file,
422 uid_t owner, gid_t group, int flag));
424 _GL_CXXALIASWARN (fchownat);
425 #elif defined GNULIB_POSIXCHECK
427 # if HAVE_RAW_DECL_FCHOWNAT
428 _GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
429 "use gnulib module openat for portability");
435 /* Synchronize changes to a file.
436 Return 0 if successful, otherwise -1 and errno set.
437 See POSIX:2001 specification
438 <http://www.opengroup.org/susv3xsh/fsync.html>. */
440 _GL_FUNCDECL_SYS (fsync, int, (int fd));
442 _GL_CXXALIAS_SYS (fsync, int, (int fd));
443 _GL_CXXALIASWARN (fsync);
444 #elif defined GNULIB_POSIXCHECK
446 # if HAVE_RAW_DECL_FSYNC
447 _GL_WARN_ON_USE (fsync, "fsync is unportable - "
448 "use gnulib module fsync for portability");
453 #if @GNULIB_FTRUNCATE@
454 /* Change the size of the file to which FD is opened to become equal to LENGTH.
455 Return 0 if successful, otherwise -1 and errno set.
456 See the POSIX:2001 specification
457 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
458 # if !@HAVE_FTRUNCATE@
459 _GL_FUNCDECL_SYS (ftruncate, int, (int fd, off_t length));
461 _GL_CXXALIAS_SYS (ftruncate, int, (int fd, off_t length));
462 _GL_CXXALIASWARN (ftruncate);
463 #elif defined GNULIB_POSIXCHECK
465 # if HAVE_RAW_DECL_FTRUNCATE
466 _GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
467 "use gnulib module ftruncate for portability");
473 /* Get the name of the current working directory, and put it in SIZE bytes
475 Return BUF if successful, or NULL if the directory couldn't be determined
476 or SIZE was too small.
477 See the POSIX:2001 specification
478 <http://www.opengroup.org/susv3xsh/getcwd.html>.
479 Additionally, the gnulib module 'getcwd' guarantees the following GNU
480 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
481 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
483 # if @REPLACE_GETCWD@
484 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
485 # define getcwd rpl_getcwd
487 _GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size));
488 _GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size));
490 _GL_CXXALIAS_SYS (getcwd, char *, (char *buf, size_t size));
492 _GL_CXXALIASWARN (getcwd);
493 #elif defined GNULIB_POSIXCHECK
495 # if HAVE_RAW_DECL_GETCWD
496 _GL_WARN_ON_USE (getcwd, "getcwd is unportable - "
497 "use gnulib module getcwd for portability");
502 #if @GNULIB_GETDOMAINNAME@
503 /* Return the NIS domain name of the machine.
504 WARNING! The NIS domain name is unrelated to the fully qualified host name
505 of the machine. It is also unrelated to email addresses.
506 WARNING! The NIS domain name is usually the empty string or "(none)" when
509 Put up to LEN bytes of the NIS domain name into NAME.
510 Null terminate it if the name is shorter than LEN.
511 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
512 Return 0 if successful, otherwise set errno and return -1. */
513 # if !@HAVE_GETDOMAINNAME@
514 _GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len)
515 _GL_ARG_NONNULL ((1)));
517 /* Need to cast, because on MacOS X 10.5 systems, the second parameter is
519 _GL_CXXALIAS_SYS_CAST (getdomainname, int, (char *name, size_t len));
520 _GL_CXXALIASWARN (getdomainname);
521 #elif defined GNULIB_POSIXCHECK
522 # undef getdomainname
523 # if HAVE_RAW_DECL_GETDOMAINNAME
524 _GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - "
525 "use gnulib module getdomainname for portability");
530 #if @GNULIB_GETDTABLESIZE@
531 /* Return the maximum number of file descriptors in the current process.
532 In POSIX, this is same as sysconf (_SC_OPEN_MAX). */
533 # if !@HAVE_GETDTABLESIZE@
534 _GL_FUNCDECL_SYS (getdtablesize, int, (void));
536 _GL_CXXALIAS_SYS (getdtablesize, int, (void));
537 _GL_CXXALIASWARN (getdtablesize);
538 #elif defined GNULIB_POSIXCHECK
539 # undef getdtablesize
540 # if HAVE_RAW_DECL_GETDTABLESIZE
541 _GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - "
542 "use gnulib module getdtablesize for portability");
547 #if @GNULIB_GETGROUPS@
548 /* Return the supplemental groups that the current process belongs to.
549 It is unspecified whether the effective group id is in the list.
550 If N is 0, return the group count; otherwise, N describes how many
551 entries are available in GROUPS. Return -1 and set errno if N is
552 not 0 and not large enough. Fails with ENOSYS on some systems. */
553 # if @REPLACE_GETGROUPS@
554 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
556 # define getgroups rpl_getgroups
558 _GL_FUNCDECL_RPL (getgroups, int, (int n, gid_t *groups));
559 _GL_CXXALIAS_RPL (getgroups, int, (int n, gid_t *groups));
561 # if !@HAVE_GETGROUPS@
562 _GL_FUNCDECL_SYS (getgroups, int, (int n, gid_t *groups));
564 _GL_CXXALIAS_SYS (getgroups, int, (int n, gid_t *groups));
566 _GL_CXXALIASWARN (getgroups);
567 #elif defined GNULIB_POSIXCHECK
569 # if HAVE_RAW_DECL_GETGROUPS
570 _GL_WARN_ON_USE (getgroups, "getgroups is unportable - "
571 "use gnulib module getgroups for portability");
576 #if @GNULIB_GETHOSTNAME@
577 /* Return the standard host name of the machine.
578 WARNING! The host name may or may not be fully qualified.
580 Put up to LEN bytes of the host name into NAME.
581 Null terminate it if the name is shorter than LEN.
582 If the host name is longer than LEN, set errno = EINVAL and return -1.
583 Return 0 if successful, otherwise set errno and return -1. */
584 # if @UNISTD_H_HAVE_WINSOCK2_H@
585 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
587 # define gethostname rpl_gethostname
589 _GL_FUNCDECL_RPL (gethostname, int, (char *name, size_t len)
590 _GL_ARG_NONNULL ((1)));
591 _GL_CXXALIAS_RPL (gethostname, int, (char *name, size_t len));
593 # if !@HAVE_GETHOSTNAME@
594 _GL_FUNCDECL_SYS (gethostname, int, (char *name, size_t len)
595 _GL_ARG_NONNULL ((1)));
597 /* Need to cast, because on Solaris 10 systems, the second parameter is
599 _GL_CXXALIAS_SYS_CAST (gethostname, int, (char *name, size_t len));
601 _GL_CXXALIASWARN (gethostname);
602 #elif @UNISTD_H_HAVE_WINSOCK2_H@
604 # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
605 #elif defined GNULIB_POSIXCHECK
607 # if HAVE_RAW_DECL_GETHOSTNAME
608 _GL_WARN_ON_USE (gethostname, "gethostname is unportable - "
609 "use gnulib module gethostname for portability");
614 #if @GNULIB_GETLOGIN@
615 /* Returns the user's login name, or NULL if it cannot be found. Upon error,
616 returns NULL with errno set.
618 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
620 Most programs don't need to use this function, because the information is
621 available through environment variables:
622 ${LOGNAME-$USER} on Unix platforms,
623 $USERNAME on native Windows platforms.
625 # if !@HAVE_GETLOGIN@
626 _GL_FUNCDECL_SYS (getlogin, char *, (void));
628 _GL_CXXALIAS_SYS (getlogin, char *, (void));
629 _GL_CXXALIASWARN (getlogin);
630 #elif defined GNULIB_POSIXCHECK
632 # if HAVE_RAW_DECL_GETLOGIN
633 _GL_WARN_ON_USE (getlogin, "getlogin is unportable - "
634 "use gnulib module getlogin for portability");
639 #if @GNULIB_GETLOGIN_R@
640 /* Copies the user's login name to NAME.
641 The array pointed to by NAME has room for SIZE bytes.
643 Returns 0 if successful. Upon error, an error number is returned, or -1 in
644 the case that the login name cannot be found but no specific error is
645 provided (this case is hopefully rare but is left open by the POSIX spec).
647 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
649 Most programs don't need to use this function, because the information is
650 available through environment variables:
651 ${LOGNAME-$USER} on Unix platforms,
652 $USERNAME on native Windows platforms.
654 # if !@HAVE_DECL_GETLOGIN_R@
655 _GL_FUNCDECL_SYS (getlogin_r, int, (char *name, size_t size)
656 _GL_ARG_NONNULL ((1)));
658 /* Need to cast, because on Solaris 10 systems, the second argument is
660 _GL_CXXALIAS_SYS_CAST (getlogin_r, int, (char *name, size_t size));
661 _GL_CXXALIASWARN (getlogin_r);
662 #elif defined GNULIB_POSIXCHECK
664 # if HAVE_RAW_DECL_GETLOGIN_R
665 _GL_WARN_ON_USE (getlogin_r, "getlogin_r is unportable - "
666 "use gnulib module getlogin_r for portability");
671 #if @GNULIB_GETPAGESIZE@
672 # if @REPLACE_GETPAGESIZE@
673 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
674 # define getpagesize rpl_getpagesize
676 _GL_FUNCDECL_RPL (getpagesize, int, (void));
677 _GL_CXXALIAS_RPL (getpagesize, int, (void));
679 # if !@HAVE_GETPAGESIZE@
680 # if !defined getpagesize
681 /* This is for POSIX systems. */
682 # if !defined _gl_getpagesize && defined _SC_PAGESIZE
683 # if ! (defined __VMS && __VMS_VER < 70000000)
684 # define _gl_getpagesize() sysconf (_SC_PAGESIZE)
687 /* This is for older VMS. */
688 # if !defined _gl_getpagesize && defined __VMS
690 # define _gl_getpagesize() 8192
692 # define _gl_getpagesize() 512
695 /* This is for BeOS. */
696 # if !defined _gl_getpagesize && @HAVE_OS_H@
698 # if defined B_PAGE_SIZE
699 # define _gl_getpagesize() B_PAGE_SIZE
702 /* This is for AmigaOS4.0. */
703 # if !defined _gl_getpagesize && defined __amigaos4__
704 # define _gl_getpagesize() 2048
706 /* This is for older Unix systems. */
707 # if !defined _gl_getpagesize && @HAVE_SYS_PARAM_H@
708 # include <sys/param.h>
709 # ifdef EXEC_PAGESIZE
710 # define _gl_getpagesize() EXEC_PAGESIZE
716 # define _gl_getpagesize() (NBPG * CLSIZE)
719 # define _gl_getpagesize() NBPC
724 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
725 # define getpagesize() _gl_getpagesize ()
730 return _gl_getpagesize ();
735 /* Need to cast, because on Cygwin 1.5.x systems, the return type is size_t. */
736 _GL_CXXALIAS_SYS_CAST (getpagesize, int, (void));
738 _GL_CXXALIASWARN (getpagesize);
739 #elif defined GNULIB_POSIXCHECK
741 # if HAVE_RAW_DECL_GETPAGESIZE
742 _GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - "
743 "use gnulib module getpagesize for portability");
748 #if @GNULIB_GETUSERSHELL@
749 /* Return the next valid login shell on the system, or NULL when the end of
750 the list has been reached. */
751 # if !@HAVE_DECL_GETUSERSHELL@
752 _GL_FUNCDECL_SYS (getusershell, char *, (void));
754 _GL_CXXALIAS_SYS (getusershell, char *, (void));
755 _GL_CXXALIASWARN (getusershell);
756 #elif defined GNULIB_POSIXCHECK
758 # if HAVE_RAW_DECL_GETUSERSHELL
759 _GL_WARN_ON_USE (getusershell, "getusershell is unportable - "
760 "use gnulib module getusershell for portability");
764 #if @GNULIB_GETUSERSHELL@
765 /* Rewind to pointer that is advanced at each getusershell() call. */
766 # if !@HAVE_DECL_GETUSERSHELL@
767 _GL_FUNCDECL_SYS (setusershell, void, (void));
769 _GL_CXXALIAS_SYS (setusershell, void, (void));
770 _GL_CXXALIASWARN (setusershell);
771 #elif defined GNULIB_POSIXCHECK
773 # if HAVE_RAW_DECL_SETUSERSHELL
774 _GL_WARN_ON_USE (setusershell, "setusershell is unportable - "
775 "use gnulib module getusershell for portability");
779 #if @GNULIB_GETUSERSHELL@
780 /* Free the pointer that is advanced at each getusershell() call and
781 associated resources. */
782 # if !@HAVE_DECL_GETUSERSHELL@
783 _GL_FUNCDECL_SYS (endusershell, void, (void));
785 _GL_CXXALIAS_SYS (endusershell, void, (void));
786 _GL_CXXALIASWARN (endusershell);
787 #elif defined GNULIB_POSIXCHECK
789 # if HAVE_RAW_DECL_ENDUSERSHELL
790 _GL_WARN_ON_USE (endusershell, "endusershell is unportable - "
791 "use gnulib module getusershell for portability");
797 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
798 to GID (if GID is not -1). Do not follow symbolic links.
799 Return 0 if successful, otherwise -1 and errno set.
800 See the POSIX:2001 specification
801 <http://www.opengroup.org/susv3xsh/lchown.html>. */
802 # if @REPLACE_LCHOWN@
803 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
805 # define lchown rpl_lchown
807 _GL_FUNCDECL_RPL (lchown, int, (char const *file, uid_t owner, gid_t group)
808 _GL_ARG_NONNULL ((1)));
809 _GL_CXXALIAS_RPL (lchown, int, (char const *file, uid_t owner, gid_t group));
812 _GL_FUNCDECL_SYS (lchown, int, (char const *file, uid_t owner, gid_t group)
813 _GL_ARG_NONNULL ((1)));
815 _GL_CXXALIAS_SYS (lchown, int, (char const *file, uid_t owner, gid_t group));
817 _GL_CXXALIASWARN (lchown);
818 #elif defined GNULIB_POSIXCHECK
820 # if HAVE_RAW_DECL_LCHOWN
821 _GL_WARN_ON_USE (lchown, "lchown is unportable to pre-POSIX.1-2001 systems - "
822 "use gnulib module lchown for portability");
828 /* Create a new hard link for an existing file.
829 Return 0 if successful, otherwise -1 and errno set.
830 See POSIX:2001 specification
831 <http://www.opengroup.org/susv3xsh/link.html>. */
833 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
834 # define link rpl_link
836 _GL_FUNCDECL_RPL (link, int, (const char *path1, const char *path2)
837 _GL_ARG_NONNULL ((1, 2)));
838 _GL_CXXALIAS_RPL (link, int, (const char *path1, const char *path2));
841 _GL_FUNCDECL_SYS (link, int, (const char *path1, const char *path2)
842 _GL_ARG_NONNULL ((1, 2)));
844 _GL_CXXALIAS_SYS (link, int, (const char *path1, const char *path2));
846 _GL_CXXALIASWARN (link);
847 #elif defined GNULIB_POSIXCHECK
849 # if HAVE_RAW_DECL_LINK
850 _GL_WARN_ON_USE (link, "link is unportable - "
851 "use gnulib module link for portability");
857 /* Create a new hard link for an existing file, relative to two
858 directories. FLAG controls whether symlinks are followed.
859 Return 0 if successful, otherwise -1 and errno set. */
860 # if @REPLACE_LINKAT@
861 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
863 # define linkat rpl_linkat
865 _GL_FUNCDECL_RPL (linkat, int,
866 (int fd1, const char *path1, int fd2, const char *path2,
868 _GL_ARG_NONNULL ((2, 4)));
869 _GL_CXXALIAS_RPL (linkat, int,
870 (int fd1, const char *path1, int fd2, const char *path2,
874 _GL_FUNCDECL_SYS (linkat, int,
875 (int fd1, const char *path1, int fd2, const char *path2,
877 _GL_ARG_NONNULL ((2, 4)));
879 _GL_CXXALIAS_SYS (linkat, int,
880 (int fd1, const char *path1, int fd2, const char *path2,
883 _GL_CXXALIASWARN (linkat);
884 #elif defined GNULIB_POSIXCHECK
886 # if HAVE_RAW_DECL_LINKAT
887 _GL_WARN_ON_USE (linkat, "linkat is unportable - "
888 "use gnulib module linkat for portability");
894 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
895 Return the new offset if successful, otherwise -1 and errno set.
896 See the POSIX:2001 specification
897 <http://www.opengroup.org/susv3xsh/lseek.html>. */
899 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
900 # define lseek rpl_lseek
902 _GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence));
903 _GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence));
905 _GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
907 _GL_CXXALIASWARN (lseek);
908 #elif defined GNULIB_POSIXCHECK
910 # if HAVE_RAW_DECL_LSEEK
911 _GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some "
912 "systems - use gnulib module lseek for portability");
918 /* Create a pipe, applying the given flags when opening the read-end of the
919 pipe and the write-end of the pipe.
920 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
921 and O_TEXT, O_BINARY (defined in "binary-io.h").
922 Store the read-end as fd[0] and the write-end as fd[1].
923 Return 0 upon success, or -1 with errno set upon failure.
924 See also the Linux man page at
925 <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */
927 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
928 # define pipe2 rpl_pipe2
930 _GL_FUNCDECL_RPL (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
931 _GL_CXXALIAS_RPL (pipe2, int, (int fd[2], int flags));
933 _GL_FUNCDECL_SYS (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
934 _GL_CXXALIAS_SYS (pipe2, int, (int fd[2], int flags));
936 _GL_CXXALIASWARN (pipe2);
937 #elif defined GNULIB_POSIXCHECK
939 # if HAVE_RAW_DECL_PIPE2
940 _GL_WARN_ON_USE (pipe2, "pipe2 is unportable - "
941 "use gnulib module pipe2 for portability");
947 /* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
948 Return the number of bytes placed into BUF if successful, otherwise
949 set errno and return -1. 0 indicates EOF. See the POSIX:2001
950 specification <http://www.opengroup.org/susv3xsh/pread.html>. */
952 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
953 # define pread rpl_pread
955 _GL_FUNCDECL_RPL (pread, ssize_t,
956 (int fd, void *buf, size_t bufsize, off_t offset)
957 _GL_ARG_NONNULL ((2)));
958 _GL_CXXALIAS_RPL (pread, ssize_t,
959 (int fd, void *buf, size_t bufsize, off_t offset));
962 _GL_FUNCDECL_SYS (pread, ssize_t,
963 (int fd, void *buf, size_t bufsize, off_t offset)
964 _GL_ARG_NONNULL ((2)));
966 _GL_CXXALIAS_SYS (pread, ssize_t,
967 (int fd, void *buf, size_t bufsize, off_t offset));
969 _GL_CXXALIASWARN (pread);
970 #elif defined GNULIB_POSIXCHECK
972 # if HAVE_RAW_DECL_PREAD
973 _GL_WARN_ON_USE (pread, "pread is unportable - "
974 "use gnulib module pread for portability");
979 #if @GNULIB_READLINK@
980 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
981 bytes of it into BUF. Return the number of bytes placed into BUF if
982 successful, otherwise -1 and errno set.
983 See the POSIX:2001 specification
984 <http://www.opengroup.org/susv3xsh/readlink.html>. */
985 # if @REPLACE_READLINK@
986 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
987 # define readlink rpl_readlink
989 _GL_FUNCDECL_RPL (readlink, ssize_t,
990 (const char *file, char *buf, size_t bufsize)
991 _GL_ARG_NONNULL ((1, 2)));
992 _GL_CXXALIAS_RPL (readlink, ssize_t,
993 (const char *file, char *buf, size_t bufsize));
995 # if !@HAVE_READLINK@
996 _GL_FUNCDECL_SYS (readlink, ssize_t,
997 (const char *file, char *buf, size_t bufsize)
998 _GL_ARG_NONNULL ((1, 2)));
1000 _GL_CXXALIAS_SYS (readlink, ssize_t,
1001 (const char *file, char *buf, size_t bufsize));
1003 _GL_CXXALIASWARN (readlink);
1004 #elif defined GNULIB_POSIXCHECK
1006 # if HAVE_RAW_DECL_READLINK
1007 _GL_WARN_ON_USE (readlink, "readlink is unportable - "
1008 "use gnulib module readlink for portability");
1013 #if @GNULIB_READLINKAT@
1014 # if !@HAVE_READLINKAT@
1015 _GL_FUNCDECL_SYS (readlinkat, ssize_t,
1016 (int fd, char const *file, char *buf, size_t len)
1017 _GL_ARG_NONNULL ((2, 3)));
1019 _GL_CXXALIAS_SYS (readlinkat, ssize_t,
1020 (int fd, char const *file, char *buf, size_t len));
1021 _GL_CXXALIASWARN (readlinkat);
1022 #elif defined GNULIB_POSIXCHECK
1024 # if HAVE_RAW_DECL_READLINKAT
1025 _GL_WARN_ON_USE (readlinkat, "readlinkat is not portable - "
1026 "use gnulib module symlinkat for portability");
1032 /* Remove the directory DIR. */
1033 # if @REPLACE_RMDIR@
1034 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1035 # define rmdir rpl_rmdir
1037 _GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1)));
1038 _GL_CXXALIAS_RPL (rmdir, int, (char const *name));
1040 _GL_CXXALIAS_SYS (rmdir, int, (char const *name));
1042 _GL_CXXALIASWARN (rmdir);
1043 #elif defined GNULIB_POSIXCHECK
1045 # if HAVE_RAW_DECL_RMDIR
1046 _GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
1047 "use gnulib module rmdir for portability");
1053 /* Pause the execution of the current thread for N seconds.
1054 Returns the number of seconds left to sleep.
1055 See the POSIX:2001 specification
1056 <http://www.opengroup.org/susv3xsh/sleep.html>. */
1057 # if @REPLACE_SLEEP@
1058 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1060 # define sleep rpl_sleep
1062 _GL_FUNCDECL_RPL (sleep, unsigned int, (unsigned int n));
1063 _GL_CXXALIAS_RPL (sleep, unsigned int, (unsigned int n));
1066 _GL_FUNCDECL_SYS (sleep, unsigned int, (unsigned int n));
1068 _GL_CXXALIAS_SYS (sleep, unsigned int, (unsigned int n));
1070 _GL_CXXALIASWARN (sleep);
1071 #elif defined GNULIB_POSIXCHECK
1073 # if HAVE_RAW_DECL_SLEEP
1074 _GL_WARN_ON_USE (sleep, "sleep is unportable - "
1075 "use gnulib module sleep for portability");
1080 #if @GNULIB_SYMLINK@
1081 # if @REPLACE_SYMLINK@
1082 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1084 # define symlink rpl_symlink
1086 _GL_FUNCDECL_RPL (symlink, int, (char const *contents, char const *file)
1087 _GL_ARG_NONNULL ((1, 2)));
1088 _GL_CXXALIAS_RPL (symlink, int, (char const *contents, char const *file));
1090 # if !@HAVE_SYMLINK@
1091 _GL_FUNCDECL_SYS (symlink, int, (char const *contents, char const *file)
1092 _GL_ARG_NONNULL ((1, 2)));
1094 _GL_CXXALIAS_SYS (symlink, int, (char const *contents, char const *file));
1096 _GL_CXXALIASWARN (symlink);
1097 #elif defined GNULIB_POSIXCHECK
1099 # if HAVE_RAW_DECL_SYMLINK
1100 _GL_WARN_ON_USE (symlink, "symlink is not portable - "
1101 "use gnulib module symlink for portability");
1106 #if @GNULIB_SYMLINKAT@
1107 # if !@HAVE_SYMLINKAT@
1108 _GL_FUNCDECL_SYS (symlinkat, int,
1109 (char const *contents, int fd, char const *file)
1110 _GL_ARG_NONNULL ((1, 3)));
1112 _GL_CXXALIAS_SYS (symlinkat, int,
1113 (char const *contents, int fd, char const *file));
1114 _GL_CXXALIASWARN (symlinkat);
1115 #elif defined GNULIB_POSIXCHECK
1117 # if HAVE_RAW_DECL_SYMLINKAT
1118 _GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - "
1119 "use gnulib module symlinkat for portability");
1124 #if @GNULIB_TTYNAME_R@
1125 /* Store at most BUFLEN characters of the pathname of the terminal FD is
1126 open on in BUF. Return 0 on success, otherwise an error number. */
1127 # if !@HAVE_TTYNAME_R@
1128 _GL_FUNCDECL_SYS (ttyname_r, int,
1129 (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2)));
1131 _GL_CXXALIAS_SYS (ttyname_r, int,
1132 (int fd, char *buf, size_t buflen));
1133 _GL_CXXALIASWARN (ttyname_r);
1134 #elif defined GNULIB_POSIXCHECK
1136 # if HAVE_RAW_DECL_TTYNAME_R
1137 _GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - "
1138 "use gnulib module ttyname_r for portability");
1144 # if @REPLACE_UNLINK@
1145 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1147 # define unlink rpl_unlink
1149 _GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1)));
1150 _GL_CXXALIAS_RPL (unlink, int, (char const *file));
1152 _GL_CXXALIAS_SYS (unlink, int, (char const *file));
1154 _GL_CXXALIASWARN (unlink);
1155 #elif defined GNULIB_POSIXCHECK
1157 # if HAVE_RAW_DECL_UNLINK
1158 _GL_WARN_ON_USE (unlink, "unlink is not portable - "
1159 "use gnulib module unlink for portability");
1164 #if @GNULIB_UNLINKAT@
1165 # if @REPLACE_UNLINKAT@
1166 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1168 # define unlinkat rpl_unlinkat
1170 _GL_FUNCDECL_RPL (unlinkat, int, (int fd, char const *file, int flag)
1171 _GL_ARG_NONNULL ((2)));
1172 _GL_CXXALIAS_RPL (unlinkat, int, (int fd, char const *file, int flag));
1174 # if !@HAVE_UNLINKAT@
1175 _GL_FUNCDECL_SYS (unlinkat, int, (int fd, char const *file, int flag)
1176 _GL_ARG_NONNULL ((2)));
1178 _GL_CXXALIAS_SYS (unlinkat, int, (int fd, char const *file, int flag));
1180 _GL_CXXALIASWARN (unlinkat);
1181 #elif defined GNULIB_POSIXCHECK
1183 # if HAVE_RAW_DECL_UNLINKAT
1184 _GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
1185 "use gnulib module openat for portability");
1191 /* Pause the execution of the current thread for N microseconds.
1192 Returns 0 on completion, or -1 on range error.
1193 See the POSIX:2001 specification
1194 <http://www.opengroup.org/susv3xsh/sleep.html>. */
1195 # if @REPLACE_USLEEP@
1196 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1198 # define usleep rpl_usleep
1200 _GL_FUNCDECL_RPL (usleep, int, (useconds_t n));
1201 _GL_CXXALIAS_RPL (usleep, int, (useconds_t n));
1204 _GL_FUNCDECL_SYS (usleep, int, (useconds_t n));
1206 _GL_CXXALIAS_SYS (usleep, int, (useconds_t n));
1208 _GL_CXXALIASWARN (usleep);
1209 #elif defined GNULIB_POSIXCHECK
1211 # if HAVE_RAW_DECL_USLEEP
1212 _GL_WARN_ON_USE (usleep, "usleep is unportable - "
1213 "use gnulib module usleep for portability");
1219 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
1220 See the POSIX:2001 specification
1221 <http://www.opengroup.org/susv3xsh/write.html>. */
1222 # if @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
1223 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1225 # define write rpl_write
1227 _GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count)
1228 _GL_ARG_NONNULL ((2)));
1229 _GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count));
1231 _GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count));
1233 _GL_CXXALIASWARN (write);
1237 #endif /* _GL_UNISTD_H */
1238 #endif /* _GL_UNISTD_H */