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