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