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. */
21 @PRAGMA_SYSTEM_HEADER@
24 /* The include_next requires a split double-inclusion guard. */
26 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
32 /* NetBSD 5.0 mis-defines NULL. Also get size_t. */
35 /* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */
36 /* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>. */
37 /* But avoid namespace pollution on glibc systems. */
38 #if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
39 || (@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK)) \
40 && ! defined __GLIBC__
44 /* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>. */
45 /* But avoid namespace pollution on glibc systems. */
46 #if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__
50 /* mingw fails to declare _exit in <unistd.h>. */
51 /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */
52 /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */
53 /* But avoid namespace pollution on glibc systems. */
58 /* mingw declares getcwd in <io.h>, not in <unistd.h>. */
59 #if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \
60 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
64 #if (@GNULIB_WRITE@ || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \
65 || @GNULIB_PREAD@ || defined GNULIB_POSIXCHECK)
67 # include <sys/types.h>
70 /* Get getopt(), optarg, optind, opterr, optopt.
71 But avoid namespace pollution on glibc systems. */
72 #if @GNULIB_UNISTD_H_GETOPT@ && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT
76 #if @GNULIB_GETHOSTNAME@
77 /* Get all possible declarations of gethostname(). */
78 # if @UNISTD_H_HAVE_WINSOCK2_H@
79 # include <winsock2.h>
80 # if !defined _GL_SYS_SOCKET_H
82 # define socket socket_used_without_including_sys_socket_h
84 # define connect connect_used_without_including_sys_socket_h
86 # define accept accept_used_without_including_sys_socket_h
88 # define bind bind_used_without_including_sys_socket_h
90 # define getpeername getpeername_used_without_including_sys_socket_h
92 # define getsockname getsockname_used_without_including_sys_socket_h
94 # define getsockopt getsockopt_used_without_including_sys_socket_h
96 # define listen listen_used_without_including_sys_socket_h
98 # define recv recv_used_without_including_sys_socket_h
100 # define send send_used_without_including_sys_socket_h
102 # define recvfrom recvfrom_used_without_including_sys_socket_h
104 # define sendto sendto_used_without_including_sys_socket_h
106 # define setsockopt setsockopt_used_without_including_sys_socket_h
108 # define shutdown shutdown_used_without_including_sys_socket_h
110 # if !defined _GL_SYS_SELECT_H
112 # define select select_used_without_including_sys_select_h
117 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
119 /* The definition of _GL_ARG_NONNULL is copied here. */
121 /* The definition of _GL_WARN_ON_USE is copied here. */
124 /* OS/2 EMX lacks these macros. */
126 # define STDIN_FILENO 0
128 #ifndef STDOUT_FILENO
129 # define STDOUT_FILENO 1
131 #ifndef STDERR_FILENO
132 # define STDERR_FILENO 2
135 /* Ensure *_OK macros exist. */
144 /* Declare overridden functions. */
147 #if defined GNULIB_POSIXCHECK
148 /* The access() function is a security risk. */
149 _GL_WARN_ON_USE (access, "the access function is a security risk - "
150 "use the gnulib module faccessat instead");
155 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
156 to GID (if GID is not -1). Follow symbolic links.
157 Return 0 if successful, otherwise -1 and errno set.
158 See the POSIX:2001 specification
159 <http://www.opengroup.org/susv3xsh/chown.html>. */
161 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
163 # define chown rpl_chown
165 _GL_FUNCDECL_RPL (chown, int, (const char *file, uid_t uid, gid_t gid)
166 _GL_ARG_NONNULL ((1)));
167 _GL_CXXALIAS_RPL (chown, int, (const char *file, uid_t uid, gid_t gid));
170 _GL_FUNCDECL_SYS (chown, int, (const char *file, uid_t uid, gid_t gid)
171 _GL_ARG_NONNULL ((1)));
173 _GL_CXXALIAS_SYS (chown, int, (const char *file, uid_t uid, gid_t gid));
175 _GL_CXXALIASWARN (chown);
176 #elif defined GNULIB_POSIXCHECK
178 # if HAVE_RAW_DECL_CHOWN
179 _GL_WARN_ON_USE (chown, "chown fails to follow symlinks on some systems and "
180 "doesn't treat a uid or gid of -1 on some systems - "
181 "use gnulib module chown for portability");
188 /* Automatically included by modules that need a replacement for close. */
189 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
191 # define close rpl_close
193 _GL_FUNCDECL_RPL (close, int, (int fd));
194 _GL_CXXALIAS_RPL (close, int, (int fd));
196 _GL_CXXALIAS_SYS (close, int, (int fd));
198 _GL_CXXALIASWARN (close);
199 #elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
201 # define close close_used_without_requesting_gnulib_module_close
202 #elif defined GNULIB_POSIXCHECK
204 /* Assume close is always declared. */
205 _GL_WARN_ON_USE (close, "close does not portably work on sockets - "
206 "use gnulib module close for portability");
211 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
214 _GL_FUNCDECL_RPL (dup, int, (int oldfd));
215 _GL_CXXALIAS_RPL (dup, int, (int oldfd));
217 _GL_CXXALIAS_SYS (dup, int, (int oldfd));
219 _GL_CXXALIASWARN (dup);
223 /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
224 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
225 Return newfd if successful, otherwise -1 and errno set.
226 See the POSIX:2001 specification
227 <http://www.opengroup.org/susv3xsh/dup2.html>. */
229 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
230 # define dup2 rpl_dup2
232 _GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd));
233 _GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd));
236 _GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd));
238 _GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
240 _GL_CXXALIASWARN (dup2);
241 #elif defined GNULIB_POSIXCHECK
243 # if HAVE_RAW_DECL_DUP2
244 _GL_WARN_ON_USE (dup2, "dup2 is unportable - "
245 "use gnulib module dup2 for portability");
251 /* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
253 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
254 and O_TEXT, O_BINARY (defined in "binary-io.h").
255 Close NEWFD first if it is open.
256 Return newfd if successful, otherwise -1 and errno set.
257 See the Linux man page at
258 <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */
260 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
261 # define dup3 rpl_dup3
263 _GL_FUNCDECL_RPL (dup3, int, (int oldfd, int newfd, int flags));
264 _GL_CXXALIAS_RPL (dup3, int, (int oldfd, int newfd, int flags));
266 _GL_FUNCDECL_SYS (dup3, int, (int oldfd, int newfd, int flags));
267 _GL_CXXALIAS_SYS (dup3, int, (int oldfd, int newfd, int flags));
269 _GL_CXXALIASWARN (dup3);
270 #elif defined GNULIB_POSIXCHECK
272 # if HAVE_RAW_DECL_DUP3
273 _GL_WARN_ON_USE (dup3, "dup3 is unportable - "
274 "use gnulib module dup3 for portability");
280 # if !@HAVE_DECL_ENVIRON@
281 /* Set of environment variables and values. An array of strings of the form
282 "VARIABLE=VALUE", terminated with a NULL. */
283 # if defined __APPLE__ && defined __MACH__
284 # include <crt_externs.h>
285 # define environ (*_NSGetEnviron ())
290 extern char **environ;
296 #elif defined GNULIB_POSIXCHECK
297 # if HAVE_RAW_DECL_ENVIRON
298 static inline char ***
303 _GL_WARN_ON_USE (rpl_environ, "environ is unportable - "
304 "use gnulib module environ for portability");
306 # define environ (*rpl_environ ())
311 #if @GNULIB_EUIDACCESS@
312 /* Like access(), except that it uses the effective user id and group id of
313 the current process. */
314 # if !@HAVE_EUIDACCESS@
315 _GL_FUNCDECL_SYS (euidaccess, int, (const char *filename, int mode)
316 _GL_ARG_NONNULL ((1)));
318 _GL_CXXALIAS_SYS (euidaccess, int, (const char *filename, int mode));
319 _GL_CXXALIASWARN (euidaccess);
320 # if defined GNULIB_POSIXCHECK
321 /* Like access(), this function is a security risk. */
322 _GL_WARN_ON_USE (euidaccess, "the euidaccess function is a security risk - "
323 "use the gnulib module faccessat instead");
325 #elif defined GNULIB_POSIXCHECK
327 # if HAVE_RAW_DECL_EUIDACCESS
328 _GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - "
329 "use gnulib module euidaccess for portability");
334 #if @GNULIB_FACCESSAT@
335 # if !@HAVE_FACCESSAT@
336 _GL_FUNCDECL_SYS (faccessat, int,
337 (int fd, char const *file, int mode, int flag)
338 _GL_ARG_NONNULL ((2)));
340 _GL_CXXALIAS_SYS (faccessat, int,
341 (int fd, char const *file, int mode, int flag));
342 _GL_CXXALIASWARN (faccessat);
343 #elif defined GNULIB_POSIXCHECK
345 # if HAVE_RAW_DECL_FACCESSAT
346 _GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
347 "use gnulib module faccessat for portability");
353 /* Change the process' current working directory to the directory on which
354 the given file descriptor is open.
355 Return 0 if successful, otherwise -1 and errno set.
356 See the POSIX:2001 specification
357 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
358 # if @REPLACE_FCHDIR@
359 _GL_FUNCDECL_RPL (fchdir, int, (int /*fd*/));
360 _GL_CXXALIAS_RPL (fchdir, int, (int /*fd*/));
362 /* Gnulib internal hooks needed to maintain the fchdir metadata. */
363 _GL_EXTERN_C int _gl_register_fd (int fd, const char *filename)
364 _GL_ARG_NONNULL ((2));
365 _GL_EXTERN_C void _gl_unregister_fd (int fd);
366 _GL_EXTERN_C int _gl_register_dup (int oldfd, int newfd);
367 _GL_EXTERN_C const char *_gl_directory_name (int fd);
370 _GL_CXXALIAS_SYS (fchdir, int, (int /*fd*/));
372 _GL_CXXALIASWARN (fchdir);
373 #elif defined GNULIB_POSIXCHECK
375 # if HAVE_RAW_DECL_FCHDIR
376 _GL_WARN_ON_USE (fchdir, "fchdir is unportable - "
377 "use gnulib module fchdir for portability");
382 #if @GNULIB_FCHOWNAT@
383 # if @REPLACE_FCHOWNAT@
384 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
386 # define fchownat rpl_fchownat
388 _GL_FUNCDECL_RPL (fchownat, int, (int fd, char const *file,
389 uid_t owner, gid_t group, int flag)
390 _GL_ARG_NONNULL ((2)));
391 _GL_CXXALIAS_RPL (fchownat, int, (int fd, char const *file,
392 uid_t owner, gid_t group, int flag));
394 # if !@HAVE_FCHOWNAT@
395 _GL_FUNCDECL_SYS (fchownat, int, (int fd, char const *file,
396 uid_t owner, gid_t group, int flag)
397 _GL_ARG_NONNULL ((2)));
399 _GL_CXXALIAS_SYS (fchownat, int, (int fd, char const *file,
400 uid_t owner, gid_t group, int flag));
402 _GL_CXXALIASWARN (fchownat);
403 #elif defined GNULIB_POSIXCHECK
405 # if HAVE_RAW_DECL_FCHOWNAT
406 _GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
407 "use gnulib module openat for portability");
413 /* Synchronize changes to a file.
414 Return 0 if successful, otherwise -1 and errno set.
415 See POSIX:2001 specification
416 <http://www.opengroup.org/susv3xsh/fsync.html>. */
418 _GL_FUNCDECL_SYS (fsync, int, (int fd));
420 _GL_CXXALIAS_SYS (fsync, int, (int fd));
421 _GL_CXXALIASWARN (fsync);
422 #elif defined GNULIB_POSIXCHECK
424 # if HAVE_RAW_DECL_FSYNC
425 _GL_WARN_ON_USE (fsync, "fsync is unportable - "
426 "use gnulib module fsync for portability");
431 #if @GNULIB_FTRUNCATE@
432 /* Change the size of the file to which FD is opened to become equal to LENGTH.
433 Return 0 if successful, otherwise -1 and errno set.
434 See the POSIX:2001 specification
435 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
436 # if !@HAVE_FTRUNCATE@
437 _GL_FUNCDECL_SYS (ftruncate, int, (int fd, off_t length));
439 _GL_CXXALIAS_SYS (ftruncate, int, (int fd, off_t length));
440 _GL_CXXALIASWARN (ftruncate);
441 #elif defined GNULIB_POSIXCHECK
443 # if HAVE_RAW_DECL_FTRUNCATE
444 _GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
445 "use gnulib module ftruncate for portability");
451 /* Get the name of the current working directory, and put it in SIZE bytes
453 Return BUF if successful, or NULL if the directory couldn't be determined
454 or SIZE was too small.
455 See the POSIX:2001 specification
456 <http://www.opengroup.org/susv3xsh/getcwd.html>.
457 Additionally, the gnulib module 'getcwd' guarantees the following GNU
458 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
459 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
461 # if @REPLACE_GETCWD@
462 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
463 # define getcwd rpl_getcwd
465 _GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size));
466 _GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size));
468 _GL_CXXALIAS_SYS (getcwd, char *, (char *buf, size_t size));
470 _GL_CXXALIASWARN (getcwd);
471 #elif defined GNULIB_POSIXCHECK
473 # if HAVE_RAW_DECL_GETCWD
474 _GL_WARN_ON_USE (getcwd, "getcwd is unportable - "
475 "use gnulib module getcwd for portability");
480 #if @GNULIB_GETDOMAINNAME@
481 /* Return the NIS domain name of the machine.
482 WARNING! The NIS domain name is unrelated to the fully qualified host name
483 of the machine. It is also unrelated to email addresses.
484 WARNING! The NIS domain name is usually the empty string or "(none)" when
487 Put up to LEN bytes of the NIS domain name into NAME.
488 Null terminate it if the name is shorter than LEN.
489 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
490 Return 0 if successful, otherwise set errno and return -1. */
491 # if !@HAVE_GETDOMAINNAME@
492 _GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len)
493 _GL_ARG_NONNULL ((1)));
495 /* Need to cast, because on MacOS X 10.5 systems, the second parameter is
497 _GL_CXXALIAS_SYS_CAST (getdomainname, int, (char *name, size_t len));
498 _GL_CXXALIASWARN (getdomainname);
499 #elif defined GNULIB_POSIXCHECK
500 # undef getdomainname
501 # if HAVE_RAW_DECL_GETDOMAINNAME
502 _GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - "
503 "use gnulib module getdomainname for portability");
508 #if @GNULIB_GETDTABLESIZE@
509 /* Return the maximum number of file descriptors in the current process.
510 In POSIX, this is same as sysconf (_SC_OPEN_MAX). */
511 # if !@HAVE_GETDTABLESIZE@
512 _GL_FUNCDECL_SYS (getdtablesize, int, (void));
514 _GL_CXXALIAS_SYS (getdtablesize, int, (void));
515 _GL_CXXALIASWARN (getdtablesize);
516 #elif defined GNULIB_POSIXCHECK
517 # undef getdtablesize
518 # if HAVE_RAW_DECL_GETDTABLESIZE
519 _GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - "
520 "use gnulib module getdtablesize for portability");
525 #if @GNULIB_GETGROUPS@
526 /* Return the supplemental groups that the current process belongs to.
527 It is unspecified whether the effective group id is in the list.
528 If N is 0, return the group count; otherwise, N describes how many
529 entries are available in GROUPS. Return -1 and set errno if N is
530 not 0 and not large enough. Fails with ENOSYS on some systems. */
531 # if @REPLACE_GETGROUPS@
532 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
534 # define getgroups rpl_getgroups
536 _GL_FUNCDECL_RPL (getgroups, int, (int n, gid_t *groups));
537 _GL_CXXALIAS_RPL (getgroups, int, (int n, gid_t *groups));
539 # if !@HAVE_GETGROUPS@
540 _GL_FUNCDECL_SYS (getgroups, int, (int n, gid_t *groups));
542 _GL_CXXALIAS_SYS (getgroups, int, (int n, gid_t *groups));
544 _GL_CXXALIASWARN (getgroups);
545 #elif defined GNULIB_POSIXCHECK
547 # if HAVE_RAW_DECL_GETGROUPS
548 _GL_WARN_ON_USE (getgroups, "getgroups is unportable - "
549 "use gnulib module getgroups for portability");
554 #if @GNULIB_GETHOSTNAME@
555 /* Return the standard host name of the machine.
556 WARNING! The host name may or may not be fully qualified.
558 Put up to LEN bytes of the host name into NAME.
559 Null terminate it if the name is shorter than LEN.
560 If the host name is longer than LEN, set errno = EINVAL and return -1.
561 Return 0 if successful, otherwise set errno and return -1. */
562 # if @UNISTD_H_HAVE_WINSOCK2_H@
563 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
565 # define gethostname rpl_gethostname
567 _GL_FUNCDECL_RPL (gethostname, int, (char *name, size_t len)
568 _GL_ARG_NONNULL ((1)));
569 _GL_CXXALIAS_RPL (gethostname, int, (char *name, size_t len));
571 # if !@HAVE_GETHOSTNAME@
572 _GL_FUNCDECL_SYS (gethostname, int, (char *name, size_t len)
573 _GL_ARG_NONNULL ((1)));
575 /* Need to cast, because on Solaris 10 systems, the second parameter is
577 _GL_CXXALIAS_SYS_CAST (gethostname, int, (char *name, size_t len));
579 _GL_CXXALIASWARN (gethostname);
580 #elif @UNISTD_H_HAVE_WINSOCK2_H@
582 # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
583 #elif defined GNULIB_POSIXCHECK
585 # if HAVE_RAW_DECL_GETHOSTNAME
586 _GL_WARN_ON_USE (gethostname, "gethostname is unportable - "
587 "use gnulib module gethostname for portability");
592 #if @GNULIB_GETLOGIN@
593 /* Returns the user's login name, or NULL if it cannot be found. Upon error,
594 returns NULL with errno set.
596 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
598 Most programs don't need to use this function, because the information is
599 available through environment variables:
600 ${LOGNAME-$USER} on Unix platforms,
601 $USERNAME on native Windows platforms.
603 # if !@HAVE_GETLOGIN@
604 _GL_FUNCDECL_SYS (getlogin, char *, (void));
606 _GL_CXXALIAS_SYS (getlogin, char *, (void));
607 _GL_CXXALIASWARN (getlogin);
608 #elif defined GNULIB_POSIXCHECK
610 # if HAVE_RAW_DECL_GETLOGIN
611 _GL_WARN_ON_USE (getlogin, "getlogin is unportable - "
612 "use gnulib module getlogin for portability");
617 #if @GNULIB_GETLOGIN_R@
618 /* Copies the user's login name to NAME.
619 The array pointed to by NAME has room for SIZE bytes.
621 Returns 0 if successful. Upon error, an error number is returned, or -1 in
622 the case that the login name cannot be found but no specific error is
623 provided (this case is hopefully rare but is left open by the POSIX spec).
625 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
627 Most programs don't need to use this function, because the information is
628 available through environment variables:
629 ${LOGNAME-$USER} on Unix platforms,
630 $USERNAME on native Windows platforms.
632 # if !@HAVE_DECL_GETLOGIN_R@
633 _GL_FUNCDECL_SYS (getlogin_r, int, (char *name, size_t size)
634 _GL_ARG_NONNULL ((1)));
636 /* Need to cast, because on Solaris 10 systems, the second argument is
638 _GL_CXXALIAS_SYS_CAST (getlogin_r, int, (char *name, size_t size));
639 _GL_CXXALIASWARN (getlogin_r);
640 #elif defined GNULIB_POSIXCHECK
642 # if HAVE_RAW_DECL_GETLOGIN_R
643 _GL_WARN_ON_USE (getlogin_r, "getlogin_r is unportable - "
644 "use gnulib module getlogin_r for portability");
649 #if @GNULIB_GETPAGESIZE@
650 # if @REPLACE_GETPAGESIZE@
651 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
652 # define getpagesize rpl_getpagesize
654 _GL_FUNCDECL_RPL (getpagesize, int, (void));
655 _GL_CXXALIAS_RPL (getpagesize, int, (void));
657 # if !@HAVE_GETPAGESIZE@
658 # if !defined getpagesize
659 /* This is for POSIX systems. */
660 # if !defined _gl_getpagesize && defined _SC_PAGESIZE
661 # if ! (defined __VMS && __VMS_VER < 70000000)
662 # define _gl_getpagesize() sysconf (_SC_PAGESIZE)
665 /* This is for older VMS. */
666 # if !defined _gl_getpagesize && defined __VMS
668 # define _gl_getpagesize() 8192
670 # define _gl_getpagesize() 512
673 /* This is for BeOS. */
674 # if !defined _gl_getpagesize && @HAVE_OS_H@
676 # if defined B_PAGE_SIZE
677 # define _gl_getpagesize() B_PAGE_SIZE
680 /* This is for AmigaOS4.0. */
681 # if !defined _gl_getpagesize && defined __amigaos4__
682 # define _gl_getpagesize() 2048
684 /* This is for older Unix systems. */
685 # if !defined _gl_getpagesize && @HAVE_SYS_PARAM_H@
686 # include <sys/param.h>
687 # ifdef EXEC_PAGESIZE
688 # define _gl_getpagesize() EXEC_PAGESIZE
694 # define _gl_getpagesize() (NBPG * CLSIZE)
697 # define _gl_getpagesize() NBPC
702 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
703 # define getpagesize() _gl_getpagesize ()
708 return _gl_getpagesize ();
713 /* Need to cast, because on Cygwin 1.5.x systems, the return type is size_t. */
714 _GL_CXXALIAS_SYS_CAST (getpagesize, int, (void));
716 _GL_CXXALIASWARN (getpagesize);
717 #elif defined GNULIB_POSIXCHECK
719 # if HAVE_RAW_DECL_GETPAGESIZE
720 _GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - "
721 "use gnulib module getpagesize for portability");
726 #if @GNULIB_GETUSERSHELL@
727 /* Return the next valid login shell on the system, or NULL when the end of
728 the list has been reached. */
729 # if !@HAVE_DECL_GETUSERSHELL@
730 _GL_FUNCDECL_SYS (getusershell, char *, (void));
732 _GL_CXXALIAS_SYS (getusershell, char *, (void));
733 _GL_CXXALIASWARN (getusershell);
734 #elif defined GNULIB_POSIXCHECK
736 # if HAVE_RAW_DECL_GETUSERSHELL
737 _GL_WARN_ON_USE (getusershell, "getusershell is unportable - "
738 "use gnulib module getusershell for portability");
742 #if @GNULIB_GETUSERSHELL@
743 /* Rewind to pointer that is advanced at each getusershell() call. */
744 # if !@HAVE_DECL_GETUSERSHELL@
745 _GL_FUNCDECL_SYS (setusershell, void, (void));
747 _GL_CXXALIAS_SYS (setusershell, void, (void));
748 _GL_CXXALIASWARN (setusershell);
749 #elif defined GNULIB_POSIXCHECK
751 # if HAVE_RAW_DECL_SETUSERSHELL
752 _GL_WARN_ON_USE (setusershell, "setusershell is unportable - "
753 "use gnulib module getusershell for portability");
757 #if @GNULIB_GETUSERSHELL@
758 /* Free the pointer that is advanced at each getusershell() call and
759 associated resources. */
760 # if !@HAVE_DECL_GETUSERSHELL@
761 _GL_FUNCDECL_SYS (endusershell, void, (void));
763 _GL_CXXALIAS_SYS (endusershell, void, (void));
764 _GL_CXXALIASWARN (endusershell);
765 #elif defined GNULIB_POSIXCHECK
767 # if HAVE_RAW_DECL_ENDUSERSHELL
768 _GL_WARN_ON_USE (endusershell, "endusershell is unportable - "
769 "use gnulib module getusershell for portability");
775 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
776 to GID (if GID is not -1). Do not follow symbolic links.
777 Return 0 if successful, otherwise -1 and errno set.
778 See the POSIX:2001 specification
779 <http://www.opengroup.org/susv3xsh/lchown.html>. */
780 # if @REPLACE_LCHOWN@
781 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
783 # define lchown rpl_lchown
785 _GL_FUNCDECL_RPL (lchown, int, (char const *file, uid_t owner, gid_t group)
786 _GL_ARG_NONNULL ((1)));
787 _GL_CXXALIAS_RPL (lchown, int, (char const *file, uid_t owner, gid_t group));
790 _GL_FUNCDECL_SYS (lchown, int, (char const *file, uid_t owner, gid_t group)
791 _GL_ARG_NONNULL ((1)));
793 _GL_CXXALIAS_SYS (lchown, int, (char const *file, uid_t owner, gid_t group));
795 _GL_CXXALIASWARN (lchown);
796 #elif defined GNULIB_POSIXCHECK
798 # if HAVE_RAW_DECL_LCHOWN
799 _GL_WARN_ON_USE (lchown, "lchown is unportable to pre-POSIX.1-2001 systems - "
800 "use gnulib module lchown for portability");
806 /* Create a new hard link for an existing file.
807 Return 0 if successful, otherwise -1 and errno set.
808 See POSIX:2001 specification
809 <http://www.opengroup.org/susv3xsh/link.html>. */
811 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
812 # define link rpl_link
814 _GL_FUNCDECL_RPL (link, int, (const char *path1, const char *path2)
815 _GL_ARG_NONNULL ((1, 2)));
816 _GL_CXXALIAS_RPL (link, int, (const char *path1, const char *path2));
819 _GL_FUNCDECL_SYS (link, int, (const char *path1, const char *path2)
820 _GL_ARG_NONNULL ((1, 2)));
822 _GL_CXXALIAS_SYS (link, int, (const char *path1, const char *path2));
824 _GL_CXXALIASWARN (link);
825 #elif defined GNULIB_POSIXCHECK
827 # if HAVE_RAW_DECL_LINK
828 _GL_WARN_ON_USE (link, "link is unportable - "
829 "use gnulib module link for portability");
835 /* Create a new hard link for an existing file, relative to two
836 directories. FLAG controls whether symlinks are followed.
837 Return 0 if successful, otherwise -1 and errno set. */
838 # if @REPLACE_LINKAT@
839 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
841 # define linkat rpl_linkat
843 _GL_FUNCDECL_RPL (linkat, int,
844 (int fd1, const char *path1, int fd2, const char *path2,
846 _GL_ARG_NONNULL ((2, 4)));
847 _GL_CXXALIAS_RPL (linkat, int,
848 (int fd1, const char *path1, int fd2, const char *path2,
852 _GL_FUNCDECL_SYS (linkat, int,
853 (int fd1, const char *path1, int fd2, const char *path2,
855 _GL_ARG_NONNULL ((2, 4)));
857 _GL_CXXALIAS_SYS (linkat, int,
858 (int fd1, const char *path1, int fd2, const char *path2,
861 _GL_CXXALIASWARN (linkat);
862 #elif defined GNULIB_POSIXCHECK
864 # if HAVE_RAW_DECL_LINKAT
865 _GL_WARN_ON_USE (linkat, "linkat is unportable - "
866 "use gnulib module linkat for portability");
872 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
873 Return the new offset if successful, otherwise -1 and errno set.
874 See the POSIX:2001 specification
875 <http://www.opengroup.org/susv3xsh/lseek.html>. */
877 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
878 # define lseek rpl_lseek
880 _GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence));
881 _GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence));
883 _GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
885 _GL_CXXALIASWARN (lseek);
886 #elif defined GNULIB_POSIXCHECK
888 # if HAVE_RAW_DECL_LSEEK
889 _GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some "
890 "systems - use gnulib module lseek for portability");
896 /* Create a pipe, applying the given flags when opening the read-end of the
897 pipe and the write-end of the pipe.
898 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
899 and O_TEXT, O_BINARY (defined in "binary-io.h").
900 Store the read-end as fd[0] and the write-end as fd[1].
901 Return 0 upon success, or -1 with errno set upon failure.
902 See also the Linux man page at
903 <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */
905 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
906 # define pipe2 rpl_pipe2
908 _GL_FUNCDECL_RPL (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
909 _GL_CXXALIAS_RPL (pipe2, int, (int fd[2], int flags));
911 _GL_FUNCDECL_SYS (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
912 _GL_CXXALIAS_SYS (pipe2, int, (int fd[2], int flags));
914 _GL_CXXALIASWARN (pipe2);
915 #elif defined GNULIB_POSIXCHECK
917 # if HAVE_RAW_DECL_PIPE2
918 _GL_WARN_ON_USE (pipe2, "pipe2 is unportable - "
919 "use gnulib module pipe2 for portability");
925 /* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
926 Return the number of bytes placed into BUF if successful, otherwise
927 set errno and return -1. 0 indicates EOF. See the POSIX:2001
928 specification <http://www.opengroup.org/susv3xsh/pread.html>. */
930 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
931 # define pread rpl_pread
933 _GL_FUNCDECL_RPL (pread, ssize_t,
934 (int fd, void *buf, size_t bufsize, off_t offset)
935 _GL_ARG_NONNULL ((2)));
936 _GL_CXXALIAS_RPL (pread, ssize_t,
937 (int fd, void *buf, size_t bufsize, off_t offset));
940 _GL_FUNCDECL_SYS (pread, ssize_t,
941 (int fd, void *buf, size_t bufsize, off_t offset)
942 _GL_ARG_NONNULL ((2)));
944 _GL_CXXALIAS_SYS (pread, ssize_t,
945 (int fd, void *buf, size_t bufsize, off_t offset));
947 _GL_CXXALIASWARN (pread);
948 #elif defined GNULIB_POSIXCHECK
950 # if HAVE_RAW_DECL_PREAD
951 _GL_WARN_ON_USE (pread, "pread is unportable - "
952 "use gnulib module pread for portability");
957 #if @GNULIB_READLINK@
958 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
959 bytes of it into BUF. Return the number of bytes placed into BUF if
960 successful, otherwise -1 and errno set.
961 See the POSIX:2001 specification
962 <http://www.opengroup.org/susv3xsh/readlink.html>. */
963 # if @REPLACE_READLINK@
964 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
965 # define readlink rpl_readlink
967 _GL_FUNCDECL_RPL (readlink, ssize_t,
968 (const char *file, char *buf, size_t bufsize)
969 _GL_ARG_NONNULL ((1, 2)));
970 _GL_CXXALIAS_RPL (readlink, ssize_t,
971 (const char *file, char *buf, size_t bufsize));
973 # if !@HAVE_READLINK@
974 _GL_FUNCDECL_SYS (readlink, ssize_t,
975 (const char *file, char *buf, size_t bufsize)
976 _GL_ARG_NONNULL ((1, 2)));
978 _GL_CXXALIAS_SYS (readlink, ssize_t,
979 (const char *file, char *buf, size_t bufsize));
981 _GL_CXXALIASWARN (readlink);
982 #elif defined GNULIB_POSIXCHECK
984 # if HAVE_RAW_DECL_READLINK
985 _GL_WARN_ON_USE (readlink, "readlink is unportable - "
986 "use gnulib module readlink for portability");
991 #if @GNULIB_READLINKAT@
992 # if !@HAVE_READLINKAT@
993 _GL_FUNCDECL_SYS (readlinkat, ssize_t,
994 (int fd, char const *file, char *buf, size_t len)
995 _GL_ARG_NONNULL ((2, 3)));
997 _GL_CXXALIAS_SYS (readlinkat, ssize_t,
998 (int fd, char const *file, char *buf, size_t len));
999 _GL_CXXALIASWARN (readlinkat);
1000 #elif defined GNULIB_POSIXCHECK
1002 # if HAVE_RAW_DECL_READLINKAT
1003 _GL_WARN_ON_USE (readlinkat, "readlinkat is not portable - "
1004 "use gnulib module symlinkat for portability");
1010 /* Remove the directory DIR. */
1011 # if @REPLACE_RMDIR@
1012 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1013 # define rmdir rpl_rmdir
1015 _GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1)));
1016 _GL_CXXALIAS_RPL (rmdir, int, (char const *name));
1018 _GL_CXXALIAS_SYS (rmdir, int, (char const *name));
1020 _GL_CXXALIASWARN (rmdir);
1021 #elif defined GNULIB_POSIXCHECK
1023 # if HAVE_RAW_DECL_RMDIR
1024 _GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
1025 "use gnulib module rmdir for portability");
1031 /* Pause the execution of the current thread for N seconds.
1032 Returns the number of seconds left to sleep.
1033 See the POSIX:2001 specification
1034 <http://www.opengroup.org/susv3xsh/sleep.html>. */
1035 # if @REPLACE_SLEEP@
1036 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1038 # define sleep rpl_sleep
1040 _GL_FUNCDECL_RPL (sleep, unsigned int, (unsigned int n));
1041 _GL_CXXALIAS_RPL (sleep, unsigned int, (unsigned int n));
1044 _GL_FUNCDECL_SYS (sleep, unsigned int, (unsigned int n));
1046 _GL_CXXALIAS_SYS (sleep, unsigned int, (unsigned int n));
1048 _GL_CXXALIASWARN (sleep);
1049 #elif defined GNULIB_POSIXCHECK
1051 # if HAVE_RAW_DECL_SLEEP
1052 _GL_WARN_ON_USE (sleep, "sleep is unportable - "
1053 "use gnulib module sleep for portability");
1058 #if @GNULIB_SYMLINK@
1059 # if @REPLACE_SYMLINK@
1060 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1062 # define symlink rpl_symlink
1064 _GL_FUNCDECL_RPL (symlink, int, (char const *contents, char const *file)
1065 _GL_ARG_NONNULL ((1, 2)));
1066 _GL_CXXALIAS_RPL (symlink, int, (char const *contents, char const *file));
1068 # if !@HAVE_SYMLINK@
1069 _GL_FUNCDECL_SYS (symlink, int, (char const *contents, char const *file)
1070 _GL_ARG_NONNULL ((1, 2)));
1072 _GL_CXXALIAS_SYS (symlink, int, (char const *contents, char const *file));
1074 _GL_CXXALIASWARN (symlink);
1075 #elif defined GNULIB_POSIXCHECK
1077 # if HAVE_RAW_DECL_SYMLINK
1078 _GL_WARN_ON_USE (symlink, "symlink is not portable - "
1079 "use gnulib module symlink for portability");
1084 #if @GNULIB_SYMLINKAT@
1085 # if !@HAVE_SYMLINKAT@
1086 _GL_FUNCDECL_SYS (symlinkat, int,
1087 (char const *contents, int fd, char const *file)
1088 _GL_ARG_NONNULL ((1, 3)));
1090 _GL_CXXALIAS_SYS (symlinkat, int,
1091 (char const *contents, int fd, char const *file));
1092 _GL_CXXALIASWARN (symlinkat);
1093 #elif defined GNULIB_POSIXCHECK
1095 # if HAVE_RAW_DECL_SYMLINKAT
1096 _GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - "
1097 "use gnulib module symlinkat for portability");
1103 # if @REPLACE_UNLINK@
1104 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1106 # define unlink rpl_unlink
1108 _GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1)));
1109 _GL_CXXALIAS_RPL (unlink, int, (char const *file));
1111 _GL_CXXALIAS_SYS (unlink, int, (char const *file));
1113 _GL_CXXALIASWARN (unlink);
1114 #elif defined GNULIB_POSIXCHECK
1116 # if HAVE_RAW_DECL_UNLINK
1117 _GL_WARN_ON_USE (unlink, "unlink is not portable - "
1118 "use gnulib module unlink for portability");
1123 #if @GNULIB_UNLINKAT@
1124 # if @REPLACE_UNLINKAT@
1125 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1127 # define unlinkat rpl_unlinkat
1129 _GL_FUNCDECL_RPL (unlinkat, int, (int fd, char const *file, int flag)
1130 _GL_ARG_NONNULL ((2)));
1131 _GL_CXXALIAS_RPL (unlinkat, int, (int fd, char const *file, int flag));
1133 # if !@HAVE_UNLINKAT@
1134 _GL_FUNCDECL_SYS (unlinkat, int, (int fd, char const *file, int flag)
1135 _GL_ARG_NONNULL ((2)));
1137 _GL_CXXALIAS_SYS (unlinkat, int, (int fd, char const *file, int flag));
1139 _GL_CXXALIASWARN (unlinkat);
1140 #elif defined GNULIB_POSIXCHECK
1142 # if HAVE_RAW_DECL_UNLINKAT
1143 _GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
1144 "use gnulib module openat for portability");
1150 /* Pause the execution of the current thread for N microseconds.
1151 Returns 0 on completion, or -1 on range error.
1152 See the POSIX:2001 specification
1153 <http://www.opengroup.org/susv3xsh/sleep.html>. */
1154 # if @REPLACE_USLEEP@
1155 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1157 # define usleep rpl_usleep
1159 _GL_FUNCDECL_RPL (usleep, int, (useconds_t n));
1160 _GL_CXXALIAS_RPL (usleep, int, (useconds_t n));
1163 _GL_FUNCDECL_SYS (usleep, int, (useconds_t n));
1165 _GL_CXXALIAS_SYS (usleep, int, (useconds_t n));
1167 _GL_CXXALIASWARN (usleep);
1168 #elif defined GNULIB_POSIXCHECK
1170 # if HAVE_RAW_DECL_USLEEP
1171 _GL_WARN_ON_USE (usleep, "usleep is unportable - "
1172 "use gnulib module usleep for portability");
1178 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
1179 See the POSIX:2001 specification
1180 <http://www.opengroup.org/susv3xsh/write.html>. */
1181 # if @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
1182 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1184 # define write rpl_write
1186 _GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count)
1187 _GL_ARG_NONNULL ((2)));
1188 _GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count));
1190 _GL_CXXALIAS_SYS (write, ssize_t, (int fd, const void *buf, size_t count));
1192 _GL_CXXALIASWARN (write);
1196 #endif /* _GL_UNISTD_H */
1197 #endif /* _GL_UNISTD_H */