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