link: fix platform bugs
[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 #elif defined GNULIB_POSIXCHECK
197 # undef symlinkat
198 # define symlinkat(c,d,n)                            \
199     (GL_LINK_WARNING ("symlinkat is not portable - " \
200                       "use gnulib module symlinkat for portability"), \
201      symlinkat (c, d, n))
202 #endif
203
204 #if @GNULIB_READLINKAT@
205 # if !@HAVE_READLINKAT@
206 ssize_t readlinkat (int fd, char const *file, char *buf, size_t len);
207 # endif
208 #elif defined GNULIB_POSIXCHECK
209 # undef readlinkat
210 # define readlinkat(d,n,b,l)                         \
211     (GL_LINK_WARNING ("readlinkat is not portable - " \
212                       "use gnulib module symlinkat for portability"), \
213      readlinkat (d, n, b, l))
214 #endif
215
216 #if @GNULIB_CLOSE@
217 # if @REPLACE_CLOSE@
218 /* Automatically included by modules that need a replacement for close.  */
219 #  undef close
220 #  define close rpl_close
221 extern int close (int);
222 # endif
223 #elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
224 # undef close
225 # define close close_used_without_requesting_gnulib_module_close
226 #elif defined GNULIB_POSIXCHECK
227 # undef close
228 # define close(f) \
229     (GL_LINK_WARNING ("close does not portably work on sockets - " \
230                       "use gnulib module close for portability"), \
231      close (f))
232 #endif
233
234
235 #if @GNULIB_DUP2@
236 # if @REPLACE_DUP2@
237 #  define dup2 rpl_dup2
238 # endif
239 # if !@HAVE_DUP2@ || @REPLACE_DUP2@
240 /* Copy the file descriptor OLDFD into file descriptor NEWFD.  Do nothing if
241    NEWFD = OLDFD, otherwise close NEWFD first if it is open.
242    Return newfd if successful, otherwise -1 and errno set.
243    See the POSIX:2001 specification
244    <http://www.opengroup.org/susv3xsh/dup2.html>.  */
245 extern int dup2 (int oldfd, int newfd);
246 # endif
247 #elif defined GNULIB_POSIXCHECK
248 # undef dup2
249 # define dup2(o,n) \
250     (GL_LINK_WARNING ("dup2 is unportable - " \
251                       "use gnulib module dup2 for portability"), \
252      dup2 (o, n))
253 #endif
254
255
256 #if @GNULIB_DUP3@
257 /* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
258    specified flags.
259    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
260    and O_TEXT, O_BINARY (defined in "binary-io.h").
261    Close NEWFD first if it is open.
262    Return newfd if successful, otherwise -1 and errno set.
263    See the Linux man page at
264    <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>.  */
265 # if @HAVE_DUP3@
266 #  define dup3 rpl_dup3
267 # endif
268 extern int dup3 (int oldfd, int newfd, int flags);
269 #elif defined GNULIB_POSIXCHECK
270 # undef dup3
271 # define dup3(o,n,f) \
272     (GL_LINK_WARNING ("dup3 is unportable - " \
273                       "use gnulib module dup3 for portability"), \
274      dup3 (o, n, f))
275 #endif
276
277
278 #if @GNULIB_ENVIRON@
279 # if !@HAVE_DECL_ENVIRON@
280 /* Set of environment variables and values.  An array of strings of the form
281    "VARIABLE=VALUE", terminated with a NULL.  */
282 #  if defined __APPLE__ && defined __MACH__
283 #   include <crt_externs.h>
284 #   define environ (*_NSGetEnviron ())
285 #  else
286 extern char **environ;
287 #  endif
288 # endif
289 #elif defined GNULIB_POSIXCHECK
290 # undef environ
291 # define environ \
292     (GL_LINK_WARNING ("environ is unportable - " \
293                       "use gnulib module environ for portability"), \
294      environ)
295 #endif
296
297
298 #if @GNULIB_EUIDACCESS@
299 # if !@HAVE_EUIDACCESS@
300 /* Like access(), except that is uses the effective user id and group id of
301    the current process.  */
302 extern int euidaccess (const char *filename, int mode);
303 # endif
304 #elif defined GNULIB_POSIXCHECK
305 # undef euidaccess
306 # define euidaccess(f,m) \
307     (GL_LINK_WARNING ("euidaccess is unportable - " \
308                       "use gnulib module euidaccess for portability"), \
309      euidaccess (f, m))
310 #endif
311
312
313 #if @GNULIB_FCHDIR@
314 # if @REPLACE_FCHDIR@
315
316 /* Change the process' current working directory to the directory on which
317    the given file descriptor is open.
318    Return 0 if successful, otherwise -1 and errno set.
319    See the POSIX:2001 specification
320    <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
321 extern int fchdir (int /*fd*/);
322
323 #  define dup rpl_dup
324 extern int dup (int);
325
326 /* Gnulib internal hooks needed to maintain the fchdir metadata.  */
327 extern int _gl_register_fd (int fd, const char *filename);
328 extern void _gl_unregister_fd (int fd);
329 extern int _gl_register_dup (int oldfd, int newfd);
330 extern const char *_gl_directory_name (int fd);
331
332 # endif
333 #elif defined GNULIB_POSIXCHECK
334 # undef fchdir
335 # define fchdir(f) \
336     (GL_LINK_WARNING ("fchdir is unportable - " \
337                       "use gnulib module fchdir for portability"), \
338      fchdir (f))
339 #endif
340
341
342 #if @GNULIB_FSYNC@
343 /* Synchronize changes to a file.
344    Return 0 if successful, otherwise -1 and errno set.
345    See POSIX:2001 specification
346    <http://www.opengroup.org/susv3xsh/fsync.html>.  */
347 # if !@HAVE_FSYNC@
348 extern int fsync (int fd);
349 # endif
350 #elif defined GNULIB_POSIXCHECK
351 # undef fsync
352 # define fsync(fd) \
353     (GL_LINK_WARNING ("fsync is unportable - " \
354                       "use gnulib module fsync for portability"), \
355      fsync (fd))
356 #endif
357
358
359 #if @GNULIB_FTRUNCATE@
360 # if !@HAVE_FTRUNCATE@
361 /* Change the size of the file to which FD is opened to become equal to LENGTH.
362    Return 0 if successful, otherwise -1 and errno set.
363    See the POSIX:2001 specification
364    <http://www.opengroup.org/susv3xsh/ftruncate.html>.  */
365 extern int ftruncate (int fd, off_t length);
366 # endif
367 #elif defined GNULIB_POSIXCHECK
368 # undef ftruncate
369 # define ftruncate(f,l) \
370     (GL_LINK_WARNING ("ftruncate is unportable - " \
371                       "use gnulib module ftruncate for portability"), \
372      ftruncate (f, l))
373 #endif
374
375
376 #if @GNULIB_GETCWD@
377 /* Include the headers that might declare getcwd so that they will not
378    cause confusion if included after this file.  */
379 # include <stdlib.h>
380 # if @REPLACE_GETCWD@
381 /* Get the name of the current working directory, and put it in SIZE bytes
382    of BUF.
383    Return BUF if successful, or NULL if the directory couldn't be determined
384    or SIZE was too small.
385    See the POSIX:2001 specification
386    <http://www.opengroup.org/susv3xsh/getcwd.html>.
387    Additionally, the gnulib module 'getcwd' guarantees the following GNU
388    extension: If BUF is NULL, an array is allocated with 'malloc'; the array
389    is SIZE bytes long, unless SIZE == 0, in which case it is as big as
390    necessary.  */
391 #  define getcwd rpl_getcwd
392 extern char * getcwd (char *buf, size_t size);
393 # endif
394 #elif defined GNULIB_POSIXCHECK
395 # undef getcwd
396 # define getcwd(b,s) \
397     (GL_LINK_WARNING ("getcwd is unportable - " \
398                       "use gnulib module getcwd for portability"), \
399      getcwd (b, s))
400 #endif
401
402
403 #if @GNULIB_GETDOMAINNAME@
404 /* Return the NIS domain name of the machine.
405    WARNING! The NIS domain name is unrelated to the fully qualified host name
406             of the machine.  It is also unrelated to email addresses.
407    WARNING! The NIS domain name is usually the empty string or "(none)" when
408             not using NIS.
409
410    Put up to LEN bytes of the NIS domain name into NAME.
411    Null terminate it if the name is shorter than LEN.
412    If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
413    Return 0 if successful, otherwise set errno and return -1.  */
414 # if !@HAVE_GETDOMAINNAME@
415 extern int getdomainname(char *name, size_t len);
416 # endif
417 #elif defined GNULIB_POSIXCHECK
418 # undef getdomainname
419 # define getdomainname(n,l) \
420     (GL_LINK_WARNING ("getdomainname is unportable - " \
421                       "use gnulib module getdomainname for portability"), \
422      getdomainname (n, l))
423 #endif
424
425
426 #if @GNULIB_GETDTABLESIZE@
427 # if !@HAVE_GETDTABLESIZE@
428 /* Return the maximum number of file descriptors in the current process.
429    In POSIX, this is same as sysconf (_SC_OPEN_MAX).  */
430 extern int getdtablesize (void);
431 # endif
432 #elif defined GNULIB_POSIXCHECK
433 # undef getdtablesize
434 # define getdtablesize() \
435     (GL_LINK_WARNING ("getdtablesize is unportable - " \
436                       "use gnulib module getdtablesize for portability"), \
437      getdtablesize ())
438 #endif
439
440
441 #if @GNULIB_GETHOSTNAME@
442 /* Return the standard host name of the machine.
443    WARNING! The host name may or may not be fully qualified.
444
445    Put up to LEN bytes of the host name into NAME.
446    Null terminate it if the name is shorter than LEN.
447    If the host name is longer than LEN, set errno = EINVAL and return -1.
448    Return 0 if successful, otherwise set errno and return -1.  */
449 # if @UNISTD_H_HAVE_WINSOCK2_H@
450 #  undef gethostname
451 #  define gethostname rpl_gethostname
452 # endif
453 # if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@
454 extern int gethostname(char *name, size_t len);
455 # endif
456 #elif @UNISTD_H_HAVE_WINSOCK2_H@
457 # undef gethostname
458 # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
459 #elif defined GNULIB_POSIXCHECK
460 # undef gethostname
461 # define gethostname(n,l) \
462     (GL_LINK_WARNING ("gethostname is unportable - " \
463                       "use gnulib module gethostname for portability"), \
464      gethostname (n, l))
465 #endif
466
467
468 #if @GNULIB_GETLOGIN_R@
469 /* Copies the user's login name to NAME.
470    The array pointed to by NAME has room for SIZE bytes.
471
472    Returns 0 if successful.  Upon error, an error number is returned, or -1 in
473    the case that the login name cannot be found but no specific error is
474    provided (this case is hopefully rare but is left open by the POSIX spec).
475
476    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
477  */
478 # if !@HAVE_DECL_GETLOGIN_R@
479 extern int getlogin_r (char *name, size_t size);
480 # endif
481 #elif defined GNULIB_POSIXCHECK
482 # undef getlogin_r
483 # define getlogin_r(n,s) \
484     (GL_LINK_WARNING ("getlogin_r is unportable - " \
485                       "use gnulib module getlogin_r for portability"), \
486      getlogin_r (n, s))
487 #endif
488
489
490 #if @GNULIB_GETPAGESIZE@
491 # if @REPLACE_GETPAGESIZE@
492 #  define getpagesize rpl_getpagesize
493 extern int getpagesize (void);
494 # elif !@HAVE_GETPAGESIZE@
495 /* This is for POSIX systems.  */
496 #  if !defined getpagesize && defined _SC_PAGESIZE
497 #   if ! (defined __VMS && __VMS_VER < 70000000)
498 #    define getpagesize() sysconf (_SC_PAGESIZE)
499 #   endif
500 #  endif
501 /* This is for older VMS.  */
502 #  if !defined getpagesize && defined __VMS
503 #   ifdef __ALPHA
504 #    define getpagesize() 8192
505 #   else
506 #    define getpagesize() 512
507 #   endif
508 #  endif
509 /* This is for BeOS.  */
510 #  if !defined getpagesize && @HAVE_OS_H@
511 #   include <OS.h>
512 #   if defined B_PAGE_SIZE
513 #    define getpagesize() B_PAGE_SIZE
514 #   endif
515 #  endif
516 /* This is for AmigaOS4.0.  */
517 #  if !defined getpagesize && defined __amigaos4__
518 #   define getpagesize() 2048
519 #  endif
520 /* This is for older Unix systems.  */
521 #  if !defined getpagesize && @HAVE_SYS_PARAM_H@
522 #   include <sys/param.h>
523 #   ifdef EXEC_PAGESIZE
524 #    define getpagesize() EXEC_PAGESIZE
525 #   else
526 #    ifdef NBPG
527 #     ifndef CLSIZE
528 #      define CLSIZE 1
529 #     endif
530 #     define getpagesize() (NBPG * CLSIZE)
531 #    else
532 #     ifdef NBPC
533 #      define getpagesize() NBPC
534 #     endif
535 #    endif
536 #   endif
537 #  endif
538 # endif
539 #elif defined GNULIB_POSIXCHECK
540 # undef getpagesize
541 # define getpagesize() \
542     (GL_LINK_WARNING ("getpagesize is unportable - " \
543                       "use gnulib module getpagesize for portability"), \
544      getpagesize ())
545 #endif
546
547
548 #if @GNULIB_GETUSERSHELL@
549 # if !@HAVE_GETUSERSHELL@
550 /* Return the next valid login shell on the system, or NULL when the end of
551    the list has been reached.  */
552 extern char *getusershell (void);
553 /* Rewind to pointer that is advanced at each getusershell() call.  */
554 extern void setusershell (void);
555 /* Free the pointer that is advanced at each getusershell() call and
556    associated resources.  */
557 extern void endusershell (void);
558 # endif
559 #elif defined GNULIB_POSIXCHECK
560 # undef getusershell
561 # define getusershell() \
562     (GL_LINK_WARNING ("getusershell is unportable - " \
563                       "use gnulib module getusershell for portability"), \
564      getusershell ())
565 # undef setusershell
566 # define setusershell() \
567     (GL_LINK_WARNING ("setusershell is unportable - " \
568                       "use gnulib module getusershell for portability"), \
569      setusershell ())
570 # undef endusershell
571 # define endusershell() \
572     (GL_LINK_WARNING ("endusershell is unportable - " \
573                       "use gnulib module getusershell for portability"), \
574      endusershell ())
575 #endif
576
577
578 #if @GNULIB_LCHOWN@
579 # if @REPLACE_LCHOWN@
580 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
581    to GID (if GID is not -1).  Do not follow symbolic links.
582    Return 0 if successful, otherwise -1 and errno set.
583    See the POSIX:2001 specification
584    <http://www.opengroup.org/susv3xsh/lchown.html>.  */
585 #  define lchown rpl_lchown
586 extern int lchown (char const *file, uid_t owner, gid_t group);
587 # endif
588 #elif defined GNULIB_POSIXCHECK
589 # undef lchown
590 # define lchown(f,u,g) \
591     (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
592                       "systems - use gnulib module lchown for portability"), \
593      lchown (f, u, g))
594 #endif
595
596
597 #if @GNULIB_LINK@
598 # if @REPLACE_LINK@
599 #  define link rpl_link
600 # endif
601 /* Create a new hard link for an existing file.
602    Return 0 if successful, otherwise -1 and errno set.
603    See POSIX:2001 specification
604    <http://www.opengroup.org/susv3xsh/link.html>.  */
605 # if !@HAVE_LINK@ || @REPLACE_LINK@
606 extern int link (const char *path1, const char *path2);
607 # endif
608 #elif defined GNULIB_POSIXCHECK
609 # undef link
610 # define link(path1,path2) \
611     (GL_LINK_WARNING ("link is unportable - " \
612                       "use gnulib module link for portability"), \
613      link (path1, path2))
614 #endif
615
616
617 #if @GNULIB_LSEEK@
618 # if @REPLACE_LSEEK@
619 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
620    Return the new offset if successful, otherwise -1 and errno set.
621    See the POSIX:2001 specification
622    <http://www.opengroup.org/susv3xsh/lseek.html>.  */
623 #  define lseek rpl_lseek
624    extern off_t lseek (int fd, off_t offset, int whence);
625 # endif
626 #elif defined GNULIB_POSIXCHECK
627 # undef lseek
628 # define lseek(f,o,w) \
629     (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
630                       "systems - use gnulib module lseek for portability"), \
631      lseek (f, o, w))
632 #endif
633
634
635 #if @GNULIB_PIPE2@
636 /* Create a pipe, applying the given flags when opening the read-end of the
637    pipe and the write-end of the pipe.
638    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
639    and O_TEXT, O_BINARY (defined in "binary-io.h").
640    Store the read-end as fd[0] and the write-end as fd[1].
641    Return 0 upon success, or -1 with errno set upon failure.
642    See also the Linux man page at
643    <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>.  */
644 # if @HAVE_PIPE2@
645 #  define pipe2 rpl_pipe2
646 # endif
647 extern int pipe2 (int fd[2], int flags);
648 #elif defined GNULIB_POSIXCHECK
649 # undef pipe2
650 # define pipe2(f,o) \
651     (GL_LINK_WARNING ("pipe2 is unportable - " \
652                       "use gnulib module pipe2 for portability"), \
653      pipe2 (f, o))
654 #endif
655
656
657 #if @GNULIB_READLINK@
658 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
659    bytes of it into BUF.  Return the number of bytes placed into BUF if
660    successful, otherwise -1 and errno set.
661    See the POSIX:2001 specification
662    <http://www.opengroup.org/susv3xsh/readlink.html>.  */
663 # if !@HAVE_READLINK@
664 extern int readlink (const char *file, char *buf, size_t bufsize);
665 # endif
666 #elif defined GNULIB_POSIXCHECK
667 # undef readlink
668 # define readlink(f,b,s) \
669     (GL_LINK_WARNING ("readlink is unportable - " \
670                       "use gnulib module readlink for portability"), \
671      readlink (f, b, s))
672 #endif
673
674
675 #if @GNULIB_SLEEP@
676 /* Pause the execution of the current thread for N seconds.
677    Returns the number of seconds left to sleep.
678    See the POSIX:2001 specification
679    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
680 # if !@HAVE_SLEEP@
681 extern unsigned int sleep (unsigned int n);
682 # endif
683 #elif defined GNULIB_POSIXCHECK
684 # undef sleep
685 # define sleep(n) \
686     (GL_LINK_WARNING ("sleep is unportable - " \
687                       "use gnulib module sleep for portability"), \
688      sleep (n))
689 #endif
690
691
692 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
693 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
694    See the POSIX:2001 specification
695    <http://www.opengroup.org/susv3xsh/write.html>.  */
696 # undef write
697 # define write rpl_write
698 extern ssize_t write (int fd, const void *buf, size_t count);
699 #endif
700
701
702 #ifdef __cplusplus
703 }
704 #endif
705
706
707 #endif /* _GL_UNISTD_H */
708 #endif /* _GL_UNISTD_H */