build: pull in conditional headers during GNULIB_POSIXCHECK
[gnulib.git] / lib / unistd.in.h
1 /* Substitute for and wrapper around <unistd.h>.
2    Copyright (C) 2003-2009 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 #ifndef _GL_UNISTD_H
19
20 #if __GNUC__ >= 3
21 @PRAGMA_SYSTEM_HEADER@
22 #endif
23
24 /* The include_next requires a split double-inclusion guard.  */
25 #if @HAVE_UNISTD_H@
26 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
27 #endif
28
29 #ifndef _GL_UNISTD_H
30 #define _GL_UNISTD_H
31
32 /* NetBSD 5.0 mis-defines NULL.  Also get size_t.  */
33 #include <stddef.h>
34
35 /* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>.  */
36 /* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>.  */
37 #if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
38      || @GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK)
39 # include <stdio.h>
40 #endif
41
42 /* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>.  */
43 #if @GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK
44 # include <fcntl.h>
45 #endif
46
47 /* mingw fails to declare _exit in <unistd.h>.  */
48 /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>.  */
49 /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>.  */
50 #include <stdlib.h>
51
52 /* mingw declares getcwd in <io.h>, not in <unistd.h>.  */
53 #if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \
54      && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
55 # include <io.h>
56 #endif
57
58 #if ((@GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@)   \
59      || (@GNULIB_READLINK@ && (!@HAVE_READLINK@ || @REPLACE_READLINK@)) \
60      || (@GNULIB_READLINKAT@ && !@HAVE_READLINKAT@) \
61      || defined GNULIB_POSIXCHECK)
62 /* Get ssize_t.  */
63 # include <sys/types.h>
64 #endif
65
66 /* Get getopt(), optarg, optind, opterr, optopt.  */
67 #if @GNULIB_UNISTD_H_GETOPT@ && !defined _GL_SYSTEM_GETOPT
68 # include <getopt.h>
69 #endif
70
71 #if @GNULIB_GETHOSTNAME@
72 /* Get all possible declarations of gethostname().  */
73 # if @UNISTD_H_HAVE_WINSOCK2_H@
74 #  include <winsock2.h>
75 #  if !defined _GL_SYS_SOCKET_H
76 #   undef socket
77 #   define socket               socket_used_without_including_sys_socket_h
78 #   undef connect
79 #   define connect              connect_used_without_including_sys_socket_h
80 #   undef accept
81 #   define accept               accept_used_without_including_sys_socket_h
82 #   undef bind
83 #   define bind                 bind_used_without_including_sys_socket_h
84 #   undef getpeername
85 #   define getpeername          getpeername_used_without_including_sys_socket_h
86 #   undef getsockname
87 #   define getsockname          getsockname_used_without_including_sys_socket_h
88 #   undef getsockopt
89 #   define getsockopt           getsockopt_used_without_including_sys_socket_h
90 #   undef listen
91 #   define listen               listen_used_without_including_sys_socket_h
92 #   undef recv
93 #   define recv                 recv_used_without_including_sys_socket_h
94 #   undef send
95 #   define send                 send_used_without_including_sys_socket_h
96 #   undef recvfrom
97 #   define recvfrom             recvfrom_used_without_including_sys_socket_h
98 #   undef sendto
99 #   define sendto               sendto_used_without_including_sys_socket_h
100 #   undef setsockopt
101 #   define setsockopt           setsockopt_used_without_including_sys_socket_h
102 #   undef shutdown
103 #   define shutdown             shutdown_used_without_including_sys_socket_h
104 #  endif
105 #  if !defined _GL_SYS_SELECT_H
106 #   undef select
107 #   define select               select_used_without_including_sys_select_h
108 #  endif
109 # endif
110 #endif
111
112 /* The definition of GL_LINK_WARNING is copied here.  */
113
114 /* The definition of _GL_ARG_NONNULL is copied here.  */
115
116
117 /* OS/2 EMX lacks these macros.  */
118 #ifndef STDIN_FILENO
119 # define STDIN_FILENO 0
120 #endif
121 #ifndef STDOUT_FILENO
122 # define STDOUT_FILENO 1
123 #endif
124 #ifndef STDERR_FILENO
125 # define STDERR_FILENO 2
126 #endif
127
128 /* Ensure *_OK macros exist.  */
129 #ifndef F_OK
130 # define F_OK 0
131 # define X_OK 1
132 # define W_OK 2
133 # define R_OK 4
134 #endif
135
136
137 /* Declare overridden functions.  */
138
139 #ifdef __cplusplus
140 extern "C" {
141 #endif
142
143
144 #if @GNULIB_CHOWN@
145 # if @REPLACE_CHOWN@
146 #  undef chown
147 #  define chown rpl_chown
148 # endif
149 # if !@HAVE_CHOWN@ || @REPLACE_CHOWN@
150 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
151    to GID (if GID is not -1).  Follow symbolic links.
152    Return 0 if successful, otherwise -1 and errno set.
153    See the POSIX:2001 specification
154    <http://www.opengroup.org/susv3xsh/chown.html>.  */
155 extern int chown (const char *file, uid_t uid, gid_t gid)
156      _GL_ARG_NONNULL ((1));
157 # endif
158 #elif defined GNULIB_POSIXCHECK
159 # undef chown
160 # define chown(f,u,g) \
161     (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
162                       "doesn't treat a uid or gid of -1 on some systems - " \
163                       "use gnulib module chown for portability"), \
164      chown (f, u, g))
165 #endif
166
167
168 #if @GNULIB_CLOSE@
169 # if @REPLACE_CLOSE@
170 /* Automatically included by modules that need a replacement for close.  */
171 #  undef close
172 #  define close rpl_close
173 extern int close (int);
174 # endif
175 #elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
176 # undef close
177 # define close close_used_without_requesting_gnulib_module_close
178 #elif defined GNULIB_POSIXCHECK
179 # undef close
180 # define close(f) \
181     (GL_LINK_WARNING ("close does not portably work on sockets - " \
182                       "use gnulib module close for portability"), \
183      close (f))
184 #endif
185
186
187 #if @REPLACE_DUP@
188 # define dup rpl_dup
189 extern int dup (int);
190 #endif
191
192
193 #if @GNULIB_DUP2@
194 # if @REPLACE_DUP2@
195 #  define dup2 rpl_dup2
196 # endif
197 # if !@HAVE_DUP2@ || @REPLACE_DUP2@
198 /* Copy the file descriptor OLDFD into file descriptor NEWFD.  Do nothing if
199    NEWFD = OLDFD, otherwise close NEWFD first if it is open.
200    Return newfd if successful, otherwise -1 and errno set.
201    See the POSIX:2001 specification
202    <http://www.opengroup.org/susv3xsh/dup2.html>.  */
203 extern int dup2 (int oldfd, int newfd);
204 # endif
205 #elif defined GNULIB_POSIXCHECK
206 # undef dup2
207 # define dup2(o,n) \
208     (GL_LINK_WARNING ("dup2 is unportable - " \
209                       "use gnulib module dup2 for portability"), \
210      dup2 (o, n))
211 #endif
212
213
214 #if @GNULIB_DUP3@
215 /* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
216    specified flags.
217    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
218    and O_TEXT, O_BINARY (defined in "binary-io.h").
219    Close NEWFD first if it is open.
220    Return newfd if successful, otherwise -1 and errno set.
221    See the Linux man page at
222    <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>.  */
223 # if @HAVE_DUP3@
224 #  define dup3 rpl_dup3
225 # endif
226 extern int dup3 (int oldfd, int newfd, int flags);
227 #elif defined GNULIB_POSIXCHECK
228 # undef dup3
229 # define dup3(o,n,f) \
230     (GL_LINK_WARNING ("dup3 is unportable - " \
231                       "use gnulib module dup3 for portability"), \
232      dup3 (o, n, f))
233 #endif
234
235
236 #if @GNULIB_ENVIRON@
237 # if !@HAVE_DECL_ENVIRON@
238 /* Set of environment variables and values.  An array of strings of the form
239    "VARIABLE=VALUE", terminated with a NULL.  */
240 #  if defined __APPLE__ && defined __MACH__
241 #   include <crt_externs.h>
242 #   define environ (*_NSGetEnviron ())
243 #  else
244 extern char **environ;
245 #  endif
246 # endif
247 #elif defined GNULIB_POSIXCHECK
248 # undef environ
249 # define environ \
250     (GL_LINK_WARNING ("environ is unportable - " \
251                       "use gnulib module environ for portability"), \
252      environ)
253 #endif
254
255
256 #if @GNULIB_EUIDACCESS@
257 # if !@HAVE_EUIDACCESS@
258 /* Like access(), except that it uses the effective user id and group id of
259    the current process.  */
260 extern int euidaccess (const char *filename, int mode) _GL_ARG_NONNULL ((1));
261 # endif
262 #elif defined GNULIB_POSIXCHECK
263 # undef euidaccess
264 # define euidaccess(f,m) \
265     (GL_LINK_WARNING ("euidaccess is unportable - " \
266                       "use gnulib module euidaccess for portability"), \
267      euidaccess (f, m))
268 #endif
269
270
271 #if @GNULIB_FACCESSAT@
272 # if !@HAVE_FACCESSAT@
273 extern int faccessat (int fd, char const *file, int mode, int flag)
274      _GL_ARG_NONNULL ((2));
275 # endif
276 #elif defined GNULIB_POSIXCHECK
277 # undef faccessat
278 # define faccessat(d,n,m,f)                         \
279     (GL_LINK_WARNING ("faccessat is not portable - " \
280                       "use gnulib module faccessat for portability"), \
281      faccessat (d, n, m, f))
282 #endif
283
284
285 #if @GNULIB_FCHDIR@
286 # if @REPLACE_FCHDIR@
287 /* Change the process' current working directory to the directory on which
288    the given file descriptor is open.
289    Return 0 if successful, otherwise -1 and errno set.
290    See the POSIX:2001 specification
291    <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
292 extern int fchdir (int /*fd*/);
293
294 /* Gnulib internal hooks needed to maintain the fchdir metadata.  */
295 extern int _gl_register_fd (int fd, const char *filename)
296      _GL_ARG_NONNULL ((2));
297 extern void _gl_unregister_fd (int fd);
298 extern int _gl_register_dup (int oldfd, int newfd);
299 extern const char *_gl_directory_name (int fd);
300
301 # endif
302 #elif defined GNULIB_POSIXCHECK
303 # undef fchdir
304 # define fchdir(f) \
305     (GL_LINK_WARNING ("fchdir is unportable - " \
306                       "use gnulib module fchdir for portability"), \
307      fchdir (f))
308 #endif
309
310
311 #if @GNULIB_FCHOWNAT@
312 # if @REPLACE_FCHOWNAT@
313 #  undef fchownat
314 #  define fchownat rpl_fchownat
315 # endif
316 # if !@HAVE_FCHOWNAT@ || @REPLACE_FCHOWNAT@
317 extern int fchownat (int fd, char const *file, uid_t owner, gid_t group, int flag)
318      _GL_ARG_NONNULL ((2));
319 # endif
320 #elif defined GNULIB_POSIXCHECK
321 # undef fchownat
322 # define fchownat(d,n,o,g,f)                        \
323     (GL_LINK_WARNING ("fchownat is not portable - " \
324                       "use gnulib module openat for portability"), \
325      fchownat (d, n, o, g, f))
326 #endif
327
328
329 #if @GNULIB_FSYNC@
330 /* Synchronize changes to a file.
331    Return 0 if successful, otherwise -1 and errno set.
332    See POSIX:2001 specification
333    <http://www.opengroup.org/susv3xsh/fsync.html>.  */
334 # if !@HAVE_FSYNC@
335 extern int fsync (int fd);
336 # endif
337 #elif defined GNULIB_POSIXCHECK
338 # undef fsync
339 # define fsync(fd) \
340     (GL_LINK_WARNING ("fsync is unportable - " \
341                       "use gnulib module fsync for portability"), \
342      fsync (fd))
343 #endif
344
345
346 #if @GNULIB_FTRUNCATE@
347 # if !@HAVE_FTRUNCATE@
348 /* Change the size of the file to which FD is opened to become equal to LENGTH.
349    Return 0 if successful, otherwise -1 and errno set.
350    See the POSIX:2001 specification
351    <http://www.opengroup.org/susv3xsh/ftruncate.html>.  */
352 extern int ftruncate (int fd, off_t length);
353 # endif
354 #elif defined GNULIB_POSIXCHECK
355 # undef ftruncate
356 # define ftruncate(f,l) \
357     (GL_LINK_WARNING ("ftruncate is unportable - " \
358                       "use gnulib module ftruncate for portability"), \
359      ftruncate (f, l))
360 #endif
361
362
363 #if @GNULIB_GETCWD@
364 # if @REPLACE_GETCWD@
365 /* Get the name of the current working directory, and put it in SIZE bytes
366    of BUF.
367    Return BUF if successful, or NULL if the directory couldn't be determined
368    or SIZE was too small.
369    See the POSIX:2001 specification
370    <http://www.opengroup.org/susv3xsh/getcwd.html>.
371    Additionally, the gnulib module 'getcwd' guarantees the following GNU
372    extension: If BUF is NULL, an array is allocated with 'malloc'; the array
373    is SIZE bytes long, unless SIZE == 0, in which case it is as big as
374    necessary.  */
375 #  define getcwd rpl_getcwd
376 extern char * getcwd (char *buf, size_t size);
377 # endif
378 #elif defined GNULIB_POSIXCHECK
379 # undef getcwd
380 # define getcwd(b,s) \
381     (GL_LINK_WARNING ("getcwd is unportable - " \
382                       "use gnulib module getcwd for portability"), \
383      getcwd (b, s))
384 #endif
385
386
387 #if @GNULIB_GETDOMAINNAME@
388 /* Return the NIS domain name of the machine.
389    WARNING! The NIS domain name is unrelated to the fully qualified host name
390             of the machine.  It is also unrelated to email addresses.
391    WARNING! The NIS domain name is usually the empty string or "(none)" when
392             not using NIS.
393
394    Put up to LEN bytes of the NIS domain name into NAME.
395    Null terminate it if the name is shorter than LEN.
396    If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
397    Return 0 if successful, otherwise set errno and return -1.  */
398 # if !@HAVE_GETDOMAINNAME@
399 extern int getdomainname(char *name, size_t len) _GL_ARG_NONNULL ((1));
400 # endif
401 #elif defined GNULIB_POSIXCHECK
402 # undef getdomainname
403 # define getdomainname(n,l) \
404     (GL_LINK_WARNING ("getdomainname is unportable - " \
405                       "use gnulib module getdomainname for portability"), \
406      getdomainname (n, l))
407 #endif
408
409
410 #if @GNULIB_GETDTABLESIZE@
411 # if !@HAVE_GETDTABLESIZE@
412 /* Return the maximum number of file descriptors in the current process.
413    In POSIX, this is same as sysconf (_SC_OPEN_MAX).  */
414 extern int getdtablesize (void);
415 # endif
416 #elif defined GNULIB_POSIXCHECK
417 # undef getdtablesize
418 # define getdtablesize() \
419     (GL_LINK_WARNING ("getdtablesize is unportable - " \
420                       "use gnulib module getdtablesize for portability"), \
421      getdtablesize ())
422 #endif
423
424
425 #if @GNULIB_GETGROUPS@
426 # if @REPLACE_GETGROUPS@
427 #  undef getgroups
428 #  define getgroups rpl_getgroups
429 # endif
430 # if !@HAVE_GETGROUPS@ || @REPLACE_GETGROUPS@
431 /* Return the supplemental groups that the current process belongs to.
432    It is unspecified whether the effective group id is in the list.
433    If N is 0, return the group count; otherwise, N describes how many
434    entries are available in GROUPS.  Return -1 and set errno if N is
435    not 0 and not large enough.  Fails with ENOSYS on some systems.  */
436 int getgroups (int n, gid_t *groups);
437 # endif
438 #elif defined GNULIB_POSIXCHECK
439 # undef getgroups
440 # define getgroups(n,g)                                                 \
441     (GL_LINK_WARNING ("getgroups is unportable - "                      \
442                       "use gnulib module getgroups for portability"),   \
443      getgroups (n, g))
444 #endif
445
446
447 #if @GNULIB_GETHOSTNAME@
448 /* Return the standard host name of the machine.
449    WARNING! The host name may or may not be fully qualified.
450
451    Put up to LEN bytes of the host name into NAME.
452    Null terminate it if the name is shorter than LEN.
453    If the host name is longer than LEN, set errno = EINVAL and return -1.
454    Return 0 if successful, otherwise set errno and return -1.  */
455 # if @UNISTD_H_HAVE_WINSOCK2_H@
456 #  undef gethostname
457 #  define gethostname rpl_gethostname
458 # endif
459 # if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@
460 extern int gethostname(char *name, size_t len) _GL_ARG_NONNULL ((1));
461 # endif
462 #elif @UNISTD_H_HAVE_WINSOCK2_H@
463 # undef gethostname
464 # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
465 #elif defined GNULIB_POSIXCHECK
466 # undef gethostname
467 # define gethostname(n,l) \
468     (GL_LINK_WARNING ("gethostname is unportable - " \
469                       "use gnulib module gethostname for portability"), \
470      gethostname (n, l))
471 #endif
472
473
474 #if @GNULIB_GETLOGIN_R@
475 /* Copies the user's login name to NAME.
476    The array pointed to by NAME has room for SIZE bytes.
477
478    Returns 0 if successful.  Upon error, an error number is returned, or -1 in
479    the case that the login name cannot be found but no specific error is
480    provided (this case is hopefully rare but is left open by the POSIX spec).
481
482    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
483  */
484 # if !@HAVE_DECL_GETLOGIN_R@
485 extern int getlogin_r (char *name, size_t size) _GL_ARG_NONNULL ((1));
486 # endif
487 #elif defined GNULIB_POSIXCHECK
488 # undef getlogin_r
489 # define getlogin_r(n,s) \
490     (GL_LINK_WARNING ("getlogin_r is unportable - " \
491                       "use gnulib module getlogin_r for portability"), \
492      getlogin_r (n, s))
493 #endif
494
495
496 #if @GNULIB_GETPAGESIZE@
497 # if @REPLACE_GETPAGESIZE@
498 #  define getpagesize rpl_getpagesize
499 extern int getpagesize (void);
500 # elif !@HAVE_GETPAGESIZE@
501 /* This is for POSIX systems.  */
502 #  if !defined getpagesize && defined _SC_PAGESIZE
503 #   if ! (defined __VMS && __VMS_VER < 70000000)
504 #    define getpagesize() sysconf (_SC_PAGESIZE)
505 #   endif
506 #  endif
507 /* This is for older VMS.  */
508 #  if !defined getpagesize && defined __VMS
509 #   ifdef __ALPHA
510 #    define getpagesize() 8192
511 #   else
512 #    define getpagesize() 512
513 #   endif
514 #  endif
515 /* This is for BeOS.  */
516 #  if !defined getpagesize && @HAVE_OS_H@
517 #   include <OS.h>
518 #   if defined B_PAGE_SIZE
519 #    define getpagesize() B_PAGE_SIZE
520 #   endif
521 #  endif
522 /* This is for AmigaOS4.0.  */
523 #  if !defined getpagesize && defined __amigaos4__
524 #   define getpagesize() 2048
525 #  endif
526 /* This is for older Unix systems.  */
527 #  if !defined getpagesize && @HAVE_SYS_PARAM_H@
528 #   include <sys/param.h>
529 #   ifdef EXEC_PAGESIZE
530 #    define getpagesize() EXEC_PAGESIZE
531 #   else
532 #    ifdef NBPG
533 #     ifndef CLSIZE
534 #      define CLSIZE 1
535 #     endif
536 #     define getpagesize() (NBPG * CLSIZE)
537 #    else
538 #     ifdef NBPC
539 #      define getpagesize() NBPC
540 #     endif
541 #    endif
542 #   endif
543 #  endif
544 # endif
545 #elif defined GNULIB_POSIXCHECK
546 # undef getpagesize
547 # define getpagesize() \
548     (GL_LINK_WARNING ("getpagesize is unportable - " \
549                       "use gnulib module getpagesize for portability"), \
550      getpagesize ())
551 #endif
552
553
554 #if @GNULIB_GETUSERSHELL@
555 # if !@HAVE_GETUSERSHELL@
556 /* Return the next valid login shell on the system, or NULL when the end of
557    the list has been reached.  */
558 extern char *getusershell (void);
559 /* Rewind to pointer that is advanced at each getusershell() call.  */
560 extern void setusershell (void);
561 /* Free the pointer that is advanced at each getusershell() call and
562    associated resources.  */
563 extern void endusershell (void);
564 # endif
565 #elif defined GNULIB_POSIXCHECK
566 # undef getusershell
567 # define getusershell() \
568     (GL_LINK_WARNING ("getusershell is unportable - " \
569                       "use gnulib module getusershell for portability"), \
570      getusershell ())
571 # undef setusershell
572 # define setusershell() \
573     (GL_LINK_WARNING ("setusershell is unportable - " \
574                       "use gnulib module getusershell for portability"), \
575      setusershell ())
576 # undef endusershell
577 # define endusershell() \
578     (GL_LINK_WARNING ("endusershell is unportable - " \
579                       "use gnulib module getusershell for portability"), \
580      endusershell ())
581 #endif
582
583
584 #if @GNULIB_LCHOWN@
585 # if @REPLACE_LCHOWN@
586 #  undef lchown
587 #  define lchown rpl_lchown
588 # endif
589 # if !@HAVE_LCHOWN@ || @REPLACE_LCHOWN@
590 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
591    to GID (if GID is not -1).  Do not follow symbolic links.
592    Return 0 if successful, otherwise -1 and errno set.
593    See the POSIX:2001 specification
594    <http://www.opengroup.org/susv3xsh/lchown.html>.  */
595 extern int lchown (char const *file, uid_t owner, gid_t group)
596      _GL_ARG_NONNULL ((1));
597 # endif
598 #elif defined GNULIB_POSIXCHECK
599 # undef lchown
600 # define lchown(f,u,g) \
601     (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
602                       "systems - use gnulib module lchown for portability"), \
603      lchown (f, u, g))
604 #endif
605
606
607 #if @GNULIB_LINK@
608 # if @REPLACE_LINK@
609 #  define link rpl_link
610 # endif
611 /* Create a new hard link for an existing file.
612    Return 0 if successful, otherwise -1 and errno set.
613    See POSIX:2001 specification
614    <http://www.opengroup.org/susv3xsh/link.html>.  */
615 # if !@HAVE_LINK@ || @REPLACE_LINK@
616 extern int link (const char *path1, const char *path2)
617      _GL_ARG_NONNULL ((1, 2));
618 # endif
619 #elif defined GNULIB_POSIXCHECK
620 # undef link
621 # define link(path1,path2) \
622     (GL_LINK_WARNING ("link is unportable - " \
623                       "use gnulib module link for portability"), \
624      link (path1, path2))
625 #endif
626
627 #if @GNULIB_LINKAT@
628 # if @REPLACE_LINKAT@
629 #  undef linkat
630 #  define linkat rpl_linkat
631 # endif
632 /* Create a new hard link for an existing file, relative to two
633    directories.  FLAG controls whether symlinks are followed.
634    Return 0 if successful, otherwise -1 and errno set.  */
635 # if !@HAVE_LINKAT@ || @REPLACE_LINKAT@
636 extern int linkat (int fd1, const char *path1, int fd2, const char *path2,
637                    int flag)
638      _GL_ARG_NONNULL ((2, 4));
639 # endif
640 #elif defined GNULIB_POSIXCHECK
641 # undef linkat
642 # define link(f1,path1,f2,path2,f)              \
643     (GL_LINK_WARNING ("linkat is unportable - " \
644                       "use gnulib module linkat for portability"), \
645      linkat (f1, path1, f2, path2,f))
646 #endif
647
648 #if @GNULIB_LSEEK@
649 # if @REPLACE_LSEEK@
650 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
651    Return the new offset if successful, otherwise -1 and errno set.
652    See the POSIX:2001 specification
653    <http://www.opengroup.org/susv3xsh/lseek.html>.  */
654 #  define lseek rpl_lseek
655    extern off_t lseek (int fd, off_t offset, int whence);
656 # endif
657 #elif defined GNULIB_POSIXCHECK
658 # undef lseek
659 # define lseek(f,o,w) \
660     (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
661                       "systems - use gnulib module lseek for portability"), \
662      lseek (f, o, w))
663 #endif
664
665
666 #if @GNULIB_PIPE2@
667 /* Create a pipe, applying the given flags when opening the read-end of the
668    pipe and the write-end of the pipe.
669    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
670    and O_TEXT, O_BINARY (defined in "binary-io.h").
671    Store the read-end as fd[0] and the write-end as fd[1].
672    Return 0 upon success, or -1 with errno set upon failure.
673    See also the Linux man page at
674    <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>.  */
675 # if @HAVE_PIPE2@
676 #  define pipe2 rpl_pipe2
677 # endif
678 extern int pipe2 (int fd[2], int flags) _GL_ARG_NONNULL ((1));
679 #elif defined GNULIB_POSIXCHECK
680 # undef pipe2
681 # define pipe2(f,o) \
682     (GL_LINK_WARNING ("pipe2 is unportable - " \
683                       "use gnulib module pipe2 for portability"), \
684      pipe2 (f, o))
685 #endif
686
687
688 #if @GNULIB_PREAD@
689 # if @REPLACE_PREAD@
690 #  define pread rpl_pread
691 # endif
692 /* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
693    Return the number of bytes placed into BUF if successful, otherwise
694    set errno and return -1.  0 indicates EOF.  See the POSIX:2001
695    specification <http://www.opengroup.org/susv3xsh/pread.html>.  */
696 # if !@HAVE_PREAD@ || @REPLACE_PREAD@
697   extern ssize_t pread (int fd, void *buf, size_t bufsize, off_t offset)
698        _GL_ARG_NONNULL ((2));
699 # endif
700 #elif defined GNULIB_POSIXCHECK
701 # undef pread
702 # define pread(f,b,s,o)                        \
703     (GL_LINK_WARNING ("pread is unportable - " \
704                       "use gnulib module pread for portability"), \
705      pread (f, b, s, o))
706 #endif
707
708
709 #if @GNULIB_READLINK@
710 # if @REPLACE_READLINK@
711 #  define readlink rpl_readlink
712 # endif
713 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
714    bytes of it into BUF.  Return the number of bytes placed into BUF if
715    successful, otherwise -1 and errno set.
716    See the POSIX:2001 specification
717    <http://www.opengroup.org/susv3xsh/readlink.html>.  */
718 # if !@HAVE_READLINK@ || @REPLACE_READLINK@
719 extern ssize_t readlink (const char *file, char *buf, size_t bufsize)
720      _GL_ARG_NONNULL ((1, 2));
721 # endif
722 #elif defined GNULIB_POSIXCHECK
723 # undef readlink
724 # define readlink(f,b,s) \
725     (GL_LINK_WARNING ("readlink is unportable - " \
726                       "use gnulib module readlink for portability"), \
727      readlink (f, b, s))
728 #endif
729
730
731 #if @GNULIB_READLINKAT@
732 # if !@HAVE_READLINKAT@
733 extern ssize_t readlinkat (int fd, char const *file, char *buf, size_t len)
734      _GL_ARG_NONNULL ((2, 3));
735 # endif
736 #elif defined GNULIB_POSIXCHECK
737 # undef readlinkat
738 # define readlinkat(d,n,b,l)                         \
739     (GL_LINK_WARNING ("readlinkat is not portable - " \
740                       "use gnulib module symlinkat for portability"), \
741      readlinkat (d, n, b, l))
742 #endif
743
744
745 #if @GNULIB_RMDIR@
746 # if @REPLACE_RMDIR@
747 #  define rmdir rpl_rmdir
748 /* Remove the directory DIR.  */
749 extern int rmdir (char const *name) _GL_ARG_NONNULL ((1));
750 # endif
751 #elif defined GNULIB_POSIXCHECK
752 # undef rmdir
753 # define rmdir(n) \
754     (GL_LINK_WARNING ("rmdir is unportable - " \
755                       "use gnulib module rmdir for portability"), \
756      rmdir (n))
757 #endif
758
759
760 #if @GNULIB_SLEEP@
761 # if @REPLACE_SLEEP@
762 #  undef sleep
763 #  define sleep rpl_sleep
764 # endif
765 /* Pause the execution of the current thread for N seconds.
766    Returns the number of seconds left to sleep.
767    See the POSIX:2001 specification
768    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
769 # if !@HAVE_SLEEP@ || @REPLACE_SLEEP@
770 extern unsigned int sleep (unsigned int n);
771 # endif
772 #elif defined GNULIB_POSIXCHECK
773 # undef sleep
774 # define sleep(n) \
775     (GL_LINK_WARNING ("sleep is unportable - " \
776                       "use gnulib module sleep for portability"), \
777      sleep (n))
778 #endif
779
780
781 #if @GNULIB_SYMLINK@
782 # if @REPLACE_SYMLINK@
783 #  undef symlink
784 #  define symlink rpl_symlink
785 # endif
786 # if !@HAVE_SYMLINK@ || @REPLACE_SYMLINK@
787 extern int symlink (char const *contents, char const *file)
788      _GL_ARG_NONNULL ((1, 2));
789 # endif
790 #elif defined GNULIB_POSIXCHECK
791 # undef symlink
792 # define symlink(c,n)                        \
793     (GL_LINK_WARNING ("symlink is not portable - " \
794                       "use gnulib module symlink for portability"), \
795      symlink (c, n))
796 #endif
797
798
799 #if @GNULIB_SYMLINKAT@
800 # if !@HAVE_SYMLINKAT@
801 extern int symlinkat (char const *contents, int fd, char const *file)
802      _GL_ARG_NONNULL ((1, 3));
803 # endif
804 #elif defined GNULIB_POSIXCHECK
805 # undef symlinkat
806 # define symlinkat(c,d,n)                            \
807     (GL_LINK_WARNING ("symlinkat is not portable - " \
808                       "use gnulib module symlinkat for portability"), \
809      symlinkat (c, d, n))
810 #endif
811
812
813 #if @GNULIB_UNLINK@
814 # if @REPLACE_UNLINK@
815 #  undef unlink
816 #  define unlink rpl_unlink
817 extern int unlink (char const *file) _GL_ARG_NONNULL ((1));
818 # endif
819 #elif defined GNULIB_POSIXCHECK
820 # undef unlink
821 # define unlink(n)                         \
822     (GL_LINK_WARNING ("unlink is not portable - " \
823                       "use gnulib module unlink for portability"), \
824      unlink (n))
825 #endif
826
827
828 #if @GNULIB_UNLINKAT@
829 # if @REPLACE_UNLINKAT@
830 #  undef unlinkat
831 #  define unlinkat rpl_unlinkat
832 # endif
833 # if !@HAVE_UNLINKAT@ || @REPLACE_UNLINKAT@
834 extern int unlinkat (int fd, char const *file, int flag) _GL_ARG_NONNULL ((2));
835 # endif
836 #elif defined GNULIB_POSIXCHECK
837 # undef unlinkat
838 # define unlinkat(d,n,f)                         \
839     (GL_LINK_WARNING ("unlinkat is not portable - " \
840                       "use gnulib module openat for portability"), \
841      unlinkat (d, n, f))
842 #endif
843
844
845 #if @GNULIB_USLEEP@
846 # if @REPLACE_USLEEP@
847 #  undef usleep
848 #  define usleep rpl_usleep
849 # endif
850 # if !@HAVE_USLEEP@ || @REPLACE_USLEEP@
851 /* Pause the execution of the current thread for N microseconds.
852    Returns 0 on completion, or -1 on range error.
853    See the POSIX:2001 specification
854    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
855 extern int usleep (useconds_t n);
856 # endif
857 #elif defined GNULIB_POSIXCHECK
858 # undef usleep
859 # define usleep(n) \
860     (GL_LINK_WARNING ("usleep is unportable - " \
861                       "use gnulib module usleep for portability"), \
862      usleep (n))
863 #endif
864
865
866 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
867 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
868    See the POSIX:2001 specification
869    <http://www.opengroup.org/susv3xsh/write.html>.  */
870 # undef write
871 # define write rpl_write
872 extern ssize_t write (int fd, const void *buf, size_t count)
873      _GL_ARG_NONNULL ((2));
874 #endif
875
876
877 #ifdef __cplusplus
878 }
879 #endif
880
881
882 #endif /* _GL_UNISTD_H */
883 #endif /* _GL_UNISTD_H */