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