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