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