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