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