pipe-posix: new module
[gnulib.git] / lib / unistd.in.h
1 /* Substitute for and wrapper around <unistd.h>.
2    Copyright (C) 2003-2010 Free Software Foundation, Inc.
3
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)
7    any later version.
8
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.
13
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.  */
17
18 #if __GNUC__ >= 3
19 @PRAGMA_SYSTEM_HEADER@
20 #endif
21 @PRAGMA_COLUMNS@
22
23 /* Special invocation convention:
24    - On mingw, several headers, including <winsock2.h>, include <unistd.h>,
25      but we need to ensure that both the system <unistd.h> and <winsock2.h>
26      are completely included before we replace gethostname.  */
27 #if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \
28   && !defined _GL_WINSOCK2_H_WITNESS && defined _WINSOCK2_H
29 /* <unistd.h> is being indirectly included for the first time from
30    <winsock2.h>; avoid declaring any overrides.  */
31 # if @HAVE_UNISTD_H@
32 #  @INCLUDE_NEXT@ @NEXT_UNISTD_H@
33 # else
34 #  error unexpected; report this to bug-gnulib@gnu.org
35 # endif
36 # define _GL_WINSOCK2_H_WITNESS
37
38 /* Normal invocation.  */
39 #elif !defined _GL_UNISTD_H
40
41 /* The include_next requires a split double-inclusion guard.  */
42 #if @HAVE_UNISTD_H@
43 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
44 #endif
45
46 /* Get all possible declarations of gethostname().  */
47 #if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \
48   && !defined _GL_INCLUDING_WINSOCK2_H
49 # define _GL_INCLUDING_WINSOCK2_H
50 # include <winsock2.h>
51 # undef _GL_INCLUDING_WINSOCK2_H
52 #endif
53
54 #if !defined _GL_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H
55 #define _GL_UNISTD_H
56
57 /* NetBSD 5.0 mis-defines NULL.  Also get size_t.  */
58 #include <stddef.h>
59
60 /* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>.  */
61 /* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>.  */
62 /* But avoid namespace pollution on glibc systems.  */
63 #if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
64      || ((@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK) \
65          && defined __CYGWIN__)) \
66     && ! defined __GLIBC__
67 # include <stdio.h>
68 #endif
69
70 /* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>.  */
71 /* But avoid namespace pollution on glibc systems.  */
72 #if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) && defined __CYGWIN__ \
73     && ! defined __GLIBC__
74 # include <fcntl.h>
75 #endif
76
77 /* mingw fails to declare _exit in <unistd.h>.  */
78 /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>.  */
79 /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>.  */
80 /* But avoid namespace pollution on glibc systems.  */
81 #ifndef __GLIBC__
82 # include <stdlib.h>
83 #endif
84
85 /* mingw declares getcwd in <io.h>, not in <unistd.h>.  It also provides
86    _pipe in <io.h>, but that requires _O_BINARY from <fcntl.h>.  */
87 #if ((@GNULIB_GETCWD@ || @GNULIB_PIPE@ || defined GNULIB_POSIXCHECK) \
88      && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
89 # include <io.h>
90 # if @GNULIB_PIPE@
91 #  include <fcntl.h>
92 # endif
93 #endif
94
95 /* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.  */
96 /* But avoid namespace pollution on glibc systems.  */
97 #if @GNULIB_GETDOMAINNAME@ && (defined _AIX || defined __osf__) \
98     && !defined __GLIBC__
99 # include <netdb.h>
100 #endif
101
102 #if (@GNULIB_WRITE@ || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \
103      || @GNULIB_PREAD@ || @GNULIB_PWRITE@ || defined GNULIB_POSIXCHECK)
104 /* Get ssize_t.  */
105 # include <sys/types.h>
106 #endif
107
108 /* Get getopt(), optarg, optind, opterr, optopt.
109    But avoid namespace pollution on glibc systems.  */
110 #if @GNULIB_UNISTD_H_GETOPT@ && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT
111 # include <getopt.h>
112 #endif
113
114 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
115
116 /* The definition of _GL_ARG_NONNULL is copied here.  */
117
118 /* The definition of _GL_WARN_ON_USE is copied here.  */
119
120
121 #if @GNULIB_GETHOSTNAME@
122 /* Get all possible declarations of gethostname().  */
123 # if @UNISTD_H_HAVE_WINSOCK2_H@
124 #  if !defined _GL_SYS_SOCKET_H
125 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
126 #    undef socket
127 #    define socket              socket_used_without_including_sys_socket_h
128 #    undef connect
129 #    define connect             connect_used_without_including_sys_socket_h
130 #    undef accept
131 #    define accept              accept_used_without_including_sys_socket_h
132 #    undef bind
133 #    define bind                bind_used_without_including_sys_socket_h
134 #    undef getpeername
135 #    define getpeername         getpeername_used_without_including_sys_socket_h
136 #    undef getsockname
137 #    define getsockname         getsockname_used_without_including_sys_socket_h
138 #    undef getsockopt
139 #    define getsockopt          getsockopt_used_without_including_sys_socket_h
140 #    undef listen
141 #    define listen              listen_used_without_including_sys_socket_h
142 #    undef recv
143 #    define recv                recv_used_without_including_sys_socket_h
144 #    undef send
145 #    define send                send_used_without_including_sys_socket_h
146 #    undef recvfrom
147 #    define recvfrom            recvfrom_used_without_including_sys_socket_h
148 #    undef sendto
149 #    define sendto              sendto_used_without_including_sys_socket_h
150 #    undef setsockopt
151 #    define setsockopt          setsockopt_used_without_including_sys_socket_h
152 #    undef shutdown
153 #    define shutdown            shutdown_used_without_including_sys_socket_h
154 #   else
155      _GL_WARN_ON_USE (socket,
156                       "socket() used without including <sys/socket.h>");
157      _GL_WARN_ON_USE (connect,
158                       "connect() used without including <sys/socket.h>");
159      _GL_WARN_ON_USE (accept,
160                       "accept() used without including <sys/socket.h>");
161      _GL_WARN_ON_USE (bind,
162                       "bind() used without including <sys/socket.h>");
163      _GL_WARN_ON_USE (getpeername,
164                       "getpeername() used without including <sys/socket.h>");
165      _GL_WARN_ON_USE (getsockname,
166                       "getsockname() used without including <sys/socket.h>");
167      _GL_WARN_ON_USE (getsockopt,
168                       "getsockopt() used without including <sys/socket.h>");
169      _GL_WARN_ON_USE (listen,
170                       "listen() used without including <sys/socket.h>");
171      _GL_WARN_ON_USE (recv,
172                       "recv() used without including <sys/socket.h>");
173      _GL_WARN_ON_USE (send,
174                       "send() used without including <sys/socket.h>");
175      _GL_WARN_ON_USE (recvfrom,
176                       "recvfrom() used without including <sys/socket.h>");
177      _GL_WARN_ON_USE (sendto,
178                       "sendto() used without including <sys/socket.h>");
179      _GL_WARN_ON_USE (setsockopt,
180                       "setsockopt() used without including <sys/socket.h>");
181      _GL_WARN_ON_USE (shutdown,
182                       "shutdown() used without including <sys/socket.h>");
183 #   endif
184 #  endif
185 #  if !defined _GL_SYS_SELECT_H
186 #   if !(defined __cplusplus && defined GNULIB_NAMESPACE)
187 #    undef select
188 #    define select              select_used_without_including_sys_select_h
189 #   else
190      _GL_WARN_ON_USE (select,
191                       "select() used without including <sys/select.h>");
192 #   endif
193 #  endif
194 # endif
195 #endif
196
197
198 /* OS/2 EMX lacks these macros.  */
199 #ifndef STDIN_FILENO
200 # define STDIN_FILENO 0
201 #endif
202 #ifndef STDOUT_FILENO
203 # define STDOUT_FILENO 1
204 #endif
205 #ifndef STDERR_FILENO
206 # define STDERR_FILENO 2
207 #endif
208
209 /* Ensure *_OK macros exist.  */
210 #ifndef F_OK
211 # define F_OK 0
212 # define X_OK 1
213 # define W_OK 2
214 # define R_OK 4
215 #endif
216
217
218 /* Declare overridden functions.  */
219
220
221 #if defined GNULIB_POSIXCHECK
222 /* The access() function is a security risk.  */
223 _GL_WARN_ON_USE (access, "the access function is a security risk - "
224                  "use the gnulib module faccessat instead");
225 #endif
226
227
228 #if @GNULIB_CHOWN@
229 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
230    to GID (if GID is not -1).  Follow symbolic links.
231    Return 0 if successful, otherwise -1 and errno set.
232    See the POSIX:2001 specification
233    <http://www.opengroup.org/susv3xsh/chown.html>.  */
234 # if @REPLACE_CHOWN@
235 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
236 #   undef chown
237 #   define chown rpl_chown
238 #  endif
239 _GL_FUNCDECL_RPL (chown, int, (const char *file, uid_t uid, gid_t gid)
240                               _GL_ARG_NONNULL ((1)));
241 _GL_CXXALIAS_RPL (chown, int, (const char *file, uid_t uid, gid_t gid));
242 # else
243 #  if !@HAVE_CHOWN@
244 _GL_FUNCDECL_SYS (chown, int, (const char *file, uid_t uid, gid_t gid)
245                               _GL_ARG_NONNULL ((1)));
246 #  endif
247 _GL_CXXALIAS_SYS (chown, int, (const char *file, uid_t uid, gid_t gid));
248 # endif
249 _GL_CXXALIASWARN (chown);
250 #elif defined GNULIB_POSIXCHECK
251 # undef chown
252 # if HAVE_RAW_DECL_CHOWN
253 _GL_WARN_ON_USE (chown, "chown fails to follow symlinks on some systems and "
254                  "doesn't treat a uid or gid of -1 on some systems - "
255                  "use gnulib module chown for portability");
256 # endif
257 #endif
258
259
260 #if @GNULIB_CLOSE@
261 # if @REPLACE_CLOSE@
262 /* Automatically included by modules that need a replacement for close.  */
263 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
264 #   undef close
265 #   define close rpl_close
266 #  endif
267 _GL_FUNCDECL_RPL (close, int, (int fd));
268 _GL_CXXALIAS_RPL (close, int, (int fd));
269 # else
270 _GL_CXXALIAS_SYS (close, int, (int fd));
271 # endif
272 _GL_CXXALIASWARN (close);
273 #elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
274 # undef close
275 # define close close_used_without_requesting_gnulib_module_close
276 #elif defined GNULIB_POSIXCHECK
277 # undef close
278 /* Assume close is always declared.  */
279 _GL_WARN_ON_USE (close, "close does not portably work on sockets - "
280                  "use gnulib module close for portability");
281 #endif
282
283
284 #if @REPLACE_DUP@
285 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
286 #  define dup rpl_dup
287 # endif
288 _GL_FUNCDECL_RPL (dup, int, (int oldfd));
289 _GL_CXXALIAS_RPL (dup, int, (int oldfd));
290 #else
291 _GL_CXXALIAS_SYS (dup, int, (int oldfd));
292 #endif
293 _GL_CXXALIASWARN (dup);
294
295
296 #if @GNULIB_DUP2@
297 /* Copy the file descriptor OLDFD into file descriptor NEWFD.  Do nothing if
298    NEWFD = OLDFD, otherwise close NEWFD first if it is open.
299    Return newfd if successful, otherwise -1 and errno set.
300    See the POSIX:2001 specification
301    <http://www.opengroup.org/susv3xsh/dup2.html>.  */
302 # if @REPLACE_DUP2@
303 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
304 #   define dup2 rpl_dup2
305 #  endif
306 _GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd));
307 _GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd));
308 # else
309 #  if !@HAVE_DUP2@
310 _GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd));
311 #  endif
312 _GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
313 # endif
314 _GL_CXXALIASWARN (dup2);
315 #elif defined GNULIB_POSIXCHECK
316 # undef dup2
317 # if HAVE_RAW_DECL_DUP2
318 _GL_WARN_ON_USE (dup2, "dup2 is unportable - "
319                  "use gnulib module dup2 for portability");
320 # endif
321 #endif
322
323
324 #if @GNULIB_DUP3@
325 /* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
326    specified flags.
327    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
328    and O_TEXT, O_BINARY (defined in "binary-io.h").
329    Close NEWFD first if it is open.
330    Return newfd if successful, otherwise -1 and errno set.
331    See the Linux man page at
332    <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>.  */
333 # if @HAVE_DUP3@
334 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
335 #   define dup3 rpl_dup3
336 #  endif
337 _GL_FUNCDECL_RPL (dup3, int, (int oldfd, int newfd, int flags));
338 _GL_CXXALIAS_RPL (dup3, int, (int oldfd, int newfd, int flags));
339 # else
340 _GL_FUNCDECL_SYS (dup3, int, (int oldfd, int newfd, int flags));
341 _GL_CXXALIAS_SYS (dup3, int, (int oldfd, int newfd, int flags));
342 # endif
343 _GL_CXXALIASWARN (dup3);
344 #elif defined GNULIB_POSIXCHECK
345 # undef dup3
346 # if HAVE_RAW_DECL_DUP3
347 _GL_WARN_ON_USE (dup3, "dup3 is unportable - "
348                  "use gnulib module dup3 for portability");
349 # endif
350 #endif
351
352
353 #if @GNULIB_ENVIRON@
354 # if !@HAVE_DECL_ENVIRON@
355 /* Set of environment variables and values.  An array of strings of the form
356    "VARIABLE=VALUE", terminated with a NULL.  */
357 #  if defined __APPLE__ && defined __MACH__
358 #   include <crt_externs.h>
359 #   define environ (*_NSGetEnviron ())
360 #  else
361 #   ifdef __cplusplus
362 extern "C" {
363 #   endif
364 extern char **environ;
365 #   ifdef __cplusplus
366 }
367 #   endif
368 #  endif
369 # endif
370 #elif defined GNULIB_POSIXCHECK
371 # if HAVE_RAW_DECL_ENVIRON
372 static inline char ***
373 rpl_environ (void)
374 {
375   return &environ;
376 }
377 _GL_WARN_ON_USE (rpl_environ, "environ is unportable - "
378                  "use gnulib module environ for portability");
379 #  undef environ
380 #  define environ (*rpl_environ ())
381 # endif
382 #endif
383
384
385 #if @GNULIB_EUIDACCESS@
386 /* Like access(), except that it uses the effective user id and group id of
387    the current process.  */
388 # if !@HAVE_EUIDACCESS@
389 _GL_FUNCDECL_SYS (euidaccess, int, (const char *filename, int mode)
390                                    _GL_ARG_NONNULL ((1)));
391 # endif
392 _GL_CXXALIAS_SYS (euidaccess, int, (const char *filename, int mode));
393 _GL_CXXALIASWARN (euidaccess);
394 # if defined GNULIB_POSIXCHECK
395 /* Like access(), this function is a security risk.  */
396 _GL_WARN_ON_USE (euidaccess, "the euidaccess function is a security risk - "
397                  "use the gnulib module faccessat instead");
398 # endif
399 #elif defined GNULIB_POSIXCHECK
400 # undef euidaccess
401 # if HAVE_RAW_DECL_EUIDACCESS
402 _GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - "
403                  "use gnulib module euidaccess for portability");
404 # endif
405 #endif
406
407
408 #if @GNULIB_FACCESSAT@
409 # if !@HAVE_FACCESSAT@
410 _GL_FUNCDECL_SYS (faccessat, int,
411                   (int fd, char const *file, int mode, int flag)
412                   _GL_ARG_NONNULL ((2)));
413 # endif
414 _GL_CXXALIAS_SYS (faccessat, int,
415                   (int fd, char const *file, int mode, int flag));
416 _GL_CXXALIASWARN (faccessat);
417 #elif defined GNULIB_POSIXCHECK
418 # undef faccessat
419 # if HAVE_RAW_DECL_FACCESSAT
420 _GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
421                  "use gnulib module faccessat for portability");
422 # endif
423 #endif
424
425
426 #if @GNULIB_FCHDIR@
427 /* Change the process' current working directory to the directory on which
428    the given file descriptor is open.
429    Return 0 if successful, otherwise -1 and errno set.
430    See the POSIX:2001 specification
431    <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
432 # if ! @HAVE_FCHDIR@
433 _GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
434
435 /* Gnulib internal hooks needed to maintain the fchdir metadata.  */
436 _GL_EXTERN_C int _gl_register_fd (int fd, const char *filename)
437      _GL_ARG_NONNULL ((2));
438 _GL_EXTERN_C void _gl_unregister_fd (int fd);
439 _GL_EXTERN_C int _gl_register_dup (int oldfd, int newfd);
440 _GL_EXTERN_C const char *_gl_directory_name (int fd);
441
442 # endif
443 _GL_CXXALIAS_SYS (fchdir, int, (int /*fd*/));
444 _GL_CXXALIASWARN (fchdir);
445 #elif defined GNULIB_POSIXCHECK
446 # undef fchdir
447 # if HAVE_RAW_DECL_FCHDIR
448 _GL_WARN_ON_USE (fchdir, "fchdir is unportable - "
449                  "use gnulib module fchdir for portability");
450 # endif
451 #endif
452
453
454 #if @GNULIB_FCHOWNAT@
455 # if @REPLACE_FCHOWNAT@
456 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
457 #   undef fchownat
458 #   define fchownat rpl_fchownat
459 #  endif
460 _GL_FUNCDECL_RPL (fchownat, int, (int fd, char const *file,
461                                   uid_t owner, gid_t group, int flag)
462                                  _GL_ARG_NONNULL ((2)));
463 _GL_CXXALIAS_RPL (fchownat, int, (int fd, char const *file,
464                                   uid_t owner, gid_t group, int flag));
465 # else
466 #  if !@HAVE_FCHOWNAT@
467 _GL_FUNCDECL_SYS (fchownat, int, (int fd, char const *file,
468                                   uid_t owner, gid_t group, int flag)
469                                  _GL_ARG_NONNULL ((2)));
470 #  endif
471 _GL_CXXALIAS_SYS (fchownat, int, (int fd, char const *file,
472                                   uid_t owner, gid_t group, int flag));
473 # endif
474 _GL_CXXALIASWARN (fchownat);
475 #elif defined GNULIB_POSIXCHECK
476 # undef fchownat
477 # if HAVE_RAW_DECL_FCHOWNAT
478 _GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
479                  "use gnulib module openat for portability");
480 # endif
481 #endif
482
483
484 #if @GNULIB_FSYNC@
485 /* Synchronize changes to a file.
486    Return 0 if successful, otherwise -1 and errno set.
487    See POSIX:2001 specification
488    <http://www.opengroup.org/susv3xsh/fsync.html>.  */
489 # if !@HAVE_FSYNC@
490 _GL_FUNCDECL_SYS (fsync, int, (int fd));
491 # endif
492 _GL_CXXALIAS_SYS (fsync, int, (int fd));
493 _GL_CXXALIASWARN (fsync);
494 #elif defined GNULIB_POSIXCHECK
495 # undef fsync
496 # if HAVE_RAW_DECL_FSYNC
497 _GL_WARN_ON_USE (fsync, "fsync is unportable - "
498                  "use gnulib module fsync for portability");
499 # endif
500 #endif
501
502
503 #if @GNULIB_FTRUNCATE@
504 /* Change the size of the file to which FD is opened to become equal to LENGTH.
505    Return 0 if successful, otherwise -1 and errno set.
506    See the POSIX:2001 specification
507    <http://www.opengroup.org/susv3xsh/ftruncate.html>.  */
508 # if !@HAVE_FTRUNCATE@
509 _GL_FUNCDECL_SYS (ftruncate, int, (int fd, off_t length));
510 # endif
511 _GL_CXXALIAS_SYS (ftruncate, int, (int fd, off_t length));
512 _GL_CXXALIASWARN (ftruncate);
513 #elif defined GNULIB_POSIXCHECK
514 # undef ftruncate
515 # if HAVE_RAW_DECL_FTRUNCATE
516 _GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
517                  "use gnulib module ftruncate for portability");
518 # endif
519 #endif
520
521
522 #if @GNULIB_GETCWD@
523 /* Get the name of the current working directory, and put it in SIZE bytes
524    of BUF.
525    Return BUF if successful, or NULL if the directory couldn't be determined
526    or SIZE was too small.
527    See the POSIX:2001 specification
528    <http://www.opengroup.org/susv3xsh/getcwd.html>.
529    Additionally, the gnulib module 'getcwd' guarantees the following GNU
530    extension: If BUF is NULL, an array is allocated with 'malloc'; the array
531    is SIZE bytes long, unless SIZE == 0, in which case it is as big as
532    necessary.  */
533 # if @REPLACE_GETCWD@
534 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
535 #   define getcwd rpl_getcwd
536 #  endif
537 _GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size));
538 _GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size));
539 # else
540 /* Need to cast, because on mingw, the second parameter is
541                                                    int size.  */
542 _GL_CXXALIAS_SYS_CAST (getcwd, char *, (char *buf, size_t size));
543 # endif
544 _GL_CXXALIASWARN (getcwd);
545 #elif defined GNULIB_POSIXCHECK
546 # undef getcwd
547 # if HAVE_RAW_DECL_GETCWD
548 _GL_WARN_ON_USE (getcwd, "getcwd is unportable - "
549                  "use gnulib module getcwd for portability");
550 # endif
551 #endif
552
553
554 #if @GNULIB_GETDOMAINNAME@
555 /* Return the NIS domain name of the machine.
556    WARNING! The NIS domain name is unrelated to the fully qualified host name
557             of the machine.  It is also unrelated to email addresses.
558    WARNING! The NIS domain name is usually the empty string or "(none)" when
559             not using NIS.
560
561    Put up to LEN bytes of the NIS domain name into NAME.
562    Null terminate it if the name is shorter than LEN.
563    If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
564    Return 0 if successful, otherwise set errno and return -1.  */
565 # if @REPLACE_GETDOMAINNAME@
566 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
567 #   undef getdomainname
568 #   define getdomainname rpl_getdomainname
569 #  endif
570 _GL_FUNCDECL_RPL (getdomainname, int, (char *name, size_t len)
571                                       _GL_ARG_NONNULL ((1)));
572 _GL_CXXALIAS_RPL (getdomainname, int, (char *name, size_t len));
573 # else
574 #  if !@HAVE_DECL_GETDOMAINNAME@
575 _GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len)
576                                       _GL_ARG_NONNULL ((1)));
577 #  endif
578 _GL_CXXALIAS_SYS (getdomainname, int, (char *name, size_t len));
579 # endif
580 _GL_CXXALIASWARN (getdomainname);
581 #elif defined GNULIB_POSIXCHECK
582 # undef getdomainname
583 # if HAVE_RAW_DECL_GETDOMAINNAME
584 _GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - "
585                  "use gnulib module getdomainname for portability");
586 # endif
587 #endif
588
589
590 #if @GNULIB_GETDTABLESIZE@
591 /* Return the maximum number of file descriptors in the current process.
592    In POSIX, this is same as sysconf (_SC_OPEN_MAX).  */
593 # if !@HAVE_GETDTABLESIZE@
594 _GL_FUNCDECL_SYS (getdtablesize, int, (void));
595 # endif
596 _GL_CXXALIAS_SYS (getdtablesize, int, (void));
597 _GL_CXXALIASWARN (getdtablesize);
598 #elif defined GNULIB_POSIXCHECK
599 # undef getdtablesize
600 # if HAVE_RAW_DECL_GETDTABLESIZE
601 _GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - "
602                  "use gnulib module getdtablesize for portability");
603 # endif
604 #endif
605
606
607 #if @GNULIB_GETGROUPS@
608 /* Return the supplemental groups that the current process belongs to.
609    It is unspecified whether the effective group id is in the list.
610    If N is 0, return the group count; otherwise, N describes how many
611    entries are available in GROUPS.  Return -1 and set errno if N is
612    not 0 and not large enough.  Fails with ENOSYS on some systems.  */
613 # if @REPLACE_GETGROUPS@
614 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
615 #   undef getgroups
616 #   define getgroups rpl_getgroups
617 #  endif
618 _GL_FUNCDECL_RPL (getgroups, int, (int n, gid_t *groups));
619 _GL_CXXALIAS_RPL (getgroups, int, (int n, gid_t *groups));
620 # else
621 #  if !@HAVE_GETGROUPS@
622 _GL_FUNCDECL_SYS (getgroups, int, (int n, gid_t *groups));
623 #  endif
624 _GL_CXXALIAS_SYS (getgroups, int, (int n, gid_t *groups));
625 # endif
626 _GL_CXXALIASWARN (getgroups);
627 #elif defined GNULIB_POSIXCHECK
628 # undef getgroups
629 # if HAVE_RAW_DECL_GETGROUPS
630 _GL_WARN_ON_USE (getgroups, "getgroups is unportable - "
631                  "use gnulib module getgroups for portability");
632 # endif
633 #endif
634
635
636 #if @GNULIB_GETHOSTNAME@
637 /* Return the standard host name of the machine.
638    WARNING! The host name may or may not be fully qualified.
639
640    Put up to LEN bytes of the host name into NAME.
641    Null terminate it if the name is shorter than LEN.
642    If the host name is longer than LEN, set errno = EINVAL and return -1.
643    Return 0 if successful, otherwise set errno and return -1.  */
644 # if @UNISTD_H_HAVE_WINSOCK2_H@
645 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
646 #   undef gethostname
647 #   define gethostname rpl_gethostname
648 #  endif
649 _GL_FUNCDECL_RPL (gethostname, int, (char *name, size_t len)
650                                     _GL_ARG_NONNULL ((1)));
651 _GL_CXXALIAS_RPL (gethostname, int, (char *name, size_t len));
652 # else
653 #  if !@HAVE_GETHOSTNAME@
654 _GL_FUNCDECL_SYS (gethostname, int, (char *name, size_t len)
655                                     _GL_ARG_NONNULL ((1)));
656 #  endif
657 /* Need to cast, because on Solaris 10 systems, the second parameter is
658                                                       int len.  */
659 _GL_CXXALIAS_SYS_CAST (gethostname, int, (char *name, size_t len));
660 # endif
661 _GL_CXXALIASWARN (gethostname);
662 #elif @UNISTD_H_HAVE_WINSOCK2_H@
663 # undef gethostname
664 # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
665 #elif defined GNULIB_POSIXCHECK
666 # undef gethostname
667 # if HAVE_RAW_DECL_GETHOSTNAME
668 _GL_WARN_ON_USE (gethostname, "gethostname is unportable - "
669                  "use gnulib module gethostname for portability");
670 # endif
671 #endif
672
673
674 #if @GNULIB_GETLOGIN@
675 /* Returns the user's login name, or NULL if it cannot be found.  Upon error,
676    returns NULL with errno set.
677
678    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
679
680    Most programs don't need to use this function, because the information is
681    available through environment variables:
682      ${LOGNAME-$USER}        on Unix platforms,
683      $USERNAME               on native Windows platforms.
684  */
685 # if !@HAVE_GETLOGIN@
686 _GL_FUNCDECL_SYS (getlogin, char *, (void));
687 # endif
688 _GL_CXXALIAS_SYS (getlogin, char *, (void));
689 _GL_CXXALIASWARN (getlogin);
690 #elif defined GNULIB_POSIXCHECK
691 # undef getlogin
692 # if HAVE_RAW_DECL_GETLOGIN
693 _GL_WARN_ON_USE (getlogin, "getlogin is unportable - "
694                  "use gnulib module getlogin for portability");
695 # endif
696 #endif
697
698
699 #if @GNULIB_GETLOGIN_R@
700 /* Copies the user's login name to NAME.
701    The array pointed to by NAME has room for SIZE bytes.
702
703    Returns 0 if successful.  Upon error, an error number is returned, or -1 in
704    the case that the login name cannot be found but no specific error is
705    provided (this case is hopefully rare but is left open by the POSIX spec).
706
707    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
708
709    Most programs don't need to use this function, because the information is
710    available through environment variables:
711      ${LOGNAME-$USER}        on Unix platforms,
712      $USERNAME               on native Windows platforms.
713  */
714 # if !@HAVE_DECL_GETLOGIN_R@
715 _GL_FUNCDECL_SYS (getlogin_r, int, (char *name, size_t size)
716                                    _GL_ARG_NONNULL ((1)));
717 # endif
718 /* Need to cast, because on Solaris 10 systems, the second argument is
719                                                      int size.  */
720 _GL_CXXALIAS_SYS_CAST (getlogin_r, int, (char *name, size_t size));
721 _GL_CXXALIASWARN (getlogin_r);
722 #elif defined GNULIB_POSIXCHECK
723 # undef getlogin_r
724 # if HAVE_RAW_DECL_GETLOGIN_R
725 _GL_WARN_ON_USE (getlogin_r, "getlogin_r is unportable - "
726                  "use gnulib module getlogin_r for portability");
727 # endif
728 #endif
729
730
731 #if @GNULIB_GETPAGESIZE@
732 # if @REPLACE_GETPAGESIZE@
733 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
734 #   define getpagesize rpl_getpagesize
735 #  endif
736 _GL_FUNCDECL_RPL (getpagesize, int, (void));
737 _GL_CXXALIAS_RPL (getpagesize, int, (void));
738 # else
739 #  if !@HAVE_GETPAGESIZE@
740 #   if !defined getpagesize
741 /* This is for POSIX systems.  */
742 #    if !defined _gl_getpagesize && defined _SC_PAGESIZE
743 #     if ! (defined __VMS && __VMS_VER < 70000000)
744 #      define _gl_getpagesize() sysconf (_SC_PAGESIZE)
745 #     endif
746 #    endif
747 /* This is for older VMS.  */
748 #    if !defined _gl_getpagesize && defined __VMS
749 #     ifdef __ALPHA
750 #      define _gl_getpagesize() 8192
751 #     else
752 #      define _gl_getpagesize() 512
753 #     endif
754 #    endif
755 /* This is for BeOS.  */
756 #    if !defined _gl_getpagesize && @HAVE_OS_H@
757 #     include <OS.h>
758 #     if defined B_PAGE_SIZE
759 #      define _gl_getpagesize() B_PAGE_SIZE
760 #     endif
761 #    endif
762 /* This is for AmigaOS4.0.  */
763 #    if !defined _gl_getpagesize && defined __amigaos4__
764 #     define _gl_getpagesize() 2048
765 #    endif
766 /* This is for older Unix systems.  */
767 #    if !defined _gl_getpagesize && @HAVE_SYS_PARAM_H@
768 #     include <sys/param.h>
769 #     ifdef EXEC_PAGESIZE
770 #      define _gl_getpagesize() EXEC_PAGESIZE
771 #     else
772 #      ifdef NBPG
773 #       ifndef CLSIZE
774 #        define CLSIZE 1
775 #       endif
776 #       define _gl_getpagesize() (NBPG * CLSIZE)
777 #      else
778 #       ifdef NBPC
779 #        define _gl_getpagesize() NBPC
780 #       endif
781 #      endif
782 #     endif
783 #    endif
784 #    if !(defined __cplusplus && defined GNULIB_NAMESPACE)
785 #     define getpagesize() _gl_getpagesize ()
786 #    else
787 static inline int
788 getpagesize ()
789 {
790   return _gl_getpagesize ();
791 }
792 #    endif
793 #   endif
794 #  endif
795 /* Need to cast, because on Cygwin 1.5.x systems, the return type is size_t.  */
796 _GL_CXXALIAS_SYS_CAST (getpagesize, int, (void));
797 # endif
798 # if @HAVE_DECL_GETPAGESIZE@
799 _GL_CXXALIASWARN (getpagesize);
800 # endif
801 #elif defined GNULIB_POSIXCHECK
802 # undef getpagesize
803 # if HAVE_RAW_DECL_GETPAGESIZE
804 _GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - "
805                  "use gnulib module getpagesize for portability");
806 # endif
807 #endif
808
809
810 #if @GNULIB_GETUSERSHELL@
811 /* Return the next valid login shell on the system, or NULL when the end of
812    the list has been reached.  */
813 # if !@HAVE_DECL_GETUSERSHELL@
814 _GL_FUNCDECL_SYS (getusershell, char *, (void));
815 # endif
816 _GL_CXXALIAS_SYS (getusershell, char *, (void));
817 _GL_CXXALIASWARN (getusershell);
818 #elif defined GNULIB_POSIXCHECK
819 # undef getusershell
820 # if HAVE_RAW_DECL_GETUSERSHELL
821 _GL_WARN_ON_USE (getusershell, "getusershell is unportable - "
822                  "use gnulib module getusershell for portability");
823 # endif
824 #endif
825
826 #if @GNULIB_GETUSERSHELL@
827 /* Rewind to pointer that is advanced at each getusershell() call.  */
828 # if !@HAVE_DECL_GETUSERSHELL@
829 _GL_FUNCDECL_SYS (setusershell, void, (void));
830 # endif
831 _GL_CXXALIAS_SYS (setusershell, void, (void));
832 _GL_CXXALIASWARN (setusershell);
833 #elif defined GNULIB_POSIXCHECK
834 # undef setusershell
835 # if HAVE_RAW_DECL_SETUSERSHELL
836 _GL_WARN_ON_USE (setusershell, "setusershell is unportable - "
837                  "use gnulib module getusershell for portability");
838 # endif
839 #endif
840
841 #if @GNULIB_GETUSERSHELL@
842 /* Free the pointer that is advanced at each getusershell() call and
843    associated resources.  */
844 # if !@HAVE_DECL_GETUSERSHELL@
845 _GL_FUNCDECL_SYS (endusershell, void, (void));
846 # endif
847 _GL_CXXALIAS_SYS (endusershell, void, (void));
848 _GL_CXXALIASWARN (endusershell);
849 #elif defined GNULIB_POSIXCHECK
850 # undef endusershell
851 # if HAVE_RAW_DECL_ENDUSERSHELL
852 _GL_WARN_ON_USE (endusershell, "endusershell is unportable - "
853                  "use gnulib module getusershell for portability");
854 # endif
855 #endif
856
857
858 #if @GNULIB_LCHOWN@
859 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
860    to GID (if GID is not -1).  Do not follow symbolic links.
861    Return 0 if successful, otherwise -1 and errno set.
862    See the POSIX:2001 specification
863    <http://www.opengroup.org/susv3xsh/lchown.html>.  */
864 # if @REPLACE_LCHOWN@
865 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
866 #   undef lchown
867 #   define lchown rpl_lchown
868 #  endif
869 _GL_FUNCDECL_RPL (lchown, int, (char const *file, uid_t owner, gid_t group)
870                                _GL_ARG_NONNULL ((1)));
871 _GL_CXXALIAS_RPL (lchown, int, (char const *file, uid_t owner, gid_t group));
872 # else
873 #  if !@HAVE_LCHOWN@
874 _GL_FUNCDECL_SYS (lchown, int, (char const *file, uid_t owner, gid_t group)
875                                _GL_ARG_NONNULL ((1)));
876 #  endif
877 _GL_CXXALIAS_SYS (lchown, int, (char const *file, uid_t owner, gid_t group));
878 # endif
879 _GL_CXXALIASWARN (lchown);
880 #elif defined GNULIB_POSIXCHECK
881 # undef lchown
882 # if HAVE_RAW_DECL_LCHOWN
883 _GL_WARN_ON_USE (lchown, "lchown is unportable to pre-POSIX.1-2001 systems - "
884                  "use gnulib module lchown for portability");
885 # endif
886 #endif
887
888
889 #if @GNULIB_LINK@
890 /* Create a new hard link for an existing file.
891    Return 0 if successful, otherwise -1 and errno set.
892    See POSIX:2001 specification
893    <http://www.opengroup.org/susv3xsh/link.html>.  */
894 # if @REPLACE_LINK@
895 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
896 #   define link rpl_link
897 #  endif
898 _GL_FUNCDECL_RPL (link, int, (const char *path1, const char *path2)
899                              _GL_ARG_NONNULL ((1, 2)));
900 _GL_CXXALIAS_RPL (link, int, (const char *path1, const char *path2));
901 # else
902 #  if !@HAVE_LINK@
903 _GL_FUNCDECL_SYS (link, int, (const char *path1, const char *path2)
904                              _GL_ARG_NONNULL ((1, 2)));
905 #  endif
906 _GL_CXXALIAS_SYS (link, int, (const char *path1, const char *path2));
907 # endif
908 _GL_CXXALIASWARN (link);
909 #elif defined GNULIB_POSIXCHECK
910 # undef link
911 # if HAVE_RAW_DECL_LINK
912 _GL_WARN_ON_USE (link, "link is unportable - "
913                  "use gnulib module link for portability");
914 # endif
915 #endif
916
917
918 #if @GNULIB_LINKAT@
919 /* Create a new hard link for an existing file, relative to two
920    directories.  FLAG controls whether symlinks are followed.
921    Return 0 if successful, otherwise -1 and errno set.  */
922 # if @REPLACE_LINKAT@
923 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
924 #   undef linkat
925 #   define linkat rpl_linkat
926 #  endif
927 _GL_FUNCDECL_RPL (linkat, int,
928                   (int fd1, const char *path1, int fd2, const char *path2,
929                    int flag)
930                   _GL_ARG_NONNULL ((2, 4)));
931 _GL_CXXALIAS_RPL (linkat, int,
932                   (int fd1, const char *path1, int fd2, const char *path2,
933                    int flag));
934 # else
935 #  if !@HAVE_LINKAT@
936 _GL_FUNCDECL_SYS (linkat, int,
937                   (int fd1, const char *path1, int fd2, const char *path2,
938                    int flag)
939                   _GL_ARG_NONNULL ((2, 4)));
940 #  endif
941 _GL_CXXALIAS_SYS (linkat, int,
942                   (int fd1, const char *path1, int fd2, const char *path2,
943                    int flag));
944 # endif
945 _GL_CXXALIASWARN (linkat);
946 #elif defined GNULIB_POSIXCHECK
947 # undef linkat
948 # if HAVE_RAW_DECL_LINKAT
949 _GL_WARN_ON_USE (linkat, "linkat is unportable - "
950                  "use gnulib module linkat for portability");
951 # endif
952 #endif
953
954
955 #if @GNULIB_LSEEK@
956 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
957    Return the new offset if successful, otherwise -1 and errno set.
958    See the POSIX:2001 specification
959    <http://www.opengroup.org/susv3xsh/lseek.html>.  */
960 # if @REPLACE_LSEEK@
961 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
962 #   define lseek rpl_lseek
963 #  endif
964 _GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence));
965 _GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence));
966 # else
967 _GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
968 # endif
969 _GL_CXXALIASWARN (lseek);
970 #elif defined GNULIB_POSIXCHECK
971 # undef lseek
972 # if HAVE_RAW_DECL_LSEEK
973 _GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some "
974                  "systems - use gnulib module lseek for portability");
975 # endif
976 #endif
977
978
979 #if @GNULIB_PIPE@
980 /* Create a pipe, defaulting to O_BINARY mode.
981    Store the read-end as fd[0] and the write-end as fd[1].
982    Return 0 upon success, or -1 with errno set upon failure.  */
983 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
984 #  define pipe(fd) _pipe (fd, 4096, _O_BINARY)
985 # endif
986 #elif defined GNULIB_POSIXCHECK
987 # undef pipe
988 # if HAVE_RAW_DECL_PIPE
989 _GL_WARN_ON_USE (pipe, "pipe is unportable - "
990                  "use gnulib module pipe for portability");
991 # endif
992 #endif
993
994
995 #if @GNULIB_PIPE2@
996 /* Create a pipe, applying the given flags when opening the read-end of the
997    pipe and the write-end of the pipe.
998    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
999    and O_TEXT, O_BINARY (defined in "binary-io.h").
1000    Store the read-end as fd[0] and the write-end as fd[1].
1001    Return 0 upon success, or -1 with errno set upon failure.
1002    See also the Linux man page at
1003    <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>.  */
1004 # if @HAVE_PIPE2@
1005 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1006 #   define pipe2 rpl_pipe2
1007 #  endif
1008 _GL_FUNCDECL_RPL (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
1009 _GL_CXXALIAS_RPL (pipe2, int, (int fd[2], int flags));
1010 # else
1011 _GL_FUNCDECL_SYS (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
1012 _GL_CXXALIAS_SYS (pipe2, int, (int fd[2], int flags));
1013 # endif
1014 _GL_CXXALIASWARN (pipe2);
1015 #elif defined GNULIB_POSIXCHECK
1016 # undef pipe2
1017 # if HAVE_RAW_DECL_PIPE2
1018 _GL_WARN_ON_USE (pipe2, "pipe2 is unportable - "
1019                  "use gnulib module pipe2 for portability");
1020 # endif
1021 #endif
1022
1023
1024 #if @GNULIB_PREAD@
1025 /* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
1026    Return the number of bytes placed into BUF if successful, otherwise
1027    set errno and return -1.  0 indicates EOF.  See the POSIX:2001
1028    specification <http://www.opengroup.org/susv3xsh/pread.html>.  */
1029 # if @REPLACE_PREAD@
1030 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1031 #   define pread rpl_pread
1032 #  endif
1033 _GL_FUNCDECL_RPL (pread, ssize_t,
1034                   (int fd, void *buf, size_t bufsize, off_t offset)
1035                   _GL_ARG_NONNULL ((2)));
1036 _GL_CXXALIAS_RPL (pread, ssize_t,
1037                   (int fd, void *buf, size_t bufsize, off_t offset));
1038 # else
1039 #  if !@HAVE_PREAD@
1040 _GL_FUNCDECL_SYS (pread, ssize_t,
1041                   (int fd, void *buf, size_t bufsize, off_t offset)
1042                   _GL_ARG_NONNULL ((2)));
1043 #  endif
1044 _GL_CXXALIAS_SYS (pread, ssize_t,
1045                   (int fd, void *buf, size_t bufsize, off_t offset));
1046 # endif
1047 _GL_CXXALIASWARN (pread);
1048 #elif defined GNULIB_POSIXCHECK
1049 # undef pread
1050 # if HAVE_RAW_DECL_PREAD
1051 _GL_WARN_ON_USE (pread, "pread is unportable - "
1052                  "use gnulib module pread for portability");
1053 # endif
1054 #endif
1055
1056
1057 #if @GNULIB_PWRITE@
1058 /* Write at most BUFSIZE bytes from BUF into FD, starting at OFFSET.
1059    Return the number of bytes written if successful, otherwise
1060    set errno and return -1.  0 indicates nothing written.  See the
1061    POSIX:2001 specification
1062    <http://www.opengroup.org/susv3xsh/pwrite.html>.  */
1063 # if @REPLACE_PWRITE@
1064 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1065 #   define pwrite rpl_pwrite
1066 #  endif
1067 _GL_FUNCDECL_RPL (pwrite, ssize_t,
1068                   (int fd, const void *buf, size_t bufsize, off_t offset)
1069                   _GL_ARG_NONNULL ((2)));
1070 _GL_CXXALIAS_RPL (pwrite, ssize_t,
1071                   (int fd, const void *buf, size_t bufsize, off_t offset));
1072 # else
1073 #  if !@HAVE_PWRITE@
1074 _GL_FUNCDECL_SYS (pwrite, ssize_t,
1075                   (int fd, const void *buf, size_t bufsize, off_t offset)
1076                   _GL_ARG_NONNULL ((2)));
1077 #  endif
1078 _GL_CXXALIAS_SYS (pwrite, ssize_t,
1079                   (int fd, const void *buf, size_t bufsize, off_t offset));
1080 # endif
1081 _GL_CXXALIASWARN (pwrite);
1082 #elif defined GNULIB_POSIXCHECK
1083 # undef pwrite
1084 # if HAVE_RAW_DECL_PWRITE
1085 _GL_WARN_ON_USE (pwrite, "pwrite is unportable - "
1086                  "use gnulib module pwrite for portability");
1087 # endif
1088 #endif
1089
1090
1091 #if @GNULIB_READLINK@
1092 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
1093    bytes of it into BUF.  Return the number of bytes placed into BUF if
1094    successful, otherwise -1 and errno set.
1095    See the POSIX:2001 specification
1096    <http://www.opengroup.org/susv3xsh/readlink.html>.  */
1097 # if @REPLACE_READLINK@
1098 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1099 #   define readlink rpl_readlink
1100 #  endif
1101 _GL_FUNCDECL_RPL (readlink, ssize_t,
1102                   (const char *file, char *buf, size_t bufsize)
1103                   _GL_ARG_NONNULL ((1, 2)));
1104 _GL_CXXALIAS_RPL (readlink, ssize_t,
1105                   (const char *file, char *buf, size_t bufsize));
1106 # else
1107 #  if !@HAVE_READLINK@
1108 _GL_FUNCDECL_SYS (readlink, ssize_t,
1109                   (const char *file, char *buf, size_t bufsize)
1110                   _GL_ARG_NONNULL ((1, 2)));
1111 #  endif
1112 _GL_CXXALIAS_SYS (readlink, ssize_t,
1113                   (const char *file, char *buf, size_t bufsize));
1114 # endif
1115 _GL_CXXALIASWARN (readlink);
1116 #elif defined GNULIB_POSIXCHECK
1117 # undef readlink
1118 # if HAVE_RAW_DECL_READLINK
1119 _GL_WARN_ON_USE (readlink, "readlink is unportable - "
1120                  "use gnulib module readlink for portability");
1121 # endif
1122 #endif
1123
1124
1125 #if @GNULIB_READLINKAT@
1126 # if !@HAVE_READLINKAT@
1127 _GL_FUNCDECL_SYS (readlinkat, ssize_t,
1128                   (int fd, char const *file, char *buf, size_t len)
1129                   _GL_ARG_NONNULL ((2, 3)));
1130 # endif
1131 _GL_CXXALIAS_SYS (readlinkat, ssize_t,
1132                   (int fd, char const *file, char *buf, size_t len));
1133 _GL_CXXALIASWARN (readlinkat);
1134 #elif defined GNULIB_POSIXCHECK
1135 # undef readlinkat
1136 # if HAVE_RAW_DECL_READLINKAT
1137 _GL_WARN_ON_USE (readlinkat, "readlinkat is not portable - "
1138                  "use gnulib module readlinkat for portability");
1139 # endif
1140 #endif
1141
1142
1143 #if @GNULIB_RMDIR@
1144 /* Remove the directory DIR.  */
1145 # if @REPLACE_RMDIR@
1146 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1147 #   define rmdir rpl_rmdir
1148 #  endif
1149 _GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1)));
1150 _GL_CXXALIAS_RPL (rmdir, int, (char const *name));
1151 # else
1152 _GL_CXXALIAS_SYS (rmdir, int, (char const *name));
1153 # endif
1154 _GL_CXXALIASWARN (rmdir);
1155 #elif defined GNULIB_POSIXCHECK
1156 # undef rmdir
1157 # if HAVE_RAW_DECL_RMDIR
1158 _GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
1159                  "use gnulib module rmdir for portability");
1160 # endif
1161 #endif
1162
1163
1164 #if @GNULIB_SLEEP@
1165 /* Pause the execution of the current thread for N seconds.
1166    Returns the number of seconds left to sleep.
1167    See the POSIX:2001 specification
1168    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
1169 # if @REPLACE_SLEEP@
1170 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1171 #   undef sleep
1172 #   define sleep rpl_sleep
1173 #  endif
1174 _GL_FUNCDECL_RPL (sleep, unsigned int, (unsigned int n));
1175 _GL_CXXALIAS_RPL (sleep, unsigned int, (unsigned int n));
1176 # else
1177 #  if !@HAVE_SLEEP@
1178 _GL_FUNCDECL_SYS (sleep, unsigned int, (unsigned int n));
1179 #  endif
1180 _GL_CXXALIAS_SYS (sleep, unsigned int, (unsigned int n));
1181 # endif
1182 _GL_CXXALIASWARN (sleep);
1183 #elif defined GNULIB_POSIXCHECK
1184 # undef sleep
1185 # if HAVE_RAW_DECL_SLEEP
1186 _GL_WARN_ON_USE (sleep, "sleep is unportable - "
1187                  "use gnulib module sleep for portability");
1188 # endif
1189 #endif
1190
1191
1192 #if @GNULIB_SYMLINK@
1193 # if @REPLACE_SYMLINK@
1194 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1195 #   undef symlink
1196 #   define symlink rpl_symlink
1197 #  endif
1198 _GL_FUNCDECL_RPL (symlink, int, (char const *contents, char const *file)
1199                                 _GL_ARG_NONNULL ((1, 2)));
1200 _GL_CXXALIAS_RPL (symlink, int, (char const *contents, char const *file));
1201 # else
1202 #  if !@HAVE_SYMLINK@
1203 _GL_FUNCDECL_SYS (symlink, int, (char const *contents, char const *file)
1204                                 _GL_ARG_NONNULL ((1, 2)));
1205 #  endif
1206 _GL_CXXALIAS_SYS (symlink, int, (char const *contents, char const *file));
1207 # endif
1208 _GL_CXXALIASWARN (symlink);
1209 #elif defined GNULIB_POSIXCHECK
1210 # undef symlink
1211 # if HAVE_RAW_DECL_SYMLINK
1212 _GL_WARN_ON_USE (symlink, "symlink is not portable - "
1213                  "use gnulib module symlink for portability");
1214 # endif
1215 #endif
1216
1217
1218 #if @GNULIB_SYMLINKAT@
1219 # if !@HAVE_SYMLINKAT@
1220 _GL_FUNCDECL_SYS (symlinkat, int,
1221                   (char const *contents, int fd, char const *file)
1222                   _GL_ARG_NONNULL ((1, 3)));
1223 # endif
1224 _GL_CXXALIAS_SYS (symlinkat, int,
1225                   (char const *contents, int fd, char const *file));
1226 _GL_CXXALIASWARN (symlinkat);
1227 #elif defined GNULIB_POSIXCHECK
1228 # undef symlinkat
1229 # if HAVE_RAW_DECL_SYMLINKAT
1230 _GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - "
1231                  "use gnulib module symlinkat for portability");
1232 # endif
1233 #endif
1234
1235
1236 #if @GNULIB_TTYNAME_R@
1237 /* Store at most BUFLEN characters of the pathname of the terminal FD is
1238    open on in BUF.  Return 0 on success, otherwise an error number.  */
1239 # if @REPLACE_TTYNAME_R@
1240 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1241 #   undef ttyname_r
1242 #   define ttyname_r rpl_ttyname_r
1243 #  endif
1244 _GL_FUNCDECL_RPL (ttyname_r, int,
1245                   (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2)));
1246 _GL_CXXALIAS_RPL (ttyname_r, int,
1247                   (int fd, char *buf, size_t buflen));
1248 # else
1249 #  if !@HAVE_TTYNAME_R@
1250 _GL_FUNCDECL_SYS (ttyname_r, int,
1251                   (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2)));
1252 #  endif
1253 _GL_CXXALIAS_SYS (ttyname_r, int,
1254                   (int fd, char *buf, size_t buflen));
1255 # endif
1256 _GL_CXXALIASWARN (ttyname_r);
1257 #elif defined GNULIB_POSIXCHECK
1258 # undef ttyname_r
1259 # if HAVE_RAW_DECL_TTYNAME_R
1260 _GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - "
1261                  "use gnulib module ttyname_r for portability");
1262 # endif
1263 #endif
1264
1265
1266 #if @GNULIB_UNLINK@
1267 # if @REPLACE_UNLINK@
1268 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1269 #   undef unlink
1270 #   define unlink rpl_unlink
1271 #  endif
1272 _GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1)));
1273 _GL_CXXALIAS_RPL (unlink, int, (char const *file));
1274 # else
1275 _GL_CXXALIAS_SYS (unlink, int, (char const *file));
1276 # endif
1277 _GL_CXXALIASWARN (unlink);
1278 #elif defined GNULIB_POSIXCHECK
1279 # undef unlink
1280 # if HAVE_RAW_DECL_UNLINK
1281 _GL_WARN_ON_USE (unlink, "unlink is not portable - "
1282                  "use gnulib module unlink for portability");
1283 # endif
1284 #endif
1285
1286
1287 #if @GNULIB_UNLINKAT@
1288 # if @REPLACE_UNLINKAT@
1289 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1290 #   undef unlinkat
1291 #   define unlinkat rpl_unlinkat
1292 #  endif
1293 _GL_FUNCDECL_RPL (unlinkat, int, (int fd, char const *file, int flag)
1294                                  _GL_ARG_NONNULL ((2)));
1295 _GL_CXXALIAS_RPL (unlinkat, int, (int fd, char const *file, int flag));
1296 # else
1297 #  if !@HAVE_UNLINKAT@
1298 _GL_FUNCDECL_SYS (unlinkat, int, (int fd, char const *file, int flag)
1299                                  _GL_ARG_NONNULL ((2)));
1300 #  endif
1301 _GL_CXXALIAS_SYS (unlinkat, int, (int fd, char const *file, int flag));
1302 # endif
1303 _GL_CXXALIASWARN (unlinkat);
1304 #elif defined GNULIB_POSIXCHECK
1305 # undef unlinkat
1306 # if HAVE_RAW_DECL_UNLINKAT
1307 _GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
1308                  "use gnulib module openat for portability");
1309 # endif
1310 #endif
1311
1312
1313 #if @GNULIB_USLEEP@
1314 /* Pause the execution of the current thread for N microseconds.
1315    Returns 0 on completion, or -1 on range error.
1316    See the POSIX:2001 specification
1317    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
1318 # if @REPLACE_USLEEP@
1319 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1320 #   undef usleep
1321 #   define usleep rpl_usleep
1322 #  endif
1323 _GL_FUNCDECL_RPL (usleep, int, (useconds_t n));
1324 _GL_CXXALIAS_RPL (usleep, int, (useconds_t n));
1325 # else
1326 #  if !@HAVE_USLEEP@
1327 _GL_FUNCDECL_SYS (usleep, int, (useconds_t n));
1328 #  endif
1329 _GL_CXXALIAS_SYS (usleep, int, (useconds_t n));
1330 # endif
1331 _GL_CXXALIASWARN (usleep);
1332 #elif defined GNULIB_POSIXCHECK
1333 # undef usleep
1334 # if HAVE_RAW_DECL_USLEEP
1335 _GL_WARN_ON_USE (usleep, "usleep is unportable - "
1336                  "use gnulib module usleep for portability");
1337 # endif
1338 #endif
1339
1340
1341 #if @GNULIB_WRITE@
1342 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
1343    See the POSIX:2001 specification
1344    <http://www.opengroup.org/susv3xsh/write.html>.  */
1345 # if @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
1346 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1347 #   undef write
1348 #   define write rpl_write
1349 #  endif
1350 _GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count)
1351                                   _GL_ARG_NONNULL ((2)));
1352 _GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count));
1353 # else
1354 /* Need to cast, because on mingw, the third parameter is
1355                                                              unsigned int count
1356    and the return type is 'int'.  */
1357 _GL_CXXALIAS_SYS_CAST (write, ssize_t, (int fd, const void *buf, size_t count));
1358 # endif
1359 _GL_CXXALIASWARN (write);
1360 #endif
1361
1362
1363 #endif /* _GL_UNISTD_H */
1364 #endif /* _GL_UNISTD_H */