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 @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \
23 && !defined _GL_WINSOCK2_H_WITNESS && 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 @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \
47 && !defined _GL_INCLUDING_WINSOCK2_H
48 # define _GL_INCLUDING_WINSOCK2_H
49 # include <winsock2.h>
50 # undef _GL_INCLUDING_WINSOCK2_H
53 #if !defined _GL_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H
56 /* NetBSD 5.0 mis-defines NULL. Also get size_t. */
59 /* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */
60 /* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>. */
61 /* But avoid namespace pollution on glibc systems. */
62 #if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
63 || (@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK)) \
64 && ! defined __GLIBC__
68 /* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>. */
69 /* But avoid namespace pollution on glibc systems. */
70 #if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__
74 /* mingw fails to declare _exit in <unistd.h>. */
75 /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */
76 /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */
77 /* But avoid namespace pollution on glibc systems. */
82 /* mingw declares getcwd in <io.h>, not in <unistd.h>. */
83 #if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \
84 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
88 #if (@GNULIB_WRITE@ || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \
89 || @GNULIB_PREAD@ || defined GNULIB_POSIXCHECK)
91 # include <sys/types.h>
94 /* Get getopt(), optarg, optind, opterr, optopt.
95 But avoid namespace pollution on glibc systems. */
96 #if @GNULIB_UNISTD_H_GETOPT@ && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT
100 #if @GNULIB_GETHOSTNAME@
101 /* Get all possible declarations of gethostname(). */
102 # if @UNISTD_H_HAVE_WINSOCK2_H@
103 # if !defined _GL_SYS_SOCKET_H
105 # define socket socket_used_without_including_sys_socket_h
107 # define connect connect_used_without_including_sys_socket_h
109 # define accept accept_used_without_including_sys_socket_h
111 # define bind bind_used_without_including_sys_socket_h
113 # define getpeername getpeername_used_without_including_sys_socket_h
115 # define getsockname getsockname_used_without_including_sys_socket_h
117 # define getsockopt getsockopt_used_without_including_sys_socket_h
119 # define listen listen_used_without_including_sys_socket_h
121 # define recv recv_used_without_including_sys_socket_h
123 # define send send_used_without_including_sys_socket_h
125 # define recvfrom recvfrom_used_without_including_sys_socket_h
127 # define sendto sendto_used_without_including_sys_socket_h
129 # define setsockopt setsockopt_used_without_including_sys_socket_h
131 # define shutdown shutdown_used_without_including_sys_socket_h
133 # if !defined _GL_SYS_SELECT_H
135 # define select select_used_without_including_sys_select_h
140 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
142 /* The definition of _GL_ARG_NONNULL is copied here. */
144 /* The definition of _GL_WARN_ON_USE is copied here. */
147 /* OS/2 EMX lacks these macros. */
149 # define STDIN_FILENO 0
151 #ifndef STDOUT_FILENO
152 # define STDOUT_FILENO 1
154 #ifndef STDERR_FILENO
155 # define STDERR_FILENO 2
158 /* Ensure *_OK macros exist. */
167 /* Declare overridden functions. */
170 #if defined GNULIB_POSIXCHECK
171 /* The access() function is a security risk. */
172 _GL_WARN_ON_USE (access, "the access function is a security risk - "
173 "use the gnulib module faccessat instead");
178 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
179 to GID (if GID is not -1). Follow symbolic links.
180 Return 0 if successful, otherwise -1 and errno set.
181 See the POSIX:2001 specification
182 <http://www.opengroup.org/susv3xsh/chown.html>. */
184 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
186 # define chown rpl_chown
188 _GL_FUNCDECL_RPL (chown, int, (const char *file, uid_t uid, gid_t gid)
189 _GL_ARG_NONNULL ((1)));
190 _GL_CXXALIAS_RPL (chown, int, (const char *file, uid_t uid, gid_t gid));
193 _GL_FUNCDECL_SYS (chown, int, (const char *file, uid_t uid, gid_t gid)
194 _GL_ARG_NONNULL ((1)));
196 _GL_CXXALIAS_SYS (chown, int, (const char *file, uid_t uid, gid_t gid));
198 _GL_CXXALIASWARN (chown);
199 #elif defined GNULIB_POSIXCHECK
201 # if HAVE_RAW_DECL_CHOWN
202 _GL_WARN_ON_USE (chown, "chown fails to follow symlinks on some systems and "
203 "doesn't treat a uid or gid of -1 on some systems - "
204 "use gnulib module chown for portability");
211 /* Automatically included by modules that need a replacement for close. */
212 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
214 # define close rpl_close
216 _GL_FUNCDECL_RPL (close, int, (int fd));
217 _GL_CXXALIAS_RPL (close, int, (int fd));
219 _GL_CXXALIAS_SYS (close, int, (int fd));
221 _GL_CXXALIASWARN (close);
222 #elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
224 # define close close_used_without_requesting_gnulib_module_close
225 #elif defined GNULIB_POSIXCHECK
227 /* Assume close is always declared. */
228 _GL_WARN_ON_USE (close, "close does not portably work on sockets - "
229 "use gnulib module close for portability");
234 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
237 _GL_FUNCDECL_RPL (dup, int, (int oldfd));
238 _GL_CXXALIAS_RPL (dup, int, (int oldfd));
240 _GL_CXXALIAS_SYS (dup, int, (int oldfd));
242 _GL_CXXALIASWARN (dup);
246 /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
247 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
248 Return newfd if successful, otherwise -1 and errno set.
249 See the POSIX:2001 specification
250 <http://www.opengroup.org/susv3xsh/dup2.html>. */
252 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
253 # define dup2 rpl_dup2
255 _GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd));
256 _GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd));
259 _GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd));
261 _GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
263 _GL_CXXALIASWARN (dup2);
264 #elif defined GNULIB_POSIXCHECK
266 # if HAVE_RAW_DECL_DUP2
267 _GL_WARN_ON_USE (dup2, "dup2 is unportable - "
268 "use gnulib module dup2 for portability");
274 /* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
276 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
277 and O_TEXT, O_BINARY (defined in "binary-io.h").
278 Close NEWFD first if it is open.
279 Return newfd if successful, otherwise -1 and errno set.
280 See the Linux man page at
281 <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */
283 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
284 # define dup3 rpl_dup3
286 _GL_FUNCDECL_RPL (dup3, int, (int oldfd, int newfd, int flags));
287 _GL_CXXALIAS_RPL (dup3, int, (int oldfd, int newfd, int flags));
289 _GL_FUNCDECL_SYS (dup3, int, (int oldfd, int newfd, int flags));
290 _GL_CXXALIAS_SYS (dup3, int, (int oldfd, int newfd, int flags));
292 _GL_CXXALIASWARN (dup3);
293 #elif defined GNULIB_POSIXCHECK
295 # if HAVE_RAW_DECL_DUP3
296 _GL_WARN_ON_USE (dup3, "dup3 is unportable - "
297 "use gnulib module dup3 for portability");
303 # if !@HAVE_DECL_ENVIRON@
304 /* Set of environment variables and values. An array of strings of the form
305 "VARIABLE=VALUE", terminated with a NULL. */
306 # if defined __APPLE__ && defined __MACH__
307 # include <crt_externs.h>
308 # define environ (*_NSGetEnviron ())
313 extern char **environ;
319 #elif defined GNULIB_POSIXCHECK
320 # if HAVE_RAW_DECL_ENVIRON
321 static inline char ***
326 _GL_WARN_ON_USE (rpl_environ, "environ is unportable - "
327 "use gnulib module environ for portability");
329 # define environ (*rpl_environ ())
334 #if @GNULIB_EUIDACCESS@
335 /* Like access(), except that it uses the effective user id and group id of
336 the current process. */
337 # if !@HAVE_EUIDACCESS@
338 _GL_FUNCDECL_SYS (euidaccess, int, (const char *filename, int mode)
339 _GL_ARG_NONNULL ((1)));
341 _GL_CXXALIAS_SYS (euidaccess, int, (const char *filename, int mode));
342 _GL_CXXALIASWARN (euidaccess);
343 # if defined GNULIB_POSIXCHECK
344 /* Like access(), this function is a security risk. */
345 _GL_WARN_ON_USE (euidaccess, "the euidaccess function is a security risk - "
346 "use the gnulib module faccessat instead");
348 #elif defined GNULIB_POSIXCHECK
350 # if HAVE_RAW_DECL_EUIDACCESS
351 _GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - "
352 "use gnulib module euidaccess for portability");
357 #if @GNULIB_FACCESSAT@
358 # if !@HAVE_FACCESSAT@
359 _GL_FUNCDECL_SYS (faccessat, int,
360 (int fd, char const *file, int mode, int flag)
361 _GL_ARG_NONNULL ((2)));
363 _GL_CXXALIAS_SYS (faccessat, int,
364 (int fd, char const *file, int mode, int flag));
365 _GL_CXXALIASWARN (faccessat);
366 #elif defined GNULIB_POSIXCHECK
368 # if HAVE_RAW_DECL_FACCESSAT
369 _GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
370 "use gnulib module faccessat for portability");
376 /* Change the process' current working directory to the directory on which
377 the given file descriptor is open.
378 Return 0 if successful, otherwise -1 and errno set.
379 See the POSIX:2001 specification
380 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
381 # if @REPLACE_FCHDIR@
382 _GL_FUNCDECL_RPL (fchdir, int, (int /*fd*/));
383 _GL_CXXALIAS_RPL (fchdir, int, (int /*fd*/));
385 /* Gnulib internal hooks needed to maintain the fchdir metadata. */
386 _GL_EXTERN_C int _gl_register_fd (int fd, const char *filename)
387 _GL_ARG_NONNULL ((2));
388 _GL_EXTERN_C void _gl_unregister_fd (int fd);
389 _GL_EXTERN_C int _gl_register_dup (int oldfd, int newfd);
390 _GL_EXTERN_C const char *_gl_directory_name (int fd);
393 _GL_CXXALIAS_SYS (fchdir, int, (int /*fd*/));
395 _GL_CXXALIASWARN (fchdir);
396 #elif defined GNULIB_POSIXCHECK
398 # if HAVE_RAW_DECL_FCHDIR
399 _GL_WARN_ON_USE (fchdir, "fchdir is unportable - "
400 "use gnulib module fchdir for portability");
405 #if @GNULIB_FCHOWNAT@
406 # if @REPLACE_FCHOWNAT@
407 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
409 # define fchownat rpl_fchownat
411 _GL_FUNCDECL_RPL (fchownat, int, (int fd, char const *file,
412 uid_t owner, gid_t group, int flag)
413 _GL_ARG_NONNULL ((2)));
414 _GL_CXXALIAS_RPL (fchownat, int, (int fd, char const *file,
415 uid_t owner, gid_t group, int flag));
417 # if !@HAVE_FCHOWNAT@
418 _GL_FUNCDECL_SYS (fchownat, int, (int fd, char const *file,
419 uid_t owner, gid_t group, int flag)
420 _GL_ARG_NONNULL ((2)));
422 _GL_CXXALIAS_SYS (fchownat, int, (int fd, char const *file,
423 uid_t owner, gid_t group, int flag));
425 _GL_CXXALIASWARN (fchownat);
426 #elif defined GNULIB_POSIXCHECK
428 # if HAVE_RAW_DECL_FCHOWNAT
429 _GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
430 "use gnulib module openat for portability");
436 /* Synchronize changes to a file.
437 Return 0 if successful, otherwise -1 and errno set.
438 See POSIX:2001 specification
439 <http://www.opengroup.org/susv3xsh/fsync.html>. */
441 _GL_FUNCDECL_SYS (fsync, int, (int fd));
443 _GL_CXXALIAS_SYS (fsync, int, (int fd));
444 _GL_CXXALIASWARN (fsync);
445 #elif defined GNULIB_POSIXCHECK
447 # if HAVE_RAW_DECL_FSYNC
448 _GL_WARN_ON_USE (fsync, "fsync is unportable - "
449 "use gnulib module fsync for portability");
454 #if @GNULIB_FTRUNCATE@
455 /* Change the size of the file to which FD is opened to become equal to LENGTH.
456 Return 0 if successful, otherwise -1 and errno set.
457 See the POSIX:2001 specification
458 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
459 # if !@HAVE_FTRUNCATE@
460 _GL_FUNCDECL_SYS (ftruncate, int, (int fd, off_t length));
462 _GL_CXXALIAS_SYS (ftruncate, int, (int fd, off_t length));
463 _GL_CXXALIASWARN (ftruncate);
464 #elif defined GNULIB_POSIXCHECK
466 # if HAVE_RAW_DECL_FTRUNCATE
467 _GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
468 "use gnulib module ftruncate for portability");
474 /* Get the name of the current working directory, and put it in SIZE bytes
476 Return BUF if successful, or NULL if the directory couldn't be determined
477 or SIZE was too small.
478 See the POSIX:2001 specification
479 <http://www.opengroup.org/susv3xsh/getcwd.html>.
480 Additionally, the gnulib module 'getcwd' guarantees the following GNU
481 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
482 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
484 # if @REPLACE_GETCWD@
485 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
486 # define getcwd rpl_getcwd
488 _GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size));
489 _GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size));
491 _GL_CXXALIAS_SYS (getcwd, char *, (char *buf, size_t size));
493 _GL_CXXALIASWARN (getcwd);
494 #elif defined GNULIB_POSIXCHECK
496 # if HAVE_RAW_DECL_GETCWD
497 _GL_WARN_ON_USE (getcwd, "getcwd is unportable - "
498 "use gnulib module getcwd for portability");
503 #if @GNULIB_GETDOMAINNAME@
504 /* Return the NIS domain name of the machine.
505 WARNING! The NIS domain name is unrelated to the fully qualified host name
506 of the machine. It is also unrelated to email addresses.
507 WARNING! The NIS domain name is usually the empty string or "(none)" when
510 Put up to LEN bytes of the NIS domain name into NAME.
511 Null terminate it if the name is shorter than LEN.
512 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
513 Return 0 if successful, otherwise set errno and return -1. */
514 # if !@HAVE_GETDOMAINNAME@
515 _GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len)
516 _GL_ARG_NONNULL ((1)));
518 /* Need to cast, because on MacOS X 10.5 systems, the second parameter is
520 _GL_CXXALIAS_SYS_CAST (getdomainname, int, (char *name, size_t len));
521 _GL_CXXALIASWARN (getdomainname);
522 #elif defined GNULIB_POSIXCHECK
523 # undef getdomainname
524 # if HAVE_RAW_DECL_GETDOMAINNAME
525 _GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - "
526 "use gnulib module getdomainname for portability");
531 #if @GNULIB_GETDTABLESIZE@
532 /* Return the maximum number of file descriptors in the current process.
533 In POSIX, this is same as sysconf (_SC_OPEN_MAX). */
534 # if !@HAVE_GETDTABLESIZE@
535 _GL_FUNCDECL_SYS (getdtablesize, int, (void));
537 _GL_CXXALIAS_SYS (getdtablesize, int, (void));
538 _GL_CXXALIASWARN (getdtablesize);
539 #elif defined GNULIB_POSIXCHECK
540 # undef getdtablesize
541 # if HAVE_RAW_DECL_GETDTABLESIZE
542 _GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - "
543 "use gnulib module getdtablesize for portability");
548 #if @GNULIB_GETGROUPS@
549 /* Return the supplemental groups that the current process belongs to.
550 It is unspecified whether the effective group id is in the list.
551 If N is 0, return the group count; otherwise, N describes how many
552 entries are available in GROUPS. Return -1 and set errno if N is
553 not 0 and not large enough. Fails with ENOSYS on some systems. */
554 # if @REPLACE_GETGROUPS@
555 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
557 # define getgroups rpl_getgroups
559 _GL_FUNCDECL_RPL (getgroups, int, (int n, gid_t *groups));
560 _GL_CXXALIAS_RPL (getgroups, int, (int n, gid_t *groups));
562 # if !@HAVE_GETGROUPS@
563 _GL_FUNCDECL_SYS (getgroups, int, (int n, gid_t *groups));
565 _GL_CXXALIAS_SYS (getgroups, int, (int n, gid_t *groups));
567 _GL_CXXALIASWARN (getgroups);
568 #elif defined GNULIB_POSIXCHECK
570 # if HAVE_RAW_DECL_GETGROUPS
571 _GL_WARN_ON_USE (getgroups, "getgroups is unportable - "
572 "use gnulib module getgroups for portability");
577 #if @GNULIB_GETHOSTNAME@
578 /* Return the standard host name of the machine.
579 WARNING! The host name may or may not be fully qualified.
581 Put up to LEN bytes of the host name into NAME.
582 Null terminate it if the name is shorter than LEN.
583 If the host name is longer than LEN, set errno = EINVAL and return -1.
584 Return 0 if successful, otherwise set errno and return -1. */
585 # if @UNISTD_H_HAVE_WINSOCK2_H@
586 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
588 # define gethostname rpl_gethostname
590 _GL_FUNCDECL_RPL (gethostname, int, (char *name, size_t len)
591 _GL_ARG_NONNULL ((1)));
592 _GL_CXXALIAS_RPL (gethostname, int, (char *name, size_t len));
594 # if !@HAVE_GETHOSTNAME@
595 _GL_FUNCDECL_SYS (gethostname, int, (char *name, size_t len)
596 _GL_ARG_NONNULL ((1)));
598 /* Need to cast, because on Solaris 10 systems, the second parameter is
600 _GL_CXXALIAS_SYS_CAST (gethostname, int, (char *name, size_t len));
602 _GL_CXXALIASWARN (gethostname);
603 #elif @UNISTD_H_HAVE_WINSOCK2_H@
605 # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
606 #elif defined GNULIB_POSIXCHECK
608 # if HAVE_RAW_DECL_GETHOSTNAME
609 _GL_WARN_ON_USE (gethostname, "gethostname is unportable - "
610 "use gnulib module gethostname for portability");
615 #if @GNULIB_GETLOGIN@
616 /* Returns the user's login name, or NULL if it cannot be found. Upon error,
617 returns NULL with errno set.
619 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
621 Most programs don't need to use this function, because the information is
622 available through environment variables:
623 ${LOGNAME-$USER} on Unix platforms,
624 $USERNAME on native Windows platforms.
626 # if !@HAVE_GETLOGIN@
627 _GL_FUNCDECL_SYS (getlogin, char *, (void));
629 _GL_CXXALIAS_SYS (getlogin, char *, (void));
630 _GL_CXXALIASWARN (getlogin);
631 #elif defined GNULIB_POSIXCHECK
633 # if HAVE_RAW_DECL_GETLOGIN
634 _GL_WARN_ON_USE (getlogin, "getlogin is unportable - "
635 "use gnulib module getlogin for portability");
640 #if @GNULIB_GETLOGIN_R@
641 /* Copies the user's login name to NAME.
642 The array pointed to by NAME has room for SIZE bytes.
644 Returns 0 if successful. Upon error, an error number is returned, or -1 in
645 the case that the login name cannot be found but no specific error is
646 provided (this case is hopefully rare but is left open by the POSIX spec).
648 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
650 Most programs don't need to use this function, because the information is
651 available through environment variables:
652 ${LOGNAME-$USER} on Unix platforms,
653 $USERNAME on native Windows platforms.
655 # if !@HAVE_DECL_GETLOGIN_R@
656 _GL_FUNCDECL_SYS (getlogin_r, int, (char *name, size_t size)
657 _GL_ARG_NONNULL ((1)));
659 /* Need to cast, because on Solaris 10 systems, the second argument is
661 _GL_CXXALIAS_SYS_CAST (getlogin_r, int, (char *name, size_t size));
662 _GL_CXXALIASWARN (getlogin_r);
663 #elif defined GNULIB_POSIXCHECK
665 # if HAVE_RAW_DECL_GETLOGIN_R
666 _GL_WARN_ON_USE (getlogin_r, "getlogin_r is unportable - "
667 "use gnulib module getlogin_r for portability");
672 #if @GNULIB_GETPAGESIZE@
673 # if @REPLACE_GETPAGESIZE@
674 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
675 # define getpagesize rpl_getpagesize
677 _GL_FUNCDECL_RPL (getpagesize, int, (void));
678 _GL_CXXALIAS_RPL (getpagesize, int, (void));
680 # if !@HAVE_GETPAGESIZE@
681 # if !defined getpagesize
682 /* This is for POSIX systems. */
683 # if !defined _gl_getpagesize && defined _SC_PAGESIZE
684 # if ! (defined __VMS && __VMS_VER < 70000000)
685 # define _gl_getpagesize() sysconf (_SC_PAGESIZE)
688 /* This is for older VMS. */
689 # if !defined _gl_getpagesize && defined __VMS
691 # define _gl_getpagesize() 8192
693 # define _gl_getpagesize() 512
696 /* This is for BeOS. */
697 # if !defined _gl_getpagesize && @HAVE_OS_H@
699 # if defined B_PAGE_SIZE
700 # define _gl_getpagesize() B_PAGE_SIZE
703 /* This is for AmigaOS4.0. */
704 # if !defined _gl_getpagesize && defined __amigaos4__
705 # define _gl_getpagesize() 2048
707 /* This is for older Unix systems. */
708 # if !defined _gl_getpagesize && @HAVE_SYS_PARAM_H@
709 # include <sys/param.h>
710 # ifdef EXEC_PAGESIZE
711 # define _gl_getpagesize() EXEC_PAGESIZE
717 # define _gl_getpagesize() (NBPG * CLSIZE)
720 # define _gl_getpagesize() NBPC
725 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
726 # define getpagesize() _gl_getpagesize ()
731 return _gl_getpagesize ();
736 /* Need to cast, because on Cygwin 1.5.x systems, the return type is size_t. */
737 _GL_CXXALIAS_SYS_CAST (getpagesize, int, (void));
739 _GL_CXXALIASWARN (getpagesize);
740 #elif defined GNULIB_POSIXCHECK
742 # if HAVE_RAW_DECL_GETPAGESIZE
743 _GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - "
744 "use gnulib module getpagesize for portability");
749 #if @GNULIB_GETUSERSHELL@
750 /* Return the next valid login shell on the system, or NULL when the end of
751 the list has been reached. */
752 # if !@HAVE_DECL_GETUSERSHELL@
753 _GL_FUNCDECL_SYS (getusershell, char *, (void));
755 _GL_CXXALIAS_SYS (getusershell, char *, (void));
756 _GL_CXXALIASWARN (getusershell);
757 #elif defined GNULIB_POSIXCHECK
759 # if HAVE_RAW_DECL_GETUSERSHELL
760 _GL_WARN_ON_USE (getusershell, "getusershell is unportable - "
761 "use gnulib module getusershell for portability");
765 #if @GNULIB_GETUSERSHELL@
766 /* Rewind to pointer that is advanced at each getusershell() call. */
767 # if !@HAVE_DECL_GETUSERSHELL@
768 _GL_FUNCDECL_SYS (setusershell, void, (void));
770 _GL_CXXALIAS_SYS (setusershell, void, (void));
771 _GL_CXXALIASWARN (setusershell);
772 #elif defined GNULIB_POSIXCHECK
774 # if HAVE_RAW_DECL_SETUSERSHELL
775 _GL_WARN_ON_USE (setusershell, "setusershell is unportable - "
776 "use gnulib module getusershell for portability");
780 #if @GNULIB_GETUSERSHELL@
781 /* Free the pointer that is advanced at each getusershell() call and
782 associated resources. */
783 # if !@HAVE_DECL_GETUSERSHELL@
784 _GL_FUNCDECL_SYS (endusershell, void, (void));
786 _GL_CXXALIAS_SYS (endusershell, void, (void));
787 _GL_CXXALIASWARN (endusershell);
788 #elif defined GNULIB_POSIXCHECK
790 # if HAVE_RAW_DECL_ENDUSERSHELL
791 _GL_WARN_ON_USE (endusershell, "endusershell is unportable - "
792 "use gnulib module getusershell for portability");
798 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
799 to GID (if GID is not -1). Do not follow symbolic links.
800 Return 0 if successful, otherwise -1 and errno set.
801 See the POSIX:2001 specification
802 <http://www.opengroup.org/susv3xsh/lchown.html>. */
803 # if @REPLACE_LCHOWN@
804 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
806 # define lchown rpl_lchown
808 _GL_FUNCDECL_RPL (lchown, int, (char const *file, uid_t owner, gid_t group)
809 _GL_ARG_NONNULL ((1)));
810 _GL_CXXALIAS_RPL (lchown, int, (char const *file, uid_t owner, gid_t group));
813 _GL_FUNCDECL_SYS (lchown, int, (char const *file, uid_t owner, gid_t group)
814 _GL_ARG_NONNULL ((1)));
816 _GL_CXXALIAS_SYS (lchown, int, (char const *file, uid_t owner, gid_t group));
818 _GL_CXXALIASWARN (lchown);
819 #elif defined GNULIB_POSIXCHECK
821 # if HAVE_RAW_DECL_LCHOWN
822 _GL_WARN_ON_USE (lchown, "lchown is unportable to pre-POSIX.1-2001 systems - "
823 "use gnulib module lchown for portability");
829 /* Create a new hard link for an existing file.
830 Return 0 if successful, otherwise -1 and errno set.
831 See POSIX:2001 specification
832 <http://www.opengroup.org/susv3xsh/link.html>. */
834 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
835 # define link rpl_link
837 _GL_FUNCDECL_RPL (link, int, (const char *path1, const char *path2)
838 _GL_ARG_NONNULL ((1, 2)));
839 _GL_CXXALIAS_RPL (link, int, (const char *path1, const char *path2));
842 _GL_FUNCDECL_SYS (link, int, (const char *path1, const char *path2)
843 _GL_ARG_NONNULL ((1, 2)));
845 _GL_CXXALIAS_SYS (link, int, (const char *path1, const char *path2));
847 _GL_CXXALIASWARN (link);
848 #elif defined GNULIB_POSIXCHECK
850 # if HAVE_RAW_DECL_LINK
851 _GL_WARN_ON_USE (link, "link is unportable - "
852 "use gnulib module link for portability");
858 /* Create a new hard link for an existing file, relative to two
859 directories. FLAG controls whether symlinks are followed.
860 Return 0 if successful, otherwise -1 and errno set. */
861 # if @REPLACE_LINKAT@
862 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
864 # define linkat rpl_linkat
866 _GL_FUNCDECL_RPL (linkat, int,
867 (int fd1, const char *path1, int fd2, const char *path2,
869 _GL_ARG_NONNULL ((2, 4)));
870 _GL_CXXALIAS_RPL (linkat, int,
871 (int fd1, const char *path1, int fd2, const char *path2,
875 _GL_FUNCDECL_SYS (linkat, int,
876 (int fd1, const char *path1, int fd2, const char *path2,
878 _GL_ARG_NONNULL ((2, 4)));
880 _GL_CXXALIAS_SYS (linkat, int,
881 (int fd1, const char *path1, int fd2, const char *path2,
884 _GL_CXXALIASWARN (linkat);
885 #elif defined GNULIB_POSIXCHECK
887 # if HAVE_RAW_DECL_LINKAT
888 _GL_WARN_ON_USE (linkat, "linkat is unportable - "
889 "use gnulib module linkat for portability");
895 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
896 Return the new offset if successful, otherwise -1 and errno set.
897 See the POSIX:2001 specification
898 <http://www.opengroup.org/susv3xsh/lseek.html>. */
900 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
901 # define lseek rpl_lseek
903 _GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence));
904 _GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence));
906 _GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
908 _GL_CXXALIASWARN (lseek);
909 #elif defined GNULIB_POSIXCHECK
911 # if HAVE_RAW_DECL_LSEEK
912 _GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some "
913 "systems - use gnulib module lseek for portability");
919 /* Create a pipe, applying the given flags when opening the read-end of the
920 pipe and the write-end of the pipe.
921 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
922 and O_TEXT, O_BINARY (defined in "binary-io.h").
923 Store the read-end as fd[0] and the write-end as fd[1].
924 Return 0 upon success, or -1 with errno set upon failure.
925 See also the Linux man page at
926 <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */
928 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
929 # define pipe2 rpl_pipe2
931 _GL_FUNCDECL_RPL (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
932 _GL_CXXALIAS_RPL (pipe2, int, (int fd[2], int flags));
934 _GL_FUNCDECL_SYS (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
935 _GL_CXXALIAS_SYS (pipe2, int, (int fd[2], int flags));
937 _GL_CXXALIASWARN (pipe2);
938 #elif defined GNULIB_POSIXCHECK
940 # if HAVE_RAW_DECL_PIPE2
941 _GL_WARN_ON_USE (pipe2, "pipe2 is unportable - "
942 "use gnulib module pipe2 for portability");
948 /* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
949 Return the number of bytes placed into BUF if successful, otherwise
950 set errno and return -1. 0 indicates EOF. See the POSIX:2001
951 specification <http://www.opengroup.org/susv3xsh/pread.html>. */
953 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
954 # define pread rpl_pread
956 _GL_FUNCDECL_RPL (pread, ssize_t,
957 (int fd, void *buf, size_t bufsize, off_t offset)
958 _GL_ARG_NONNULL ((2)));
959 _GL_CXXALIAS_RPL (pread, ssize_t,
960 (int fd, void *buf, size_t bufsize, off_t offset));
963 _GL_FUNCDECL_SYS (pread, ssize_t,
964 (int fd, void *buf, size_t bufsize, off_t offset)
965 _GL_ARG_NONNULL ((2)));
967 _GL_CXXALIAS_SYS (pread, ssize_t,
968 (int fd, void *buf, size_t bufsize, off_t offset));
970 _GL_CXXALIASWARN (pread);
971 #elif defined GNULIB_POSIXCHECK
973 # if HAVE_RAW_DECL_PREAD
974 _GL_WARN_ON_USE (pread, "pread is unportable - "
975 "use gnulib module pread for portability");
980 #if @GNULIB_READLINK@
981 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
982 bytes of it into BUF. Return the number of bytes placed into BUF if
983 successful, otherwise -1 and errno set.
984 See the POSIX:2001 specification
985 <http://www.opengroup.org/susv3xsh/readlink.html>. */
986 # if @REPLACE_READLINK@
987 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
988 # define readlink rpl_readlink
990 _GL_FUNCDECL_RPL (readlink, ssize_t,
991 (const char *file, char *buf, size_t bufsize)
992 _GL_ARG_NONNULL ((1, 2)));
993 _GL_CXXALIAS_RPL (readlink, ssize_t,
994 (const char *file, char *buf, size_t bufsize));
996 # if !@HAVE_READLINK@
997 _GL_FUNCDECL_SYS (readlink, ssize_t,
998 (const char *file, char *buf, size_t bufsize)
999 _GL_ARG_NONNULL ((1, 2)));
1001 _GL_CXXALIAS_SYS (readlink, ssize_t,
1002 (const char *file, char *buf, size_t bufsize));
1004 _GL_CXXALIASWARN (readlink);
1005 #elif defined GNULIB_POSIXCHECK
1007 # if HAVE_RAW_DECL_READLINK
1008 _GL_WARN_ON_USE (readlink, "readlink is unportable - "
1009 "use gnulib module readlink for portability");
1014 #if @GNULIB_READLINKAT@
1015 # if !@HAVE_READLINKAT@
1016 _GL_FUNCDECL_SYS (readlinkat, ssize_t,
1017 (int fd, char const *file, char *buf, size_t len)
1018 _GL_ARG_NONNULL ((2, 3)));
1020 _GL_CXXALIAS_SYS (readlinkat, ssize_t,
1021 (int fd, char const *file, char *buf, size_t len));
1022 _GL_CXXALIASWARN (readlinkat);
1023 #elif defined GNULIB_POSIXCHECK
1025 # if HAVE_RAW_DECL_READLINKAT
1026 _GL_WARN_ON_USE (readlinkat, "readlinkat is not portable - "
1027 "use gnulib module symlinkat for portability");
1033 /* Remove the directory DIR. */
1034 # if @REPLACE_RMDIR@
1035 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1036 # define rmdir rpl_rmdir
1038 _GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1)));
1039 _GL_CXXALIAS_RPL (rmdir, int, (char const *name));
1041 _GL_CXXALIAS_SYS (rmdir, int, (char const *name));
1043 _GL_CXXALIASWARN (rmdir);
1044 #elif defined GNULIB_POSIXCHECK
1046 # if HAVE_RAW_DECL_RMDIR
1047 _GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
1048 "use gnulib module rmdir for portability");
1054 /* Pause the execution of the current thread for N seconds.
1055 Returns the number of seconds left to sleep.
1056 See the POSIX:2001 specification
1057 <http://www.opengroup.org/susv3xsh/sleep.html>. */
1058 # if @REPLACE_SLEEP@
1059 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1061 # define sleep rpl_sleep
1063 _GL_FUNCDECL_RPL (sleep, unsigned int, (unsigned int n));
1064 _GL_CXXALIAS_RPL (sleep, unsigned int, (unsigned int n));
1067 _GL_FUNCDECL_SYS (sleep, unsigned int, (unsigned int n));
1069 _GL_CXXALIAS_SYS (sleep, unsigned int, (unsigned int n));
1071 _GL_CXXALIASWARN (sleep);
1072 #elif defined GNULIB_POSIXCHECK
1074 # if HAVE_RAW_DECL_SLEEP
1075 _GL_WARN_ON_USE (sleep, "sleep is unportable - "
1076 "use gnulib module sleep for portability");
1081 #if @GNULIB_SYMLINK@
1082 # if @REPLACE_SYMLINK@
1083 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1085 # define symlink rpl_symlink
1087 _GL_FUNCDECL_RPL (symlink, int, (char const *contents, char const *file)
1088 _GL_ARG_NONNULL ((1, 2)));
1089 _GL_CXXALIAS_RPL (symlink, int, (char const *contents, char const *file));
1091 # if !@HAVE_SYMLINK@
1092 _GL_FUNCDECL_SYS (symlink, int, (char const *contents, char const *file)
1093 _GL_ARG_NONNULL ((1, 2)));
1095 _GL_CXXALIAS_SYS (symlink, int, (char const *contents, char const *file));
1097 _GL_CXXALIASWARN (symlink);
1098 #elif defined GNULIB_POSIXCHECK
1100 # if HAVE_RAW_DECL_SYMLINK
1101 _GL_WARN_ON_USE (symlink, "symlink is not portable - "
1102 "use gnulib module symlink for portability");
1107 #if @GNULIB_SYMLINKAT@
1108 # if !@HAVE_SYMLINKAT@
1109 _GL_FUNCDECL_SYS (symlinkat, int,
1110 (char const *contents, int fd, char const *file)
1111 _GL_ARG_NONNULL ((1, 3)));
1113 _GL_CXXALIAS_SYS (symlinkat, int,
1114 (char const *contents, int fd, char const *file));
1115 _GL_CXXALIASWARN (symlinkat);
1116 #elif defined GNULIB_POSIXCHECK
1118 # if HAVE_RAW_DECL_SYMLINKAT
1119 _GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - "
1120 "use gnulib module symlinkat for portability");
1125 #if @GNULIB_TTYNAME_R@
1126 /* Store at most BUFLEN characters of the pathname of the terminal FD is
1127 open on in BUF. Return 0 on success, otherwise an error number. */
1128 # if !@HAVE_TTYNAME_R@
1129 _GL_FUNCDECL_SYS (ttyname_r, int,
1130 (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2)));
1132 _GL_CXXALIAS_SYS (ttyname_r, int,
1133 (int fd, char *buf, size_t buflen));
1134 _GL_CXXALIASWARN (ttyname_r);
1135 #elif defined GNULIB_POSIXCHECK
1137 # if HAVE_RAW_DECL_TTYNAME_R
1138 _GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - "
1139 "use gnulib module ttyname_r for portability");
1145 # if @REPLACE_UNLINK@
1146 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1148 # define unlink rpl_unlink
1150 _GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1)));
1151 _GL_CXXALIAS_RPL (unlink, int, (char const *file));
1153 _GL_CXXALIAS_SYS (unlink, int, (char const *file));
1155 _GL_CXXALIASWARN (unlink);
1156 #elif defined GNULIB_POSIXCHECK
1158 # if HAVE_RAW_DECL_UNLINK
1159 _GL_WARN_ON_USE (unlink, "unlink is not portable - "
1160 "use gnulib module unlink for portability");
1165 #if @GNULIB_UNLINKAT@
1166 # if @REPLACE_UNLINKAT@
1167 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1169 # define unlinkat rpl_unlinkat
1171 _GL_FUNCDECL_RPL (unlinkat, int, (int fd, char const *file, int flag)
1172 _GL_ARG_NONNULL ((2)));
1173 _GL_CXXALIAS_RPL (unlinkat, int, (int fd, char const *file, int flag));
1175 # if !@HAVE_UNLINKAT@
1176 _GL_FUNCDECL_SYS (unlinkat, int, (int fd, char const *file, int flag)
1177 _GL_ARG_NONNULL ((2)));
1179 _GL_CXXALIAS_SYS (unlinkat, int, (int fd, char const *file, int flag));
1181 _GL_CXXALIASWARN (unlinkat);
1182 #elif defined GNULIB_POSIXCHECK
1184 # if HAVE_RAW_DECL_UNLINKAT
1185 _GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
1186 "use gnulib module openat for portability");
1192 /* Pause the execution of the current thread for N microseconds.
1193 Returns 0 on completion, or -1 on range error.
1194 See the POSIX:2001 specification
1195 <http://www.opengroup.org/susv3xsh/sleep.html>. */
1196 # if @REPLACE_USLEEP@
1197 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1199 # define usleep rpl_usleep
1201 _GL_FUNCDECL_RPL (usleep, int, (useconds_t n));
1202 _GL_CXXALIAS_RPL (usleep, int, (useconds_t n));
1205 _GL_FUNCDECL_SYS (usleep, int, (useconds_t n));
1207 _GL_CXXALIAS_SYS (usleep, int, (useconds_t n));
1209 _GL_CXXALIASWARN (usleep);
1210 #elif defined GNULIB_POSIXCHECK
1212 # if HAVE_RAW_DECL_USLEEP
1213 _GL_WARN_ON_USE (usleep, "usleep is unportable - "
1214 "use gnulib module usleep for portability");
1220 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
1221 See the POSIX:2001 specification
1222 <http://www.opengroup.org/susv3xsh/write.html>. */
1223 # if @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
1224 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1226 # define write rpl_write
1228 _GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count)
1229 _GL_ARG_NONNULL ((2)));
1230 _GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count));
1232 _GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count));
1234 _GL_CXXALIASWARN (write);
1238 #endif /* _GL_UNISTD_H */
1239 #endif /* _GL_UNISTD_H */