1 /* Substitute for and wrapper around <unistd.h>.
2 Copyright (C) 2003-2020 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, see <https://www.gnu.org/licenses/>. */
17 #ifndef _@GUARD_PREFIX@_UNISTD_H
20 @PRAGMA_SYSTEM_HEADER@
24 #if @HAVE_UNISTD_H@ && defined _GL_INCLUDING_UNISTD_H
25 /* Special invocation convention:
26 - On Mac OS X 10.3.9 we have a sequence of nested includes
27 <unistd.h> -> <signal.h> -> <pthread.h> -> <unistd.h>
28 In this situation, the functions are not yet declared, therefore we cannot
29 provide the C++ aliases. */
31 #@INCLUDE_NEXT@ @NEXT_UNISTD_H@
34 /* Normal invocation convention. */
36 /* The include_next requires a split double-inclusion guard. */
38 # define _GL_INCLUDING_UNISTD_H
39 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
40 # undef _GL_INCLUDING_UNISTD_H
43 /* Get all possible declarations of gethostname(). */
44 #if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \
45 && !defined _GL_INCLUDING_WINSOCK2_H
46 # define _GL_INCLUDING_WINSOCK2_H
47 # include <winsock2.h>
48 # undef _GL_INCLUDING_WINSOCK2_H
51 #if !defined _@GUARD_PREFIX@_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H
52 #define _@GUARD_PREFIX@_UNISTD_H
54 /* NetBSD 5.0 mis-defines NULL. Also get size_t. */
55 /* But avoid namespace pollution on glibc systems. */
60 /* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */
61 /* MSVC declares 'unlink' in <stdio.h>, not in <unistd.h>. We must include
62 it before we #define unlink rpl_unlink. */
63 /* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>. */
64 /* But avoid namespace pollution on glibc systems. */
65 #if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
66 || ((@GNULIB_UNLINK@ || defined GNULIB_POSIXCHECK) \
67 && (defined _WIN32 && ! defined __CYGWIN__)) \
68 || ((@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK) \
69 && defined __CYGWIN__)) \
70 && ! defined __GLIBC__
74 /* Cygwin 1.7.1 and Android 4.3 declare unlinkat in <fcntl.h>, not in
76 /* But avoid namespace pollution on glibc systems. */
77 #if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) \
78 && (defined __CYGWIN__ || defined __ANDROID__) \
79 && ! defined __GLIBC__
83 /* mingw fails to declare _exit in <unistd.h>. */
84 /* mingw, MSVC, BeOS, Haiku declare environ in <stdlib.h>, not in
86 /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */
87 /* OSF Tru64 Unix cannot see gnulib rpl_strtod when system <stdlib.h> is
89 /* But avoid namespace pollution on glibc systems. */
90 #if !defined __GLIBC__ && !defined __osf__
91 # define __need_system_stdlib_h
93 # undef __need_system_stdlib_h
96 /* Native Windows platforms declare chdir, getcwd, rmdir in
97 <io.h> and/or <direct.h>, not in <unistd.h>.
98 They also declare access(), chmod(), close(), dup(), dup2(), isatty(),
99 lseek(), read(), unlink(), write() in <io.h>. */
100 #if ((@GNULIB_CHDIR@ || @GNULIB_GETCWD@ || @GNULIB_RMDIR@ \
101 || defined GNULIB_POSIXCHECK) \
102 && (defined _WIN32 && ! defined __CYGWIN__))
103 # include <io.h> /* mingw32, mingw64 */
104 # include <direct.h> /* mingw64, MSVC 9 */
105 #elif (@GNULIB_CLOSE@ || @GNULIB_DUP@ || @GNULIB_DUP2@ || @GNULIB_ISATTY@ \
106 || @GNULIB_LSEEK@ || @GNULIB_READ@ || @GNULIB_UNLINK@ || @GNULIB_WRITE@ \
107 || defined GNULIB_POSIXCHECK) \
108 && (defined _WIN32 && ! defined __CYGWIN__)
112 /* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.
113 NonStop Kernel declares gethostname in <netdb.h>, not in <unistd.h>. */
114 /* But avoid namespace pollution on glibc systems. */
115 #if ((@GNULIB_GETDOMAINNAME@ && (defined _AIX || defined __osf__)) \
116 || (@GNULIB_GETHOSTNAME@ && defined __TANDEM)) \
117 && !defined __GLIBC__
121 /* Android 4.3 declares fchownat in <sys/stat.h>, not in <unistd.h>. */
122 /* But avoid namespace pollution on glibc systems. */
123 #if (@GNULIB_FCHOWNAT@ || defined GNULIB_POSIXCHECK) && defined __ANDROID__ \
124 && !defined __GLIBC__
125 # include <sys/stat.h>
128 /* MSVC defines off_t in <sys/types.h>.
129 May also define off_t to a 64-bit type on native Windows. */
130 /* But avoid namespace pollution on glibc systems. */
132 /* Get off_t, ssize_t. */
133 # include <sys/types.h>
136 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
138 /* The definition of _GL_ARG_NONNULL is copied here. */
140 /* The definition of _GL_WARN_ON_USE is copied here. */
143 /* Get getopt(), optarg, optind, opterr, optopt. */
144 #if @GNULIB_GETOPT_POSIX@ && @GNULIB_UNISTD_H_GETOPT@ && !defined _GL_SYSTEM_GETOPT
145 # include <getopt-cdefs.h>
146 # include <getopt-pfx-core.h>
149 #ifndef _GL_INLINE_HEADER_BEGIN
150 #error "Please include config.h first."
152 _GL_INLINE_HEADER_BEGIN
153 #ifndef _GL_UNISTD_INLINE
154 # define _GL_UNISTD_INLINE _GL_INLINE
157 /* Hide some function declarations from <winsock2.h>. */
159 #if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@
160 # if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
161 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
163 # define socket socket_used_without_including_sys_socket_h
165 # define connect connect_used_without_including_sys_socket_h
167 # define accept accept_used_without_including_sys_socket_h
169 # define bind bind_used_without_including_sys_socket_h
171 # define getpeername getpeername_used_without_including_sys_socket_h
173 # define getsockname getsockname_used_without_including_sys_socket_h
175 # define getsockopt getsockopt_used_without_including_sys_socket_h
177 # define listen listen_used_without_including_sys_socket_h
179 # define recv recv_used_without_including_sys_socket_h
181 # define send send_used_without_including_sys_socket_h
183 # define recvfrom recvfrom_used_without_including_sys_socket_h
185 # define sendto sendto_used_without_including_sys_socket_h
187 # define setsockopt setsockopt_used_without_including_sys_socket_h
189 # define shutdown shutdown_used_without_including_sys_socket_h
191 _GL_WARN_ON_USE (socket
,
192 "socket() used without including <sys/socket.h>");
193 _GL_WARN_ON_USE (connect
,
194 "connect() used without including <sys/socket.h>");
195 _GL_WARN_ON_USE (accept
,
196 "accept() used without including <sys/socket.h>");
197 _GL_WARN_ON_USE (bind
,
198 "bind() used without including <sys/socket.h>");
199 _GL_WARN_ON_USE (getpeername
,
200 "getpeername() used without including <sys/socket.h>");
201 _GL_WARN_ON_USE (getsockname
,
202 "getsockname() used without including <sys/socket.h>");
203 _GL_WARN_ON_USE (getsockopt
,
204 "getsockopt() used without including <sys/socket.h>");
205 _GL_WARN_ON_USE (listen
,
206 "listen() used without including <sys/socket.h>");
207 _GL_WARN_ON_USE (recv
,
208 "recv() used without including <sys/socket.h>");
209 _GL_WARN_ON_USE (send
,
210 "send() used without including <sys/socket.h>");
211 _GL_WARN_ON_USE (recvfrom
,
212 "recvfrom() used without including <sys/socket.h>");
213 _GL_WARN_ON_USE (sendto
,
214 "sendto() used without including <sys/socket.h>");
215 _GL_WARN_ON_USE (setsockopt
,
216 "setsockopt() used without including <sys/socket.h>");
217 _GL_WARN_ON_USE (shutdown
,
218 "shutdown() used without including <sys/socket.h>");
221 # if !defined _@GUARD_PREFIX@_SYS_SELECT_H
222 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
224 # define select select_used_without_including_sys_select_h
226 _GL_WARN_ON_USE (select
,
227 "select() used without including <sys/select.h>");
233 /* OS/2 EMX lacks these macros. */
235 # define STDIN_FILENO 0
237 #ifndef STDOUT_FILENO
238 # define STDOUT_FILENO 1
240 #ifndef STDERR_FILENO
241 # define STDERR_FILENO 2
244 /* Ensure *_OK macros exist. */
253 /* Declare overridden functions. */
257 # if @REPLACE_ACCESS@
258 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
260 # define access rpl_access
262 _GL_FUNCDECL_RPL (access
, int, (const char *file
, int mode
)
263 _GL_ARG_NONNULL ((1)));
264 _GL_CXXALIAS_RPL (access
, int, (const char *file
, int mode
));
266 _GL_CXXALIAS_SYS (access
, int, (const char *file
, int mode
));
268 _GL_CXXALIASWARN (access
);
269 #elif defined GNULIB_POSIXCHECK
271 # if HAVE_RAW_DECL_ACCESS
272 /* The access() function is a security risk. */
273 _GL_WARN_ON_USE (access
, "access does not always support X_OK - "
274 "use gnulib module access for portability; "
275 "also, this function is a security risk - "
276 "use the gnulib module faccessat instead");
282 _GL_CXXALIAS_SYS (chdir
, int, (const char *file
) _GL_ARG_NONNULL ((1)));
283 _GL_CXXALIASWARN (chdir
);
284 #elif defined GNULIB_POSIXCHECK
286 # if HAVE_RAW_DECL_CHDIR
287 _GL_WARN_ON_USE (chown
, "chdir is not always in <unistd.h> - "
288 "use gnulib module chdir for portability");
294 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
295 to GID (if GID is not -1). Follow symbolic links.
296 Return 0 if successful, otherwise -1 and errno set.
297 See the POSIX:2008 specification
298 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/chown.html. */
300 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
302 # define chown rpl_chown
304 _GL_FUNCDECL_RPL (chown
, int, (const char *file
, uid_t uid
, gid_t gid
)
305 _GL_ARG_NONNULL ((1)));
306 _GL_CXXALIAS_RPL (chown
, int, (const char *file
, uid_t uid
, gid_t gid
));
309 _GL_FUNCDECL_SYS (chown
, int, (const char *file
, uid_t uid
, gid_t gid
)
310 _GL_ARG_NONNULL ((1)));
312 _GL_CXXALIAS_SYS (chown
, int, (const char *file
, uid_t uid
, gid_t gid
));
314 _GL_CXXALIASWARN (chown
);
315 #elif defined GNULIB_POSIXCHECK
317 # if HAVE_RAW_DECL_CHOWN
318 _GL_WARN_ON_USE (chown
, "chown fails to follow symlinks on some systems and "
319 "doesn't treat a uid or gid of -1 on some systems - "
320 "use gnulib module chown for portability");
327 /* Automatically included by modules that need a replacement for close. */
328 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
330 # define close rpl_close
332 _GL_FUNCDECL_RPL (close
, int, (int fd
));
333 _GL_CXXALIAS_RPL (close
, int, (int fd
));
335 _GL_CXXALIAS_SYS (close
, int, (int fd
));
337 _GL_CXXALIASWARN (close
);
338 #elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
340 # define close close_used_without_requesting_gnulib_module_close
341 #elif defined GNULIB_POSIXCHECK
343 /* Assume close is always declared. */
344 _GL_WARN_ON_USE (close
, "close does not portably work on sockets - "
345 "use gnulib module close for portability");
349 #if @GNULIB_COPY_FILE_RANGE@
350 # if !@HAVE_COPY_FILE_RANGE@
351 _GL_FUNCDECL_SYS (copy_file_range
, ssize_t
, (int ifd
, off_t
*ipos
,
352 int ofd
, off_t
*opos
,
353 size_t len
, unsigned flags
));
354 _GL_CXXALIAS_SYS (copy_file_range
, ssize_t
, (int ifd
, off_t
*ipos
,
355 int ofd
, off_t
*opos
,
356 size_t len
, unsigned flags
));
358 _GL_CXXALIASWARN (copy_file_range
);
359 #elif defined GNULIB_POSIXCHECK
360 /* Assume copy_file_range is always declared. */
361 _GL_WARN_ON_USE (copy_file_range
,
362 "copy_file_range is unportable - "
363 "use gnulib module copy_file_range for portability");
369 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
372 _GL_FUNCDECL_RPL (dup
, int, (int oldfd
));
373 _GL_CXXALIAS_RPL (dup
, int, (int oldfd
));
375 _GL_CXXALIAS_SYS (dup
, int, (int oldfd
));
377 _GL_CXXALIASWARN (dup
);
378 #elif defined GNULIB_POSIXCHECK
380 # if HAVE_RAW_DECL_DUP
381 _GL_WARN_ON_USE (dup
, "dup is unportable - "
382 "use gnulib module dup for portability");
388 /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
389 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
390 Return newfd if successful, otherwise -1 and errno set.
391 See the POSIX:2008 specification
392 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html>. */
394 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
395 # define dup2 rpl_dup2
397 _GL_FUNCDECL_RPL (dup2
, int, (int oldfd
, int newfd
));
398 _GL_CXXALIAS_RPL (dup2
, int, (int oldfd
, int newfd
));
401 _GL_FUNCDECL_SYS (dup2
, int, (int oldfd
, int newfd
));
403 _GL_CXXALIAS_SYS (dup2
, int, (int oldfd
, int newfd
));
405 _GL_CXXALIASWARN (dup2
);
406 #elif defined GNULIB_POSIXCHECK
408 # if HAVE_RAW_DECL_DUP2
409 _GL_WARN_ON_USE (dup2
, "dup2 is unportable - "
410 "use gnulib module dup2 for portability");
416 /* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
418 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
419 and O_TEXT, O_BINARY (defined in "binary-io.h").
420 Close NEWFD first if it is open.
421 Return newfd if successful, otherwise -1 and errno set.
422 See the Linux man page at
423 <https://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */
425 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
426 # define dup3 rpl_dup3
428 _GL_FUNCDECL_RPL (dup3
, int, (int oldfd
, int newfd
, int flags
));
429 _GL_CXXALIAS_RPL (dup3
, int, (int oldfd
, int newfd
, int flags
));
431 _GL_FUNCDECL_SYS (dup3
, int, (int oldfd
, int newfd
, int flags
));
432 _GL_CXXALIAS_SYS (dup3
, int, (int oldfd
, int newfd
, int flags
));
434 _GL_CXXALIASWARN (dup3
);
435 #elif defined GNULIB_POSIXCHECK
437 # if HAVE_RAW_DECL_DUP3
438 _GL_WARN_ON_USE (dup3
, "dup3 is unportable - "
439 "use gnulib module dup3 for portability");
445 # if defined __CYGWIN__ && !defined __i386__
446 /* The 'environ' variable is defined in a DLL. Therefore its declaration needs
447 the '__declspec(dllimport)' attribute, but the system's <unistd.h> lacks it.
448 This leads to a link error on 64-bit Cygwin when the option
449 -Wl,--disable-auto-import is in use. */
450 _GL_EXTERN_C
__declspec(dllimport
) char **environ
;
452 # if !@HAVE_DECL_ENVIRON@
453 /* Set of environment variables and values. An array of strings of the form
454 "VARIABLE=VALUE", terminated with a NULL. */
455 # if defined __APPLE__ && defined __MACH__
456 # include <TargetConditionals.h>
457 # if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
458 # define _GL_USE_CRT_EXTERNS
461 # ifdef _GL_USE_CRT_EXTERNS
462 # include <crt_externs.h>
463 # define environ (*_NSGetEnviron ())
468 extern char **environ
;
474 #elif defined GNULIB_POSIXCHECK
475 # if HAVE_RAW_DECL_ENVIRON
476 _GL_UNISTD_INLINE
char ***
477 _GL_WARN_ON_USE_ATTRIBUTE ("environ is unportable - "
478 "use gnulib module environ for portability")
484 # define environ (*rpl_environ ())
489 #if @GNULIB_EUIDACCESS@
490 /* Like access(), except that it uses the effective user id and group id of
491 the current process. */
492 # if !@HAVE_EUIDACCESS@
493 _GL_FUNCDECL_SYS (euidaccess
, int, (const char *filename
, int mode
)
494 _GL_ARG_NONNULL ((1)));
496 _GL_CXXALIAS_SYS (euidaccess
, int, (const char *filename
, int mode
));
497 _GL_CXXALIASWARN (euidaccess
);
498 # if defined GNULIB_POSIXCHECK
499 /* Like access(), this function is a security risk. */
500 _GL_WARN_ON_USE (euidaccess
, "the euidaccess function is a security risk - "
501 "use the gnulib module faccessat instead");
503 #elif defined GNULIB_POSIXCHECK
505 # if HAVE_RAW_DECL_EUIDACCESS
506 _GL_WARN_ON_USE (euidaccess
, "euidaccess is unportable - "
507 "use gnulib module euidaccess for portability");
512 #if @GNULIB_FACCESSAT@
513 # if @REPLACE_FACCESSAT@
514 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
516 # define faccessat rpl_faccessat
518 _GL_FUNCDECL_RPL (faccessat
, int,
519 (int fd
, char const *name
, int mode
, int flag
)
520 _GL_ARG_NONNULL ((2)));
521 _GL_CXXALIAS_RPL (faccessat
, int,
522 (int fd
, char const *name
, int mode
, int flag
));
524 # if !@HAVE_FACCESSAT@
525 _GL_FUNCDECL_SYS (faccessat
, int,
526 (int fd
, char const *file
, int mode
, int flag
)
527 _GL_ARG_NONNULL ((2)));
529 _GL_CXXALIAS_SYS (faccessat
, int,
530 (int fd
, char const *file
, int mode
, int flag
));
532 _GL_CXXALIASWARN (faccessat
);
533 #elif defined GNULIB_POSIXCHECK
535 # if HAVE_RAW_DECL_FACCESSAT
536 _GL_WARN_ON_USE (faccessat
, "faccessat is not portable - "
537 "use gnulib module faccessat for portability");
543 /* Change the process' current working directory to the directory on which
544 the given file descriptor is open.
545 Return 0 if successful, otherwise -1 and errno set.
546 See the POSIX:2008 specification
547 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html>. */
549 _GL_FUNCDECL_SYS (fchdir
, int, (int /*fd*/));
551 /* Gnulib internal hooks needed to maintain the fchdir metadata. */
552 _GL_EXTERN_C
int _gl_register_fd (int fd
, const char *filename
)
553 _GL_ARG_NONNULL ((2));
554 _GL_EXTERN_C
void _gl_unregister_fd (int fd
);
555 _GL_EXTERN_C
int _gl_register_dup (int oldfd
, int newfd
);
556 _GL_EXTERN_C
const char *_gl_directory_name (int fd
);
559 # if !@HAVE_DECL_FCHDIR@
560 _GL_FUNCDECL_SYS (fchdir
, int, (int /*fd*/));
563 _GL_CXXALIAS_SYS (fchdir
, int, (int /*fd*/));
564 _GL_CXXALIASWARN (fchdir
);
565 #elif defined GNULIB_POSIXCHECK
567 # if HAVE_RAW_DECL_FCHDIR
568 _GL_WARN_ON_USE (fchdir
, "fchdir is unportable - "
569 "use gnulib module fchdir for portability");
574 #if @GNULIB_FCHOWNAT@
575 # if @REPLACE_FCHOWNAT@
576 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
578 # define fchownat rpl_fchownat
580 _GL_FUNCDECL_RPL (fchownat
, int, (int fd
, char const *file
,
581 uid_t owner
, gid_t group
, int flag
)
582 _GL_ARG_NONNULL ((2)));
583 _GL_CXXALIAS_RPL (fchownat
, int, (int fd
, char const *file
,
584 uid_t owner
, gid_t group
, int flag
));
586 # if !@HAVE_FCHOWNAT@
587 _GL_FUNCDECL_SYS (fchownat
, int, (int fd
, char const *file
,
588 uid_t owner
, gid_t group
, int flag
)
589 _GL_ARG_NONNULL ((2)));
591 _GL_CXXALIAS_SYS (fchownat
, int, (int fd
, char const *file
,
592 uid_t owner
, gid_t group
, int flag
));
594 _GL_CXXALIASWARN (fchownat
);
595 #elif defined GNULIB_POSIXCHECK
597 # if HAVE_RAW_DECL_FCHOWNAT
598 _GL_WARN_ON_USE (fchownat
, "fchownat is not portable - "
599 "use gnulib module openat for portability");
604 #if @GNULIB_FDATASYNC@
605 /* Synchronize changes to a file.
606 Return 0 if successful, otherwise -1 and errno set.
607 See POSIX:2008 specification
608 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html>. */
609 # if !@HAVE_FDATASYNC@ || !@HAVE_DECL_FDATASYNC@
610 _GL_FUNCDECL_SYS (fdatasync
, int, (int fd
));
612 _GL_CXXALIAS_SYS (fdatasync
, int, (int fd
));
613 _GL_CXXALIASWARN (fdatasync
);
614 #elif defined GNULIB_POSIXCHECK
616 # if HAVE_RAW_DECL_FDATASYNC
617 _GL_WARN_ON_USE (fdatasync
, "fdatasync is unportable - "
618 "use gnulib module fdatasync for portability");
624 /* Synchronize changes, including metadata, to a file.
625 Return 0 if successful, otherwise -1 and errno set.
626 See POSIX:2008 specification
627 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html>. */
629 _GL_FUNCDECL_SYS (fsync
, int, (int fd
));
631 _GL_CXXALIAS_SYS (fsync
, int, (int fd
));
632 _GL_CXXALIASWARN (fsync
);
633 #elif defined GNULIB_POSIXCHECK
635 # if HAVE_RAW_DECL_FSYNC
636 _GL_WARN_ON_USE (fsync
, "fsync is unportable - "
637 "use gnulib module fsync for portability");
642 #if @GNULIB_FTRUNCATE@
643 /* Change the size of the file to which FD is opened to become equal to LENGTH.
644 Return 0 if successful, otherwise -1 and errno set.
645 See the POSIX:2008 specification
646 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html>. */
647 # if @REPLACE_FTRUNCATE@
648 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
650 # define ftruncate rpl_ftruncate
652 _GL_FUNCDECL_RPL (ftruncate
, int, (int fd
, off_t length
));
653 _GL_CXXALIAS_RPL (ftruncate
, int, (int fd
, off_t length
));
655 # if !@HAVE_FTRUNCATE@
656 _GL_FUNCDECL_SYS (ftruncate
, int, (int fd
, off_t length
));
658 _GL_CXXALIAS_SYS (ftruncate
, int, (int fd
, off_t length
));
660 _GL_CXXALIASWARN (ftruncate
);
661 #elif defined GNULIB_POSIXCHECK
663 # if HAVE_RAW_DECL_FTRUNCATE
664 _GL_WARN_ON_USE (ftruncate
, "ftruncate is unportable - "
665 "use gnulib module ftruncate for portability");
671 /* Get the name of the current working directory, and put it in SIZE bytes
673 Return BUF if successful, or NULL if the directory couldn't be determined
674 or SIZE was too small.
675 See the POSIX:2008 specification
676 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html>.
677 Additionally, the gnulib module 'getcwd' guarantees the following GNU
678 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
679 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
681 # if @REPLACE_GETCWD@
682 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
683 # define getcwd rpl_getcwd
685 _GL_FUNCDECL_RPL (getcwd
, char *, (char *buf
, size_t size
));
686 _GL_CXXALIAS_RPL (getcwd
, char *, (char *buf
, size_t size
));
688 /* Need to cast, because on mingw, the second parameter is
690 _GL_CXXALIAS_SYS_CAST (getcwd
, char *, (char *buf
, size_t size
));
692 _GL_CXXALIASWARN (getcwd
);
693 #elif defined GNULIB_POSIXCHECK
695 # if HAVE_RAW_DECL_GETCWD
696 _GL_WARN_ON_USE (getcwd
, "getcwd is unportable - "
697 "use gnulib module getcwd for portability");
702 #if @GNULIB_GETDOMAINNAME@
703 /* Return the NIS domain name of the machine.
704 WARNING! The NIS domain name is unrelated to the fully qualified host name
705 of the machine. It is also unrelated to email addresses.
706 WARNING! The NIS domain name is usually the empty string or "(none)" when
709 Put up to LEN bytes of the NIS domain name into NAME.
710 Null terminate it if the name is shorter than LEN.
711 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
712 Return 0 if successful, otherwise set errno and return -1. */
713 # if @REPLACE_GETDOMAINNAME@
714 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
715 # undef getdomainname
716 # define getdomainname rpl_getdomainname
718 _GL_FUNCDECL_RPL (getdomainname
, int, (char *name
, size_t len
)
719 _GL_ARG_NONNULL ((1)));
720 _GL_CXXALIAS_RPL (getdomainname
, int, (char *name
, size_t len
));
722 # if !@HAVE_DECL_GETDOMAINNAME@
723 _GL_FUNCDECL_SYS (getdomainname
, int, (char *name
, size_t len
)
724 _GL_ARG_NONNULL ((1)));
726 _GL_CXXALIAS_SYS (getdomainname
, int, (char *name
, size_t len
));
728 _GL_CXXALIASWARN (getdomainname
);
729 #elif defined GNULIB_POSIXCHECK
730 # undef getdomainname
731 # if HAVE_RAW_DECL_GETDOMAINNAME
732 _GL_WARN_ON_USE (getdomainname
, "getdomainname is unportable - "
733 "use gnulib module getdomainname for portability");
738 #if @GNULIB_GETDTABLESIZE@
739 /* Return the maximum number of file descriptors in the current process.
740 In POSIX, this is same as sysconf (_SC_OPEN_MAX). */
741 # if @REPLACE_GETDTABLESIZE@
742 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
743 # undef getdtablesize
744 # define getdtablesize rpl_getdtablesize
746 _GL_FUNCDECL_RPL (getdtablesize
, int, (void));
747 _GL_CXXALIAS_RPL (getdtablesize
, int, (void));
749 # if !@HAVE_GETDTABLESIZE@
750 _GL_FUNCDECL_SYS (getdtablesize
, int, (void));
752 /* Need to cast, because on AIX, the parameter list is
754 _GL_CXXALIAS_SYS_CAST (getdtablesize
, int, (void));
756 _GL_CXXALIASWARN (getdtablesize
);
757 #elif defined GNULIB_POSIXCHECK
758 # undef getdtablesize
759 # if HAVE_RAW_DECL_GETDTABLESIZE
760 _GL_WARN_ON_USE (getdtablesize
, "getdtablesize is unportable - "
761 "use gnulib module getdtablesize for portability");
766 #if @GNULIB_GETGROUPS@
767 /* Return the supplemental groups that the current process belongs to.
768 It is unspecified whether the effective group id is in the list.
769 If N is 0, return the group count; otherwise, N describes how many
770 entries are available in GROUPS. Return -1 and set errno if N is
771 not 0 and not large enough. Fails with ENOSYS on some systems. */
772 # if @REPLACE_GETGROUPS@
773 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
775 # define getgroups rpl_getgroups
777 _GL_FUNCDECL_RPL (getgroups
, int, (int n
, gid_t
*groups
));
778 _GL_CXXALIAS_RPL (getgroups
, int, (int n
, gid_t
*groups
));
780 # if !@HAVE_GETGROUPS@
781 _GL_FUNCDECL_SYS (getgroups
, int, (int n
, gid_t
*groups
));
783 _GL_CXXALIAS_SYS (getgroups
, int, (int n
, gid_t
*groups
));
785 _GL_CXXALIASWARN (getgroups
);
786 #elif defined GNULIB_POSIXCHECK
788 # if HAVE_RAW_DECL_GETGROUPS
789 _GL_WARN_ON_USE (getgroups
, "getgroups is unportable - "
790 "use gnulib module getgroups for portability");
795 #if @GNULIB_GETHOSTNAME@
796 /* Return the standard host name of the machine.
797 WARNING! The host name may or may not be fully qualified.
799 Put up to LEN bytes of the host name into NAME.
800 Null terminate it if the name is shorter than LEN.
801 If the host name is longer than LEN, set errno = EINVAL and return -1.
802 Return 0 if successful, otherwise set errno and return -1. */
803 # if @UNISTD_H_HAVE_WINSOCK2_H@
804 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
806 # define gethostname rpl_gethostname
808 _GL_FUNCDECL_RPL (gethostname
, int, (char *name
, size_t len
)
809 _GL_ARG_NONNULL ((1)));
810 _GL_CXXALIAS_RPL (gethostname
, int, (char *name
, size_t len
));
812 # if !@HAVE_GETHOSTNAME@
813 _GL_FUNCDECL_SYS (gethostname
, int, (char *name
, size_t len
)
814 _GL_ARG_NONNULL ((1)));
816 /* Need to cast, because on Solaris 10 and OSF/1 5.1 systems, the second
819 _GL_CXXALIAS_SYS_CAST (gethostname
, int, (char *name
, size_t len
));
821 _GL_CXXALIASWARN (gethostname
);
822 #elif @UNISTD_H_HAVE_WINSOCK2_H@
824 # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
825 #elif defined GNULIB_POSIXCHECK
827 # if HAVE_RAW_DECL_GETHOSTNAME
828 _GL_WARN_ON_USE (gethostname
, "gethostname is unportable - "
829 "use gnulib module gethostname for portability");
834 #if @GNULIB_GETLOGIN@
835 /* Returns the user's login name, or NULL if it cannot be found. Upon error,
836 returns NULL with errno set.
838 See <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getlogin.html>.
840 Most programs don't need to use this function, because the information is
841 available through environment variables:
842 ${LOGNAME-$USER} on Unix platforms,
843 $USERNAME on native Windows platforms.
845 # if !@HAVE_DECL_GETLOGIN@
846 _GL_FUNCDECL_SYS (getlogin
, char *, (void));
848 _GL_CXXALIAS_SYS (getlogin
, char *, (void));
849 _GL_CXXALIASWARN (getlogin
);
850 #elif defined GNULIB_POSIXCHECK
852 # if HAVE_RAW_DECL_GETLOGIN
853 _GL_WARN_ON_USE (getlogin
, "getlogin is unportable - "
854 "use gnulib module getlogin for portability");
859 #if @GNULIB_GETLOGIN_R@
860 /* Copies the user's login name to NAME.
861 The array pointed to by NAME has room for SIZE bytes.
863 Returns 0 if successful. Upon error, an error number is returned, or -1 in
864 the case that the login name cannot be found but no specific error is
865 provided (this case is hopefully rare but is left open by the POSIX spec).
867 See <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getlogin.html>.
869 Most programs don't need to use this function, because the information is
870 available through environment variables:
871 ${LOGNAME-$USER} on Unix platforms,
872 $USERNAME on native Windows platforms.
874 # if @REPLACE_GETLOGIN_R@
875 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
876 # define getlogin_r rpl_getlogin_r
878 _GL_FUNCDECL_RPL (getlogin_r
, int, (char *name
, size_t size
)
879 _GL_ARG_NONNULL ((1)));
880 _GL_CXXALIAS_RPL (getlogin_r
, int, (char *name
, size_t size
));
882 # if !@HAVE_DECL_GETLOGIN_R@
883 _GL_FUNCDECL_SYS (getlogin_r
, int, (char *name
, size_t size
)
884 _GL_ARG_NONNULL ((1)));
886 /* Need to cast, because on Solaris 10 systems, the second argument is
888 _GL_CXXALIAS_SYS_CAST (getlogin_r
, int, (char *name
, size_t size
));
890 _GL_CXXALIASWARN (getlogin_r
);
891 #elif defined GNULIB_POSIXCHECK
893 # if HAVE_RAW_DECL_GETLOGIN_R
894 _GL_WARN_ON_USE (getlogin_r
, "getlogin_r is unportable - "
895 "use gnulib module getlogin_r for portability");
900 #if @GNULIB_GETPAGESIZE@
901 # if @REPLACE_GETPAGESIZE@
902 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
903 # define getpagesize rpl_getpagesize
905 _GL_FUNCDECL_RPL (getpagesize
, int, (void));
906 _GL_CXXALIAS_RPL (getpagesize
, int, (void));
908 /* On HP-UX, getpagesize exists, but it is not declared in <unistd.h> even if
909 the compiler options -D_HPUX_SOURCE -D_XOPEN_SOURCE=600 are used. */
911 _GL_FUNCDECL_SYS (getpagesize
, int, (void));
913 # if !@HAVE_GETPAGESIZE@
914 # if !defined getpagesize
915 /* This is for POSIX systems. */
916 # if !defined _gl_getpagesize && defined _SC_PAGESIZE
917 # if ! (defined __VMS && __VMS_VER < 70000000)
918 # define _gl_getpagesize() sysconf (_SC_PAGESIZE)
921 /* This is for older VMS. */
922 # if !defined _gl_getpagesize && defined __VMS
924 # define _gl_getpagesize() 8192
926 # define _gl_getpagesize() 512
929 /* This is for BeOS. */
930 # if !defined _gl_getpagesize && @HAVE_OS_H@
932 # if defined B_PAGE_SIZE
933 # define _gl_getpagesize() B_PAGE_SIZE
936 /* This is for AmigaOS4.0. */
937 # if !defined _gl_getpagesize && defined __amigaos4__
938 # define _gl_getpagesize() 2048
940 /* This is for older Unix systems. */
941 # if !defined _gl_getpagesize && @HAVE_SYS_PARAM_H@
942 # include <sys/param.h>
943 # ifdef EXEC_PAGESIZE
944 # define _gl_getpagesize() EXEC_PAGESIZE
950 # define _gl_getpagesize() (NBPG * CLSIZE)
953 # define _gl_getpagesize() NBPC
958 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
959 # define getpagesize() _gl_getpagesize ()
961 # if !GNULIB_defined_getpagesize_function
962 _GL_UNISTD_INLINE
int
965 return _gl_getpagesize ();
967 # define GNULIB_defined_getpagesize_function 1
972 /* Need to cast, because on Cygwin 1.5.x systems, the return type is size_t. */
973 _GL_CXXALIAS_SYS_CAST (getpagesize
, int, (void));
975 # if @HAVE_DECL_GETPAGESIZE@
976 _GL_CXXALIASWARN (getpagesize
);
978 #elif defined GNULIB_POSIXCHECK
980 # if HAVE_RAW_DECL_GETPAGESIZE
981 _GL_WARN_ON_USE (getpagesize
, "getpagesize is unportable - "
982 "use gnulib module getpagesize for portability");
988 /* Function getpass() from module 'getpass':
989 Read a password from /dev/tty or stdin.
990 Function getpass() from module 'getpass-gnu':
991 Read a password of arbitrary length from /dev/tty or stdin. */
992 # if @REPLACE_GETPASS@
993 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
995 # define getpass rpl_getpass
997 _GL_FUNCDECL_RPL (getpass
, char *, (const char *prompt
)
998 _GL_ARG_NONNULL ((1)));
999 _GL_CXXALIAS_RPL (getpass
, char *, (const char *prompt
));
1001 # if !@HAVE_GETPASS@
1002 _GL_FUNCDECL_SYS (getpass
, char *, (const char *prompt
)
1003 _GL_ARG_NONNULL ((1)));
1005 _GL_CXXALIAS_SYS (getpass
, char *, (const char *prompt
));
1007 _GL_CXXALIASWARN (getpass
);
1008 #elif defined GNULIB_POSIXCHECK
1010 # if HAVE_RAW_DECL_GETPASS
1011 _GL_WARN_ON_USE (getpass
, "getpass is unportable - "
1012 "use gnulib module getpass or getpass-gnu for portability");
1017 #if @GNULIB_GETUSERSHELL@
1018 /* Return the next valid login shell on the system, or NULL when the end of
1019 the list has been reached. */
1020 # if !@HAVE_DECL_GETUSERSHELL@
1021 _GL_FUNCDECL_SYS (getusershell
, char *, (void));
1023 _GL_CXXALIAS_SYS (getusershell
, char *, (void));
1024 _GL_CXXALIASWARN (getusershell
);
1025 #elif defined GNULIB_POSIXCHECK
1026 # undef getusershell
1027 # if HAVE_RAW_DECL_GETUSERSHELL
1028 _GL_WARN_ON_USE (getusershell
, "getusershell is unportable - "
1029 "use gnulib module getusershell for portability");
1033 #if @GNULIB_GETUSERSHELL@
1034 /* Rewind to pointer that is advanced at each getusershell() call. */
1035 # if !@HAVE_DECL_GETUSERSHELL@
1036 _GL_FUNCDECL_SYS (setusershell
, void, (void));
1038 _GL_CXXALIAS_SYS (setusershell
, void, (void));
1039 _GL_CXXALIASWARN (setusershell
);
1040 #elif defined GNULIB_POSIXCHECK
1041 # undef setusershell
1042 # if HAVE_RAW_DECL_SETUSERSHELL
1043 _GL_WARN_ON_USE (setusershell
, "setusershell is unportable - "
1044 "use gnulib module getusershell for portability");
1048 #if @GNULIB_GETUSERSHELL@
1049 /* Free the pointer that is advanced at each getusershell() call and
1050 associated resources. */
1051 # if !@HAVE_DECL_GETUSERSHELL@
1052 _GL_FUNCDECL_SYS (endusershell
, void, (void));
1054 _GL_CXXALIAS_SYS (endusershell
, void, (void));
1055 _GL_CXXALIASWARN (endusershell
);
1056 #elif defined GNULIB_POSIXCHECK
1057 # undef endusershell
1058 # if HAVE_RAW_DECL_ENDUSERSHELL
1059 _GL_WARN_ON_USE (endusershell
, "endusershell is unportable - "
1060 "use gnulib module getusershell for portability");
1065 #if @GNULIB_GROUP_MEMBER@
1066 /* Determine whether group id is in calling user's group list. */
1067 # if !@HAVE_GROUP_MEMBER@
1068 _GL_FUNCDECL_SYS (group_member
, int, (gid_t gid
));
1070 _GL_CXXALIAS_SYS (group_member
, int, (gid_t gid
));
1071 _GL_CXXALIASWARN (group_member
);
1072 #elif defined GNULIB_POSIXCHECK
1073 # undef group_member
1074 # if HAVE_RAW_DECL_GROUP_MEMBER
1075 _GL_WARN_ON_USE (group_member
, "group_member is unportable - "
1076 "use gnulib module group-member for portability");
1082 # if @REPLACE_ISATTY@
1083 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1085 # define isatty rpl_isatty
1087 _GL_FUNCDECL_RPL (isatty
, int, (int fd
));
1088 _GL_CXXALIAS_RPL (isatty
, int, (int fd
));
1090 _GL_CXXALIAS_SYS (isatty
, int, (int fd
));
1092 _GL_CXXALIASWARN (isatty
);
1093 #elif defined GNULIB_POSIXCHECK
1095 # if HAVE_RAW_DECL_ISATTY
1096 _GL_WARN_ON_USE (isatty
, "isatty has portability problems on native Windows - "
1097 "use gnulib module isatty for portability");
1103 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
1104 to GID (if GID is not -1). Do not follow symbolic links.
1105 Return 0 if successful, otherwise -1 and errno set.
1106 See the POSIX:2008 specification
1107 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/lchown.html>. */
1108 # if @REPLACE_LCHOWN@
1109 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1111 # define lchown rpl_lchown
1113 _GL_FUNCDECL_RPL (lchown
, int, (char const *file
, uid_t owner
, gid_t group
)
1114 _GL_ARG_NONNULL ((1)));
1115 _GL_CXXALIAS_RPL (lchown
, int, (char const *file
, uid_t owner
, gid_t group
));
1118 _GL_FUNCDECL_SYS (lchown
, int, (char const *file
, uid_t owner
, gid_t group
)
1119 _GL_ARG_NONNULL ((1)));
1121 _GL_CXXALIAS_SYS (lchown
, int, (char const *file
, uid_t owner
, gid_t group
));
1123 _GL_CXXALIASWARN (lchown
);
1124 #elif defined GNULIB_POSIXCHECK
1126 # if HAVE_RAW_DECL_LCHOWN
1127 _GL_WARN_ON_USE (lchown
, "lchown is unportable to pre-POSIX.1-2001 systems - "
1128 "use gnulib module lchown for portability");
1134 /* Create a new hard link for an existing file.
1135 Return 0 if successful, otherwise -1 and errno set.
1136 See POSIX:2008 specification
1137 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html>. */
1139 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1140 # define link rpl_link
1142 _GL_FUNCDECL_RPL (link
, int, (const char *path1
, const char *path2
)
1143 _GL_ARG_NONNULL ((1, 2)));
1144 _GL_CXXALIAS_RPL (link
, int, (const char *path1
, const char *path2
));
1147 _GL_FUNCDECL_SYS (link
, int, (const char *path1
, const char *path2
)
1148 _GL_ARG_NONNULL ((1, 2)));
1150 _GL_CXXALIAS_SYS (link
, int, (const char *path1
, const char *path2
));
1152 _GL_CXXALIASWARN (link
);
1153 #elif defined GNULIB_POSIXCHECK
1155 # if HAVE_RAW_DECL_LINK
1156 _GL_WARN_ON_USE (link
, "link is unportable - "
1157 "use gnulib module link for portability");
1163 /* Create a new hard link for an existing file, relative to two
1164 directories. FLAG controls whether symlinks are followed.
1165 Return 0 if successful, otherwise -1 and errno set. */
1166 # if @REPLACE_LINKAT@
1167 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1169 # define linkat rpl_linkat
1171 _GL_FUNCDECL_RPL (linkat
, int,
1172 (int fd1
, const char *path1
, int fd2
, const char *path2
,
1174 _GL_ARG_NONNULL ((2, 4)));
1175 _GL_CXXALIAS_RPL (linkat
, int,
1176 (int fd1
, const char *path1
, int fd2
, const char *path2
,
1180 _GL_FUNCDECL_SYS (linkat
, int,
1181 (int fd1
, const char *path1
, int fd2
, const char *path2
,
1183 _GL_ARG_NONNULL ((2, 4)));
1185 _GL_CXXALIAS_SYS (linkat
, int,
1186 (int fd1
, const char *path1
, int fd2
, const char *path2
,
1189 _GL_CXXALIASWARN (linkat
);
1190 #elif defined GNULIB_POSIXCHECK
1192 # if HAVE_RAW_DECL_LINKAT
1193 _GL_WARN_ON_USE (linkat
, "linkat is unportable - "
1194 "use gnulib module linkat for portability");
1200 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
1201 Return the new offset if successful, otherwise -1 and errno set.
1202 See the POSIX:2008 specification
1203 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html>. */
1204 # if @REPLACE_LSEEK@
1205 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1206 # define lseek rpl_lseek
1208 _GL_FUNCDECL_RPL (lseek
, off_t
, (int fd
, off_t offset
, int whence
));
1209 _GL_CXXALIAS_RPL (lseek
, off_t
, (int fd
, off_t offset
, int whence
));
1211 _GL_CXXALIAS_SYS (lseek
, off_t
, (int fd
, off_t offset
, int whence
));
1213 _GL_CXXALIASWARN (lseek
);
1214 #elif defined GNULIB_POSIXCHECK
1216 # if HAVE_RAW_DECL_LSEEK
1217 _GL_WARN_ON_USE (lseek
, "lseek does not fail with ESPIPE on pipes on some "
1218 "systems - use gnulib module lseek for portability");
1224 /* Create a pipe, defaulting to O_BINARY mode.
1225 Store the read-end as fd[0] and the write-end as fd[1].
1226 Return 0 upon success, or -1 with errno set upon failure. */
1228 _GL_FUNCDECL_SYS (pipe
, int, (int fd
[2]) _GL_ARG_NONNULL ((1)));
1230 _GL_CXXALIAS_SYS (pipe
, int, (int fd
[2]));
1231 _GL_CXXALIASWARN (pipe
);
1232 #elif defined GNULIB_POSIXCHECK
1234 # if HAVE_RAW_DECL_PIPE
1235 _GL_WARN_ON_USE (pipe
, "pipe is unportable - "
1236 "use gnulib module pipe-posix for portability");
1242 /* Create a pipe, applying the given flags when opening the read-end of the
1243 pipe and the write-end of the pipe.
1244 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
1245 and O_TEXT, O_BINARY (defined in "binary-io.h").
1246 Store the read-end as fd[0] and the write-end as fd[1].
1247 Return 0 upon success, or -1 with errno set upon failure.
1248 See also the Linux man page at
1249 <https://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */
1251 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1252 # define pipe2 rpl_pipe2
1254 _GL_FUNCDECL_RPL (pipe2
, int, (int fd
[2], int flags
) _GL_ARG_NONNULL ((1)));
1255 _GL_CXXALIAS_RPL (pipe2
, int, (int fd
[2], int flags
));
1257 _GL_FUNCDECL_SYS (pipe2
, int, (int fd
[2], int flags
) _GL_ARG_NONNULL ((1)));
1258 _GL_CXXALIAS_SYS (pipe2
, int, (int fd
[2], int flags
));
1260 _GL_CXXALIASWARN (pipe2
);
1261 #elif defined GNULIB_POSIXCHECK
1263 # if HAVE_RAW_DECL_PIPE2
1264 _GL_WARN_ON_USE (pipe2
, "pipe2 is unportable - "
1265 "use gnulib module pipe2 for portability");
1271 /* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
1272 Return the number of bytes placed into BUF if successful, otherwise
1273 set errno and return -1. 0 indicates EOF.
1274 See the POSIX:2008 specification
1275 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html>. */
1276 # if @REPLACE_PREAD@
1277 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1279 # define pread rpl_pread
1281 _GL_FUNCDECL_RPL (pread
, ssize_t
,
1282 (int fd
, void *buf
, size_t bufsize
, off_t offset
)
1283 _GL_ARG_NONNULL ((2)));
1284 _GL_CXXALIAS_RPL (pread
, ssize_t
,
1285 (int fd
, void *buf
, size_t bufsize
, off_t offset
));
1288 _GL_FUNCDECL_SYS (pread
, ssize_t
,
1289 (int fd
, void *buf
, size_t bufsize
, off_t offset
)
1290 _GL_ARG_NONNULL ((2)));
1292 _GL_CXXALIAS_SYS (pread
, ssize_t
,
1293 (int fd
, void *buf
, size_t bufsize
, off_t offset
));
1295 _GL_CXXALIASWARN (pread
);
1296 #elif defined GNULIB_POSIXCHECK
1298 # if HAVE_RAW_DECL_PREAD
1299 _GL_WARN_ON_USE (pread
, "pread is unportable - "
1300 "use gnulib module pread for portability");
1306 /* Write at most BUFSIZE bytes from BUF into FD, starting at OFFSET.
1307 Return the number of bytes written if successful, otherwise
1308 set errno and return -1. 0 indicates nothing written. See the
1309 POSIX:2008 specification
1310 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html>. */
1311 # if @REPLACE_PWRITE@
1312 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1314 # define pwrite rpl_pwrite
1316 _GL_FUNCDECL_RPL (pwrite
, ssize_t
,
1317 (int fd
, const void *buf
, size_t bufsize
, off_t offset
)
1318 _GL_ARG_NONNULL ((2)));
1319 _GL_CXXALIAS_RPL (pwrite
, ssize_t
,
1320 (int fd
, const void *buf
, size_t bufsize
, off_t offset
));
1323 _GL_FUNCDECL_SYS (pwrite
, ssize_t
,
1324 (int fd
, const void *buf
, size_t bufsize
, off_t offset
)
1325 _GL_ARG_NONNULL ((2)));
1327 _GL_CXXALIAS_SYS (pwrite
, ssize_t
,
1328 (int fd
, const void *buf
, size_t bufsize
, off_t offset
));
1330 _GL_CXXALIASWARN (pwrite
);
1331 #elif defined GNULIB_POSIXCHECK
1333 # if HAVE_RAW_DECL_PWRITE
1334 _GL_WARN_ON_USE (pwrite
, "pwrite is unportable - "
1335 "use gnulib module pwrite for portability");
1341 /* Read up to COUNT bytes from file descriptor FD into the buffer starting
1342 at BUF. See the POSIX:2008 specification
1343 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html>. */
1345 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1347 # define read rpl_read
1349 _GL_FUNCDECL_RPL (read
, ssize_t
, (int fd
, void *buf
, size_t count
)
1350 _GL_ARG_NONNULL ((2)));
1351 _GL_CXXALIAS_RPL (read
, ssize_t
, (int fd
, void *buf
, size_t count
));
1353 /* Need to cast, because on mingw, the third parameter is
1355 and the return type is 'int'. */
1356 _GL_CXXALIAS_SYS_CAST (read
, ssize_t
, (int fd
, void *buf
, size_t count
));
1358 _GL_CXXALIASWARN (read
);
1362 #if @GNULIB_READLINK@
1363 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
1364 bytes of it into BUF. Return the number of bytes placed into BUF if
1365 successful, otherwise -1 and errno set.
1366 See the POSIX:2008 specification
1367 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>. */
1368 # if @REPLACE_READLINK@
1369 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1370 # define readlink rpl_readlink
1372 _GL_FUNCDECL_RPL (readlink
, ssize_t
,
1373 (const char *file
, char *buf
, size_t bufsize
)
1374 _GL_ARG_NONNULL ((1, 2)));
1375 _GL_CXXALIAS_RPL (readlink
, ssize_t
,
1376 (const char *file
, char *buf
, size_t bufsize
));
1378 # if !@HAVE_READLINK@
1379 _GL_FUNCDECL_SYS (readlink
, ssize_t
,
1380 (const char *file
, char *buf
, size_t bufsize
)
1381 _GL_ARG_NONNULL ((1, 2)));
1383 _GL_CXXALIAS_SYS (readlink
, ssize_t
,
1384 (const char *file
, char *buf
, size_t bufsize
));
1386 _GL_CXXALIASWARN (readlink
);
1387 #elif defined GNULIB_POSIXCHECK
1389 # if HAVE_RAW_DECL_READLINK
1390 _GL_WARN_ON_USE (readlink
, "readlink is unportable - "
1391 "use gnulib module readlink for portability");
1396 #if @GNULIB_READLINKAT@
1397 # if @REPLACE_READLINKAT@
1398 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1399 # define readlinkat rpl_readlinkat
1401 _GL_FUNCDECL_RPL (readlinkat
, ssize_t
,
1402 (int fd
, char const *file
, char *buf
, size_t len
)
1403 _GL_ARG_NONNULL ((2, 3)));
1404 _GL_CXXALIAS_RPL (readlinkat
, ssize_t
,
1405 (int fd
, char const *file
, char *buf
, size_t len
));
1407 # if !@HAVE_READLINKAT@
1408 _GL_FUNCDECL_SYS (readlinkat
, ssize_t
,
1409 (int fd
, char const *file
, char *buf
, size_t len
)
1410 _GL_ARG_NONNULL ((2, 3)));
1412 _GL_CXXALIAS_SYS (readlinkat
, ssize_t
,
1413 (int fd
, char const *file
, char *buf
, size_t len
));
1415 _GL_CXXALIASWARN (readlinkat
);
1416 #elif defined GNULIB_POSIXCHECK
1418 # if HAVE_RAW_DECL_READLINKAT
1419 _GL_WARN_ON_USE (readlinkat
, "readlinkat is not portable - "
1420 "use gnulib module readlinkat for portability");
1426 /* Remove the directory DIR. */
1427 # if @REPLACE_RMDIR@
1428 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1429 # define rmdir rpl_rmdir
1431 _GL_FUNCDECL_RPL (rmdir
, int, (char const *name
) _GL_ARG_NONNULL ((1)));
1432 _GL_CXXALIAS_RPL (rmdir
, int, (char const *name
));
1434 _GL_CXXALIAS_SYS (rmdir
, int, (char const *name
));
1436 _GL_CXXALIASWARN (rmdir
);
1437 #elif defined GNULIB_POSIXCHECK
1439 # if HAVE_RAW_DECL_RMDIR
1440 _GL_WARN_ON_USE (rmdir
, "rmdir is unportable - "
1441 "use gnulib module rmdir for portability");
1446 #if @GNULIB_SETHOSTNAME@
1447 /* Set the host name of the machine.
1448 The host name may or may not be fully qualified.
1450 Put LEN bytes of NAME into the host name.
1451 Return 0 if successful, otherwise, set errno and return -1.
1453 Platforms with no ability to set the hostname return -1 and set
1455 # if !@HAVE_SETHOSTNAME@ || !@HAVE_DECL_SETHOSTNAME@
1456 _GL_FUNCDECL_SYS (sethostname
, int, (const char *name
, size_t len
)
1457 _GL_ARG_NONNULL ((1)));
1459 /* Need to cast, because on Solaris 11 2011-10, Mac OS X 10.5, IRIX 6.5
1460 and FreeBSD 6.4 the second parameter is int. On Solaris 11
1461 2011-10, the first parameter is not const. */
1462 _GL_CXXALIAS_SYS_CAST (sethostname
, int, (const char *name
, size_t len
));
1463 _GL_CXXALIASWARN (sethostname
);
1464 #elif defined GNULIB_POSIXCHECK
1466 # if HAVE_RAW_DECL_SETHOSTNAME
1467 _GL_WARN_ON_USE (sethostname
, "sethostname is unportable - "
1468 "use gnulib module sethostname for portability");
1474 /* Pause the execution of the current thread for N seconds.
1475 Returns the number of seconds left to sleep.
1476 See the POSIX:2008 specification
1477 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html>. */
1478 # if @REPLACE_SLEEP@
1479 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1481 # define sleep rpl_sleep
1483 _GL_FUNCDECL_RPL (sleep
, unsigned int, (unsigned int n
));
1484 _GL_CXXALIAS_RPL (sleep
, unsigned int, (unsigned int n
));
1487 _GL_FUNCDECL_SYS (sleep
, unsigned int, (unsigned int n
));
1489 _GL_CXXALIAS_SYS (sleep
, unsigned int, (unsigned int n
));
1491 _GL_CXXALIASWARN (sleep
);
1492 #elif defined GNULIB_POSIXCHECK
1494 # if HAVE_RAW_DECL_SLEEP
1495 _GL_WARN_ON_USE (sleep
, "sleep is unportable - "
1496 "use gnulib module sleep for portability");
1501 #if @GNULIB_SYMLINK@
1502 # if @REPLACE_SYMLINK@
1503 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1505 # define symlink rpl_symlink
1507 _GL_FUNCDECL_RPL (symlink
, int, (char const *contents
, char const *file
)
1508 _GL_ARG_NONNULL ((1, 2)));
1509 _GL_CXXALIAS_RPL (symlink
, int, (char const *contents
, char const *file
));
1511 # if !@HAVE_SYMLINK@
1512 _GL_FUNCDECL_SYS (symlink
, int, (char const *contents
, char const *file
)
1513 _GL_ARG_NONNULL ((1, 2)));
1515 _GL_CXXALIAS_SYS (symlink
, int, (char const *contents
, char const *file
));
1517 _GL_CXXALIASWARN (symlink
);
1518 #elif defined GNULIB_POSIXCHECK
1520 # if HAVE_RAW_DECL_SYMLINK
1521 _GL_WARN_ON_USE (symlink
, "symlink is not portable - "
1522 "use gnulib module symlink for portability");
1527 #if @GNULIB_SYMLINKAT@
1528 # if @REPLACE_SYMLINKAT@
1529 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1531 # define symlinkat rpl_symlinkat
1533 _GL_FUNCDECL_RPL (symlinkat
, int,
1534 (char const *contents
, int fd
, char const *file
)
1535 _GL_ARG_NONNULL ((1, 3)));
1536 _GL_CXXALIAS_RPL (symlinkat
, int,
1537 (char const *contents
, int fd
, char const *file
));
1539 # if !@HAVE_SYMLINKAT@
1540 _GL_FUNCDECL_SYS (symlinkat
, int,
1541 (char const *contents
, int fd
, char const *file
)
1542 _GL_ARG_NONNULL ((1, 3)));
1544 _GL_CXXALIAS_SYS (symlinkat
, int,
1545 (char const *contents
, int fd
, char const *file
));
1547 _GL_CXXALIASWARN (symlinkat
);
1548 #elif defined GNULIB_POSIXCHECK
1550 # if HAVE_RAW_DECL_SYMLINKAT
1551 _GL_WARN_ON_USE (symlinkat
, "symlinkat is not portable - "
1552 "use gnulib module symlinkat for portability");
1557 #if @GNULIB_TRUNCATE@
1558 /* Change the size of the file designated by FILENAME to become equal to LENGTH.
1559 Return 0 if successful, otherwise -1 and errno set.
1560 See the POSIX:2008 specification
1561 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/truncate.html>. */
1562 # if @REPLACE_TRUNCATE@
1563 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1565 # define truncate rpl_truncate
1567 _GL_FUNCDECL_RPL (truncate
, int, (const char *filename
, off_t length
)
1568 _GL_ARG_NONNULL ((1)));
1569 _GL_CXXALIAS_RPL (truncate
, int, (const char *filename
, off_t length
));
1571 # if !@HAVE_DECL_TRUNCATE@
1572 _GL_FUNCDECL_SYS (truncate
, int, (const char *filename
, off_t length
)
1573 _GL_ARG_NONNULL ((1)));
1575 _GL_CXXALIAS_SYS (truncate
, int, (const char *filename
, off_t length
));
1577 _GL_CXXALIASWARN (truncate
);
1578 #elif defined GNULIB_POSIXCHECK
1580 # if HAVE_RAW_DECL_TRUNCATE
1581 _GL_WARN_ON_USE (truncate
, "truncate is unportable - "
1582 "use gnulib module truncate for portability");
1587 #if @GNULIB_TTYNAME_R@
1588 /* Store at most BUFLEN characters of the pathname of the terminal FD is
1589 open on in BUF. Return 0 on success, otherwise an error number. */
1590 # if @REPLACE_TTYNAME_R@
1591 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1593 # define ttyname_r rpl_ttyname_r
1595 _GL_FUNCDECL_RPL (ttyname_r
, int,
1596 (int fd
, char *buf
, size_t buflen
) _GL_ARG_NONNULL ((2)));
1597 _GL_CXXALIAS_RPL (ttyname_r
, int,
1598 (int fd
, char *buf
, size_t buflen
));
1600 # if !@HAVE_DECL_TTYNAME_R@
1601 _GL_FUNCDECL_SYS (ttyname_r
, int,
1602 (int fd
, char *buf
, size_t buflen
) _GL_ARG_NONNULL ((2)));
1604 _GL_CXXALIAS_SYS (ttyname_r
, int,
1605 (int fd
, char *buf
, size_t buflen
));
1607 _GL_CXXALIASWARN (ttyname_r
);
1608 #elif defined GNULIB_POSIXCHECK
1610 # if HAVE_RAW_DECL_TTYNAME_R
1611 _GL_WARN_ON_USE (ttyname_r
, "ttyname_r is not portable - "
1612 "use gnulib module ttyname_r for portability");
1618 # if @REPLACE_UNLINK@
1619 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1621 # define unlink rpl_unlink
1623 _GL_FUNCDECL_RPL (unlink
, int, (char const *file
) _GL_ARG_NONNULL ((1)));
1624 _GL_CXXALIAS_RPL (unlink
, int, (char const *file
));
1626 _GL_CXXALIAS_SYS (unlink
, int, (char const *file
));
1628 _GL_CXXALIASWARN (unlink
);
1629 #elif defined GNULIB_POSIXCHECK
1631 # if HAVE_RAW_DECL_UNLINK
1632 _GL_WARN_ON_USE (unlink
, "unlink is not portable - "
1633 "use gnulib module unlink for portability");
1638 #if @GNULIB_UNLINKAT@
1639 # if @REPLACE_UNLINKAT@
1640 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1642 # define unlinkat rpl_unlinkat
1644 _GL_FUNCDECL_RPL (unlinkat
, int, (int fd
, char const *file
, int flag
)
1645 _GL_ARG_NONNULL ((2)));
1646 _GL_CXXALIAS_RPL (unlinkat
, int, (int fd
, char const *file
, int flag
));
1648 # if !@HAVE_UNLINKAT@
1649 _GL_FUNCDECL_SYS (unlinkat
, int, (int fd
, char const *file
, int flag
)
1650 _GL_ARG_NONNULL ((2)));
1652 _GL_CXXALIAS_SYS (unlinkat
, int, (int fd
, char const *file
, int flag
));
1654 _GL_CXXALIASWARN (unlinkat
);
1655 #elif defined GNULIB_POSIXCHECK
1657 # if HAVE_RAW_DECL_UNLINKAT
1658 _GL_WARN_ON_USE (unlinkat
, "unlinkat is not portable - "
1659 "use gnulib module openat for portability");
1665 /* Pause the execution of the current thread for N microseconds.
1666 Returns 0 on completion, or -1 on range error.
1667 See the POSIX:2001 specification
1668 <https://pubs.opengroup.org/onlinepubs/009695399/functions/usleep.html>. */
1669 # if @REPLACE_USLEEP@
1670 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1672 # define usleep rpl_usleep
1674 _GL_FUNCDECL_RPL (usleep
, int, (useconds_t n
));
1675 _GL_CXXALIAS_RPL (usleep
, int, (useconds_t n
));
1678 _GL_FUNCDECL_SYS (usleep
, int, (useconds_t n
));
1680 /* Need to cast, because on Haiku, the first parameter is
1682 _GL_CXXALIAS_SYS_CAST (usleep
, int, (useconds_t n
));
1684 _GL_CXXALIASWARN (usleep
);
1685 #elif defined GNULIB_POSIXCHECK
1687 # if HAVE_RAW_DECL_USLEEP
1688 _GL_WARN_ON_USE (usleep
, "usleep is unportable - "
1689 "use gnulib module usleep for portability");
1695 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
1696 See the POSIX:2008 specification
1697 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html>. */
1698 # if @REPLACE_WRITE@
1699 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1701 # define write rpl_write
1703 _GL_FUNCDECL_RPL (write
, ssize_t
, (int fd
, const void *buf
, size_t count
)
1704 _GL_ARG_NONNULL ((2)));
1705 _GL_CXXALIAS_RPL (write
, ssize_t
, (int fd
, const void *buf
, size_t count
));
1707 /* Need to cast, because on mingw, the third parameter is
1709 and the return type is 'int'. */
1710 _GL_CXXALIAS_SYS_CAST (write
, ssize_t
, (int fd
, const void *buf
, size_t count
));
1712 _GL_CXXALIASWARN (write
);
1715 _GL_INLINE_HEADER_END
1717 #endif /* _@GUARD_PREFIX@_UNISTD_H */
1718 #endif /* _GL_INCLUDING_UNISTD_H */
1719 #endif /* _@GUARD_PREFIX@_UNISTD_H */