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