unistd: warn on use of environ without module
[pspp] / 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_LINK_WARNING is copied here.  */
118
119 /* The definition of _GL_ARG_NONNULL is copied here.  */
120
121 /* The definition of _GL_WARN_ON_USE 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 # if HAVE_RAW_DECL_ENVIRON
256 static inline char ***
257 rpl_environ (void)
258 {
259   return &environ;
260 }
261 _GL_WARN_ON_USE (rpl_environ, "environ is unportable - "
262                  "use gnulib module environ for portability");
263 #  undef environ
264 #  define environ (*rpl_environ ())
265 # endif
266 #endif
267
268
269 #if @GNULIB_EUIDACCESS@
270 # if !@HAVE_EUIDACCESS@
271 /* Like access(), except that it uses the effective user id and group id of
272    the current process.  */
273 extern int euidaccess (const char *filename, int mode) _GL_ARG_NONNULL ((1));
274 # endif
275 #elif defined GNULIB_POSIXCHECK
276 # undef euidaccess
277 # define euidaccess(f,m) \
278     (GL_LINK_WARNING ("euidaccess is unportable - " \
279                       "use gnulib module euidaccess for portability"), \
280      euidaccess (f, m))
281 #endif
282
283
284 #if @GNULIB_FACCESSAT@
285 # if !@HAVE_FACCESSAT@
286 extern int faccessat (int fd, char const *file, int mode, int flag)
287      _GL_ARG_NONNULL ((2));
288 # endif
289 #elif defined GNULIB_POSIXCHECK
290 # undef faccessat
291 # define faccessat(d,n,m,f)                         \
292     (GL_LINK_WARNING ("faccessat is not portable - " \
293                       "use gnulib module faccessat for portability"), \
294      faccessat (d, n, m, f))
295 #endif
296
297
298 #if @GNULIB_FCHDIR@
299 # if @REPLACE_FCHDIR@
300 /* Change the process' current working directory to the directory on which
301    the given file descriptor is open.
302    Return 0 if successful, otherwise -1 and errno set.
303    See the POSIX:2001 specification
304    <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
305 extern int fchdir (int /*fd*/);
306
307 /* Gnulib internal hooks needed to maintain the fchdir metadata.  */
308 extern int _gl_register_fd (int fd, const char *filename)
309      _GL_ARG_NONNULL ((2));
310 extern void _gl_unregister_fd (int fd);
311 extern int _gl_register_dup (int oldfd, int newfd);
312 extern const char *_gl_directory_name (int fd);
313
314 # endif
315 #elif defined GNULIB_POSIXCHECK
316 # undef fchdir
317 # define fchdir(f) \
318     (GL_LINK_WARNING ("fchdir is unportable - " \
319                       "use gnulib module fchdir for portability"), \
320      fchdir (f))
321 #endif
322
323
324 #if @GNULIB_FCHOWNAT@
325 # if @REPLACE_FCHOWNAT@
326 #  undef fchownat
327 #  define fchownat rpl_fchownat
328 # endif
329 # if !@HAVE_FCHOWNAT@ || @REPLACE_FCHOWNAT@
330 extern int fchownat (int fd, char const *file, uid_t owner, gid_t group, int flag)
331      _GL_ARG_NONNULL ((2));
332 # endif
333 #elif defined GNULIB_POSIXCHECK
334 # undef fchownat
335 # define fchownat(d,n,o,g,f)                        \
336     (GL_LINK_WARNING ("fchownat is not portable - " \
337                       "use gnulib module openat for portability"), \
338      fchownat (d, n, o, g, f))
339 #endif
340
341
342 #if @GNULIB_FSYNC@
343 /* Synchronize changes to a file.
344    Return 0 if successful, otherwise -1 and errno set.
345    See POSIX:2001 specification
346    <http://www.opengroup.org/susv3xsh/fsync.html>.  */
347 # if !@HAVE_FSYNC@
348 extern int fsync (int fd);
349 # endif
350 #elif defined GNULIB_POSIXCHECK
351 # undef fsync
352 # define fsync(fd) \
353     (GL_LINK_WARNING ("fsync is unportable - " \
354                       "use gnulib module fsync for portability"), \
355      fsync (fd))
356 #endif
357
358
359 #if @GNULIB_FTRUNCATE@
360 # if !@HAVE_FTRUNCATE@
361 /* Change the size of the file to which FD is opened to become equal to LENGTH.
362    Return 0 if successful, otherwise -1 and errno set.
363    See the POSIX:2001 specification
364    <http://www.opengroup.org/susv3xsh/ftruncate.html>.  */
365 extern int ftruncate (int fd, off_t length);
366 # endif
367 #elif defined GNULIB_POSIXCHECK
368 # undef ftruncate
369 # define ftruncate(f,l) \
370     (GL_LINK_WARNING ("ftruncate is unportable - " \
371                       "use gnulib module ftruncate for portability"), \
372      ftruncate (f, l))
373 #endif
374
375
376 #if @GNULIB_GETCWD@
377 # if @REPLACE_GETCWD@
378 /* Get the name of the current working directory, and put it in SIZE bytes
379    of BUF.
380    Return BUF if successful, or NULL if the directory couldn't be determined
381    or SIZE was too small.
382    See the POSIX:2001 specification
383    <http://www.opengroup.org/susv3xsh/getcwd.html>.
384    Additionally, the gnulib module 'getcwd' guarantees the following GNU
385    extension: If BUF is NULL, an array is allocated with 'malloc'; the array
386    is SIZE bytes long, unless SIZE == 0, in which case it is as big as
387    necessary.  */
388 #  define getcwd rpl_getcwd
389 extern char * getcwd (char *buf, size_t size);
390 # endif
391 #elif defined GNULIB_POSIXCHECK
392 # undef getcwd
393 # define getcwd(b,s) \
394     (GL_LINK_WARNING ("getcwd is unportable - " \
395                       "use gnulib module getcwd for portability"), \
396      getcwd (b, s))
397 #endif
398
399
400 #if @GNULIB_GETDOMAINNAME@
401 /* Return the NIS domain name of the machine.
402    WARNING! The NIS domain name is unrelated to the fully qualified host name
403             of the machine.  It is also unrelated to email addresses.
404    WARNING! The NIS domain name is usually the empty string or "(none)" when
405             not using NIS.
406
407    Put up to LEN bytes of the NIS domain name into NAME.
408    Null terminate it if the name is shorter than LEN.
409    If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
410    Return 0 if successful, otherwise set errno and return -1.  */
411 # if !@HAVE_GETDOMAINNAME@
412 extern int getdomainname(char *name, size_t len) _GL_ARG_NONNULL ((1));
413 # endif
414 #elif defined GNULIB_POSIXCHECK
415 # undef getdomainname
416 # define getdomainname(n,l) \
417     (GL_LINK_WARNING ("getdomainname is unportable - " \
418                       "use gnulib module getdomainname for portability"), \
419      getdomainname (n, l))
420 #endif
421
422
423 #if @GNULIB_GETDTABLESIZE@
424 # if !@HAVE_GETDTABLESIZE@
425 /* Return the maximum number of file descriptors in the current process.
426    In POSIX, this is same as sysconf (_SC_OPEN_MAX).  */
427 extern int getdtablesize (void);
428 # endif
429 #elif defined GNULIB_POSIXCHECK
430 # undef getdtablesize
431 # define getdtablesize() \
432     (GL_LINK_WARNING ("getdtablesize is unportable - " \
433                       "use gnulib module getdtablesize for portability"), \
434      getdtablesize ())
435 #endif
436
437
438 #if @GNULIB_GETGROUPS@
439 # if @REPLACE_GETGROUPS@
440 #  undef getgroups
441 #  define getgroups rpl_getgroups
442 # endif
443 # if !@HAVE_GETGROUPS@ || @REPLACE_GETGROUPS@
444 /* Return the supplemental groups that the current process belongs to.
445    It is unspecified whether the effective group id is in the list.
446    If N is 0, return the group count; otherwise, N describes how many
447    entries are available in GROUPS.  Return -1 and set errno if N is
448    not 0 and not large enough.  Fails with ENOSYS on some systems.  */
449 int getgroups (int n, gid_t *groups);
450 # endif
451 #elif defined GNULIB_POSIXCHECK
452 # undef getgroups
453 # define getgroups(n,g)                                                 \
454     (GL_LINK_WARNING ("getgroups is unportable - "                      \
455                       "use gnulib module getgroups for portability"),   \
456      getgroups (n, g))
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) _GL_ARG_NONNULL ((1));
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@
488 /* Returns the user's login name, or NULL if it cannot be found.  Upon error,
489    returns NULL with errno set.
490
491    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
492
493    Most programs don't need to use this function, because the information is
494    available through environment variables:
495      ${LOGNAME-$USER}        on Unix platforms,
496      $USERNAME               on native Windows platforms.
497  */
498 # if !@HAVE_GETLOGIN@
499 extern char *getlogin (void);
500 # endif
501 #elif defined GNULIB_POSIXCHECK
502 # undef getlogin
503 # define getlogin() \
504     (GL_LINK_WARNING ("getlogin is unportable - " \
505                       "use gnulib module getlogin for portability"), \
506      getlogin ())
507 #endif
508
509
510 #if @GNULIB_GETLOGIN_R@
511 /* Copies the user's login name to NAME.
512    The array pointed to by NAME has room for SIZE bytes.
513
514    Returns 0 if successful.  Upon error, an error number is returned, or -1 in
515    the case that the login name cannot be found but no specific error is
516    provided (this case is hopefully rare but is left open by the POSIX spec).
517
518    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
519
520    Most programs don't need to use this function, because the information is
521    available through environment variables:
522      ${LOGNAME-$USER}        on Unix platforms,
523      $USERNAME               on native Windows platforms.
524  */
525 # if !@HAVE_DECL_GETLOGIN_R@
526 extern int getlogin_r (char *name, size_t size) _GL_ARG_NONNULL ((1));
527 # endif
528 #elif defined GNULIB_POSIXCHECK
529 # undef getlogin_r
530 # define getlogin_r(n,s) \
531     (GL_LINK_WARNING ("getlogin_r is unportable - " \
532                       "use gnulib module getlogin_r for portability"), \
533      getlogin_r (n, s))
534 #endif
535
536
537 #if @GNULIB_GETPAGESIZE@
538 # if @REPLACE_GETPAGESIZE@
539 #  define getpagesize rpl_getpagesize
540 extern int getpagesize (void);
541 # elif !@HAVE_GETPAGESIZE@
542 /* This is for POSIX systems.  */
543 #  if !defined getpagesize && defined _SC_PAGESIZE
544 #   if ! (defined __VMS && __VMS_VER < 70000000)
545 #    define getpagesize() sysconf (_SC_PAGESIZE)
546 #   endif
547 #  endif
548 /* This is for older VMS.  */
549 #  if !defined getpagesize && defined __VMS
550 #   ifdef __ALPHA
551 #    define getpagesize() 8192
552 #   else
553 #    define getpagesize() 512
554 #   endif
555 #  endif
556 /* This is for BeOS.  */
557 #  if !defined getpagesize && @HAVE_OS_H@
558 #   include <OS.h>
559 #   if defined B_PAGE_SIZE
560 #    define getpagesize() B_PAGE_SIZE
561 #   endif
562 #  endif
563 /* This is for AmigaOS4.0.  */
564 #  if !defined getpagesize && defined __amigaos4__
565 #   define getpagesize() 2048
566 #  endif
567 /* This is for older Unix systems.  */
568 #  if !defined getpagesize && @HAVE_SYS_PARAM_H@
569 #   include <sys/param.h>
570 #   ifdef EXEC_PAGESIZE
571 #    define getpagesize() EXEC_PAGESIZE
572 #   else
573 #    ifdef NBPG
574 #     ifndef CLSIZE
575 #      define CLSIZE 1
576 #     endif
577 #     define getpagesize() (NBPG * CLSIZE)
578 #    else
579 #     ifdef NBPC
580 #      define getpagesize() NBPC
581 #     endif
582 #    endif
583 #   endif
584 #  endif
585 # endif
586 #elif defined GNULIB_POSIXCHECK
587 # undef getpagesize
588 # define getpagesize() \
589     (GL_LINK_WARNING ("getpagesize is unportable - " \
590                       "use gnulib module getpagesize for portability"), \
591      getpagesize ())
592 #endif
593
594
595 #if @GNULIB_GETUSERSHELL@
596 # if !@HAVE_GETUSERSHELL@
597 /* Return the next valid login shell on the system, or NULL when the end of
598    the list has been reached.  */
599 extern char *getusershell (void);
600 /* Rewind to pointer that is advanced at each getusershell() call.  */
601 extern void setusershell (void);
602 /* Free the pointer that is advanced at each getusershell() call and
603    associated resources.  */
604 extern void endusershell (void);
605 # endif
606 #elif defined GNULIB_POSIXCHECK
607 # undef getusershell
608 # define getusershell() \
609     (GL_LINK_WARNING ("getusershell is unportable - " \
610                       "use gnulib module getusershell for portability"), \
611      getusershell ())
612 # undef setusershell
613 # define setusershell() \
614     (GL_LINK_WARNING ("setusershell is unportable - " \
615                       "use gnulib module getusershell for portability"), \
616      setusershell ())
617 # undef endusershell
618 # define endusershell() \
619     (GL_LINK_WARNING ("endusershell is unportable - " \
620                       "use gnulib module getusershell for portability"), \
621      endusershell ())
622 #endif
623
624
625 #if @GNULIB_LCHOWN@
626 # if @REPLACE_LCHOWN@
627 #  undef lchown
628 #  define lchown rpl_lchown
629 # endif
630 # if !@HAVE_LCHOWN@ || @REPLACE_LCHOWN@
631 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
632    to GID (if GID is not -1).  Do not follow symbolic links.
633    Return 0 if successful, otherwise -1 and errno set.
634    See the POSIX:2001 specification
635    <http://www.opengroup.org/susv3xsh/lchown.html>.  */
636 extern int lchown (char const *file, uid_t owner, gid_t group)
637      _GL_ARG_NONNULL ((1));
638 # endif
639 #elif defined GNULIB_POSIXCHECK
640 # undef lchown
641 # define lchown(f,u,g) \
642     (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
643                       "systems - use gnulib module lchown for portability"), \
644      lchown (f, u, g))
645 #endif
646
647
648 #if @GNULIB_LINK@
649 # if @REPLACE_LINK@
650 #  define link rpl_link
651 # endif
652 /* Create a new hard link for an existing file.
653    Return 0 if successful, otherwise -1 and errno set.
654    See POSIX:2001 specification
655    <http://www.opengroup.org/susv3xsh/link.html>.  */
656 # if !@HAVE_LINK@ || @REPLACE_LINK@
657 extern int link (const char *path1, const char *path2)
658      _GL_ARG_NONNULL ((1, 2));
659 # endif
660 #elif defined GNULIB_POSIXCHECK
661 # undef link
662 # define link(path1,path2) \
663     (GL_LINK_WARNING ("link is unportable - " \
664                       "use gnulib module link for portability"), \
665      link (path1, path2))
666 #endif
667
668 #if @GNULIB_LINKAT@
669 # if @REPLACE_LINKAT@
670 #  undef linkat
671 #  define linkat rpl_linkat
672 # endif
673 /* Create a new hard link for an existing file, relative to two
674    directories.  FLAG controls whether symlinks are followed.
675    Return 0 if successful, otherwise -1 and errno set.  */
676 # if !@HAVE_LINKAT@ || @REPLACE_LINKAT@
677 extern int linkat (int fd1, const char *path1, int fd2, const char *path2,
678                    int flag)
679      _GL_ARG_NONNULL ((2, 4));
680 # endif
681 #elif defined GNULIB_POSIXCHECK
682 # undef linkat
683 # define linkat(f1,path1,f2,path2,f)              \
684     (GL_LINK_WARNING ("linkat is unportable - " \
685                       "use gnulib module linkat for portability"), \
686      linkat (f1, path1, f2, path2,f))
687 #endif
688
689 #if @GNULIB_LSEEK@
690 # if @REPLACE_LSEEK@
691 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
692    Return the new offset if successful, otherwise -1 and errno set.
693    See the POSIX:2001 specification
694    <http://www.opengroup.org/susv3xsh/lseek.html>.  */
695 #  define lseek rpl_lseek
696    extern off_t lseek (int fd, off_t offset, int whence);
697 # endif
698 #elif defined GNULIB_POSIXCHECK
699 # undef lseek
700 # define lseek(f,o,w) \
701     (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
702                       "systems - use gnulib module lseek for portability"), \
703      lseek (f, o, w))
704 #endif
705
706
707 #if @GNULIB_PIPE2@
708 /* Create a pipe, applying the given flags when opening the read-end of the
709    pipe and the write-end of the pipe.
710    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
711    and O_TEXT, O_BINARY (defined in "binary-io.h").
712    Store the read-end as fd[0] and the write-end as fd[1].
713    Return 0 upon success, or -1 with errno set upon failure.
714    See also the Linux man page at
715    <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>.  */
716 # if @HAVE_PIPE2@
717 #  define pipe2 rpl_pipe2
718 # endif
719 extern int pipe2 (int fd[2], int flags) _GL_ARG_NONNULL ((1));
720 #elif defined GNULIB_POSIXCHECK
721 # undef pipe2
722 # define pipe2(f,o) \
723     (GL_LINK_WARNING ("pipe2 is unportable - " \
724                       "use gnulib module pipe2 for portability"), \
725      pipe2 (f, o))
726 #endif
727
728
729 #if @GNULIB_PREAD@
730 # if @REPLACE_PREAD@
731 #  define pread rpl_pread
732 # endif
733 /* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
734    Return the number of bytes placed into BUF if successful, otherwise
735    set errno and return -1.  0 indicates EOF.  See the POSIX:2001
736    specification <http://www.opengroup.org/susv3xsh/pread.html>.  */
737 # if !@HAVE_PREAD@ || @REPLACE_PREAD@
738   extern ssize_t pread (int fd, void *buf, size_t bufsize, off_t offset)
739        _GL_ARG_NONNULL ((2));
740 # endif
741 #elif defined GNULIB_POSIXCHECK
742 # undef pread
743 # define pread(f,b,s,o)                        \
744     (GL_LINK_WARNING ("pread is unportable - " \
745                       "use gnulib module pread for portability"), \
746      pread (f, b, s, o))
747 #endif
748
749
750 #if @GNULIB_READLINK@
751 # if @REPLACE_READLINK@
752 #  define readlink rpl_readlink
753 # endif
754 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
755    bytes of it into BUF.  Return the number of bytes placed into BUF if
756    successful, otherwise -1 and errno set.
757    See the POSIX:2001 specification
758    <http://www.opengroup.org/susv3xsh/readlink.html>.  */
759 # if !@HAVE_READLINK@ || @REPLACE_READLINK@
760 extern ssize_t readlink (const char *file, char *buf, size_t bufsize)
761      _GL_ARG_NONNULL ((1, 2));
762 # endif
763 #elif defined GNULIB_POSIXCHECK
764 # undef readlink
765 # define readlink(f,b,s) \
766     (GL_LINK_WARNING ("readlink is unportable - " \
767                       "use gnulib module readlink for portability"), \
768      readlink (f, b, s))
769 #endif
770
771
772 #if @GNULIB_READLINKAT@
773 # if !@HAVE_READLINKAT@
774 extern ssize_t readlinkat (int fd, char const *file, char *buf, size_t len)
775      _GL_ARG_NONNULL ((2, 3));
776 # endif
777 #elif defined GNULIB_POSIXCHECK
778 # undef readlinkat
779 # define readlinkat(d,n,b,l)                         \
780     (GL_LINK_WARNING ("readlinkat is not portable - " \
781                       "use gnulib module symlinkat for portability"), \
782      readlinkat (d, n, b, l))
783 #endif
784
785
786 #if @GNULIB_RMDIR@
787 # if @REPLACE_RMDIR@
788 #  define rmdir rpl_rmdir
789 /* Remove the directory DIR.  */
790 extern int rmdir (char const *name) _GL_ARG_NONNULL ((1));
791 # endif
792 #elif defined GNULIB_POSIXCHECK
793 # undef rmdir
794 # define rmdir(n) \
795     (GL_LINK_WARNING ("rmdir is unportable - " \
796                       "use gnulib module rmdir for portability"), \
797      rmdir (n))
798 #endif
799
800
801 #if @GNULIB_SLEEP@
802 # if @REPLACE_SLEEP@
803 #  undef sleep
804 #  define sleep rpl_sleep
805 # endif
806 /* Pause the execution of the current thread for N seconds.
807    Returns the number of seconds left to sleep.
808    See the POSIX:2001 specification
809    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
810 # if !@HAVE_SLEEP@ || @REPLACE_SLEEP@
811 extern unsigned int sleep (unsigned int n);
812 # endif
813 #elif defined GNULIB_POSIXCHECK
814 # undef sleep
815 # define sleep(n) \
816     (GL_LINK_WARNING ("sleep is unportable - " \
817                       "use gnulib module sleep for portability"), \
818      sleep (n))
819 #endif
820
821
822 #if @GNULIB_SYMLINK@
823 # if @REPLACE_SYMLINK@
824 #  undef symlink
825 #  define symlink rpl_symlink
826 # endif
827 # if !@HAVE_SYMLINK@ || @REPLACE_SYMLINK@
828 extern int symlink (char const *contents, char const *file)
829      _GL_ARG_NONNULL ((1, 2));
830 # endif
831 #elif defined GNULIB_POSIXCHECK
832 # undef symlink
833 # define symlink(c,n)                        \
834     (GL_LINK_WARNING ("symlink is not portable - " \
835                       "use gnulib module symlink for portability"), \
836      symlink (c, n))
837 #endif
838
839
840 #if @GNULIB_SYMLINKAT@
841 # if !@HAVE_SYMLINKAT@
842 extern int symlinkat (char const *contents, int fd, char const *file)
843      _GL_ARG_NONNULL ((1, 3));
844 # endif
845 #elif defined GNULIB_POSIXCHECK
846 # undef symlinkat
847 # define symlinkat(c,d,n)                            \
848     (GL_LINK_WARNING ("symlinkat is not portable - " \
849                       "use gnulib module symlinkat for portability"), \
850      symlinkat (c, d, n))
851 #endif
852
853
854 #if @GNULIB_UNLINK@
855 # if @REPLACE_UNLINK@
856 #  undef unlink
857 #  define unlink rpl_unlink
858 extern int unlink (char const *file) _GL_ARG_NONNULL ((1));
859 # endif
860 #elif defined GNULIB_POSIXCHECK
861 # undef unlink
862 # define unlink(n)                         \
863     (GL_LINK_WARNING ("unlink is not portable - " \
864                       "use gnulib module unlink for portability"), \
865      unlink (n))
866 #endif
867
868
869 #if @GNULIB_UNLINKAT@
870 # if @REPLACE_UNLINKAT@
871 #  undef unlinkat
872 #  define unlinkat rpl_unlinkat
873 # endif
874 # if !@HAVE_UNLINKAT@ || @REPLACE_UNLINKAT@
875 extern int unlinkat (int fd, char const *file, int flag) _GL_ARG_NONNULL ((2));
876 # endif
877 #elif defined GNULIB_POSIXCHECK
878 # undef unlinkat
879 # define unlinkat(d,n,f)                         \
880     (GL_LINK_WARNING ("unlinkat is not portable - " \
881                       "use gnulib module openat for portability"), \
882      unlinkat (d, n, f))
883 #endif
884
885
886 #if @GNULIB_USLEEP@
887 # if @REPLACE_USLEEP@
888 #  undef usleep
889 #  define usleep rpl_usleep
890 # endif
891 # if !@HAVE_USLEEP@ || @REPLACE_USLEEP@
892 /* Pause the execution of the current thread for N microseconds.
893    Returns 0 on completion, or -1 on range error.
894    See the POSIX:2001 specification
895    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
896 extern int usleep (useconds_t n);
897 # endif
898 #elif defined GNULIB_POSIXCHECK
899 # undef usleep
900 # define usleep(n) \
901     (GL_LINK_WARNING ("usleep is unportable - " \
902                       "use gnulib module usleep for portability"), \
903      usleep (n))
904 #endif
905
906
907 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
908 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
909    See the POSIX:2001 specification
910    <http://www.opengroup.org/susv3xsh/write.html>.  */
911 # undef write
912 # define write rpl_write
913 extern ssize_t write (int fd, const void *buf, size_t count)
914      _GL_ARG_NONNULL ((2));
915 #endif
916
917
918 #ifdef __cplusplus
919 }
920 #endif
921
922
923 #endif /* _GL_UNISTD_H */
924 #endif /* _GL_UNISTD_H */