getcwd: Tweak for MSVC 9.
[gnulib.git] / lib / unistd.in.h
1 /* Substitute for and wrapper around <unistd.h>.
2    Copyright (C) 2003-2011 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 #if __GNUC__ >= 3
19 @PRAGMA_SYSTEM_HEADER@
20 #endif
21 @PRAGMA_COLUMNS@
22
23 /* Special invocation convention:
24    - On mingw, several headers, including <winsock2.h>, include <unistd.h>,
25      but we need to ensure that both the system <unistd.h> and <winsock2.h>
26      are completely included before we replace gethostname.  */
27 #if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \
28   && !defined _GL_WINSOCK2_H_WITNESS && defined _WINSOCK2_H
29 /* <unistd.h> is being indirectly included for the first time from
30    <winsock2.h>; avoid declaring any overrides.  */
31 # if @HAVE_UNISTD_H@
32 #  @INCLUDE_NEXT@ @NEXT_UNISTD_H@
33 # else
34 #  error unexpected; report this to bug-gnulib@gnu.org
35 # endif
36 # define _GL_WINSOCK2_H_WITNESS
37
38 /* Normal invocation.  */
39 #elif !defined _@GUARD_PREFIX@_UNISTD_H
40
41 /* The include_next requires a split double-inclusion guard.  */
42 #if @HAVE_UNISTD_H@
43 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
44 #endif
45
46 /* Get all possible declarations of gethostname().  */
47 #if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \
48   && !defined _GL_INCLUDING_WINSOCK2_H
49 # define _GL_INCLUDING_WINSOCK2_H
50 # include <winsock2.h>
51 # undef _GL_INCLUDING_WINSOCK2_H
52 #endif
53
54 #if !defined _@GUARD_PREFIX@_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H
55 #define _@GUARD_PREFIX@_UNISTD_H
56
57 /* NetBSD 5.0 mis-defines NULL.  Also get size_t.  */
58 #include <stddef.h>
59
60 /* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>.  */
61 /* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>.  */
62 /* But avoid namespace pollution on glibc systems.  */
63 #if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
64      || ((@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK) \
65          && defined __CYGWIN__)) \
66     && ! defined __GLIBC__
67 # include <stdio.h>
68 #endif
69
70 /* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>.  */
71 /* But avoid namespace pollution on glibc systems.  */
72 #if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) && defined __CYGWIN__ \
73     && ! defined __GLIBC__
74 # include <fcntl.h>
75 #endif
76
77 /* mingw fails to declare _exit in <unistd.h>.  */
78 /* mingw, MSVC, BeOS, Haiku declare environ in <stdlib.h>, not in
79    <unistd.h>.  */
80 /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>.  */
81 /* But avoid namespace pollution on glibc systems.  */
82 #ifndef __GLIBC__
83 # include <stdlib.h>
84 #endif
85
86 /* Native Windows platforms declare getcwd in
87    <io.h> and/or <direct.h>, not in <unistd.h>.  */
88 #if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \
89      && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
90 # include <io.h>     /* mingw32, mingw64 */
91 # include <direct.h> /* mingw64, MSVC 9 */
92 #endif
93
94 /* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.
95    NonStop Kernel declares gethostname in <netdb.h>, not in <unistd.h>.  */
96 /* But avoid namespace pollution on glibc systems.  */
97 #if ((@GNULIB_GETDOMAINNAME@ && (defined _AIX || defined __osf__)) \
98      || (@GNULIB_GETHOSTNAME@ && defined __TANDEM)) \
99     && !defined __GLIBC__
100 # include <netdb.h>
101 #endif
102
103 /* MSVC defines off_t in <sys/types.h>.  */
104 #if !@HAVE_UNISTD_H@
105 /* Get off_t.  */
106 # include <sys/types.h>
107 #endif
108
109 #if (@GNULIB_READ@ || @GNULIB_WRITE@ \
110      || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \
111      || @GNULIB_PREAD@ || @GNULIB_PWRITE@ || defined GNULIB_POSIXCHECK)
112 /* Get ssize_t.  */
113 # include <sys/types.h>
114 #endif
115
116 /* Get getopt(), optarg, optind, opterr, optopt.
117    But avoid namespace pollution on glibc systems.  */
118 #if @GNULIB_UNISTD_H_GETOPT@ && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT
119 # include <getopt.h>
120 #endif
121
122 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
123
124 /* The definition of _GL_ARG_NONNULL is copied here.  */
125
126 /* The definition of _GL_WARN_ON_USE is copied here.  */
127
128
129 /* Hide some function declarations from <winsock2.h>.  */
130
131 #if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@
132 # if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
133 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
134 #   undef socket
135 #   define socket              socket_used_without_including_sys_socket_h
136 #   undef connect
137 #   define connect             connect_used_without_including_sys_socket_h
138 #   undef accept
139 #   define accept              accept_used_without_including_sys_socket_h
140 #   undef bind
141 #   define bind                bind_used_without_including_sys_socket_h
142 #   undef getpeername
143 #   define getpeername         getpeername_used_without_including_sys_socket_h
144 #   undef getsockname
145 #   define getsockname         getsockname_used_without_including_sys_socket_h
146 #   undef getsockopt
147 #   define getsockopt          getsockopt_used_without_including_sys_socket_h
148 #   undef listen
149 #   define listen              listen_used_without_including_sys_socket_h
150 #   undef recv
151 #   define recv                recv_used_without_including_sys_socket_h
152 #   undef send
153 #   define send                send_used_without_including_sys_socket_h
154 #   undef recvfrom
155 #   define recvfrom            recvfrom_used_without_including_sys_socket_h
156 #   undef sendto
157 #   define sendto              sendto_used_without_including_sys_socket_h
158 #   undef setsockopt
159 #   define setsockopt          setsockopt_used_without_including_sys_socket_h
160 #   undef shutdown
161 #   define shutdown            shutdown_used_without_including_sys_socket_h
162 #  else
163     _GL_WARN_ON_USE (socket,
164                      "socket() used without including <sys/socket.h>");
165     _GL_WARN_ON_USE (connect,
166                      "connect() used without including <sys/socket.h>");
167     _GL_WARN_ON_USE (accept,
168                      "accept() used without including <sys/socket.h>");
169     _GL_WARN_ON_USE (bind,
170                      "bind() used without including <sys/socket.h>");
171     _GL_WARN_ON_USE (getpeername,
172                      "getpeername() used without including <sys/socket.h>");
173     _GL_WARN_ON_USE (getsockname,
174                      "getsockname() used without including <sys/socket.h>");
175     _GL_WARN_ON_USE (getsockopt,
176                      "getsockopt() used without including <sys/socket.h>");
177     _GL_WARN_ON_USE (listen,
178                      "listen() used without including <sys/socket.h>");
179     _GL_WARN_ON_USE (recv,
180                      "recv() used without including <sys/socket.h>");
181     _GL_WARN_ON_USE (send,
182                      "send() used without including <sys/socket.h>");
183     _GL_WARN_ON_USE (recvfrom,
184                      "recvfrom() used without including <sys/socket.h>");
185     _GL_WARN_ON_USE (sendto,
186                      "sendto() used without including <sys/socket.h>");
187     _GL_WARN_ON_USE (setsockopt,
188                      "setsockopt() used without including <sys/socket.h>");
189     _GL_WARN_ON_USE (shutdown,
190                      "shutdown() used without including <sys/socket.h>");
191 #  endif
192 # endif
193 # if !defined _@GUARD_PREFIX@_SYS_SELECT_H
194 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
195 #   undef select
196 #   define select              select_used_without_including_sys_select_h
197 #  else
198     _GL_WARN_ON_USE (select,
199                      "select() used without including <sys/select.h>");
200 #  endif
201 # endif
202 #endif
203
204
205 /* OS/2 EMX lacks these macros.  */
206 #ifndef STDIN_FILENO
207 # define STDIN_FILENO 0
208 #endif
209 #ifndef STDOUT_FILENO
210 # define STDOUT_FILENO 1
211 #endif
212 #ifndef STDERR_FILENO
213 # define STDERR_FILENO 2
214 #endif
215
216 /* Ensure *_OK macros exist.  */
217 #ifndef F_OK
218 # define F_OK 0
219 # define X_OK 1
220 # define W_OK 2
221 # define R_OK 4
222 #endif
223
224
225 /* Declare overridden functions.  */
226
227
228 #if defined GNULIB_POSIXCHECK
229 /* The access() function is a security risk.  */
230 _GL_WARN_ON_USE (access, "the access function is a security risk - "
231                  "use the gnulib module faccessat instead");
232 #endif
233
234
235 #if @GNULIB_CHOWN@
236 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
237    to GID (if GID is not -1).  Follow symbolic links.
238    Return 0 if successful, otherwise -1 and errno set.
239    See the POSIX:2008 specification
240    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/chown.html.  */
241 # if @REPLACE_CHOWN@
242 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
243 #   undef chown
244 #   define chown rpl_chown
245 #  endif
246 _GL_FUNCDECL_RPL (chown, int, (const char *file, uid_t uid, gid_t gid)
247                               _GL_ARG_NONNULL ((1)));
248 _GL_CXXALIAS_RPL (chown, int, (const char *file, uid_t uid, gid_t gid));
249 # else
250 #  if !@HAVE_CHOWN@
251 _GL_FUNCDECL_SYS (chown, int, (const char *file, uid_t uid, gid_t gid)
252                               _GL_ARG_NONNULL ((1)));
253 #  endif
254 _GL_CXXALIAS_SYS (chown, int, (const char *file, uid_t uid, gid_t gid));
255 # endif
256 _GL_CXXALIASWARN (chown);
257 #elif defined GNULIB_POSIXCHECK
258 # undef chown
259 # if HAVE_RAW_DECL_CHOWN
260 _GL_WARN_ON_USE (chown, "chown fails to follow symlinks on some systems and "
261                  "doesn't treat a uid or gid of -1 on some systems - "
262                  "use gnulib module chown for portability");
263 # endif
264 #endif
265
266
267 #if @GNULIB_CLOSE@
268 # if @REPLACE_CLOSE@
269 /* Automatically included by modules that need a replacement for close.  */
270 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
271 #   undef close
272 #   define close rpl_close
273 #  endif
274 _GL_FUNCDECL_RPL (close, int, (int fd));
275 _GL_CXXALIAS_RPL (close, int, (int fd));
276 # else
277 _GL_CXXALIAS_SYS (close, int, (int fd));
278 # endif
279 _GL_CXXALIASWARN (close);
280 #elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
281 # undef close
282 # define close close_used_without_requesting_gnulib_module_close
283 #elif defined GNULIB_POSIXCHECK
284 # undef close
285 /* Assume close is always declared.  */
286 _GL_WARN_ON_USE (close, "close does not portably work on sockets - "
287                  "use gnulib module close for portability");
288 #endif
289
290
291 #if @REPLACE_DUP@
292 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
293 #  define dup rpl_dup
294 # endif
295 _GL_FUNCDECL_RPL (dup, int, (int oldfd));
296 _GL_CXXALIAS_RPL (dup, int, (int oldfd));
297 #else
298 _GL_CXXALIAS_SYS (dup, int, (int oldfd));
299 #endif
300 _GL_CXXALIASWARN (dup);
301
302
303 #if @GNULIB_DUP2@
304 /* Copy the file descriptor OLDFD into file descriptor NEWFD.  Do nothing if
305    NEWFD = OLDFD, otherwise close NEWFD first if it is open.
306    Return newfd if successful, otherwise -1 and errno set.
307    See the POSIX:2008 specification
308    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/dup2.html>.  */
309 # if @REPLACE_DUP2@
310 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
311 #   define dup2 rpl_dup2
312 #  endif
313 _GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd));
314 _GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd));
315 # else
316 #  if !@HAVE_DUP2@
317 _GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd));
318 #  endif
319 _GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
320 # endif
321 _GL_CXXALIASWARN (dup2);
322 #elif defined GNULIB_POSIXCHECK
323 # undef dup2
324 # if HAVE_RAW_DECL_DUP2
325 _GL_WARN_ON_USE (dup2, "dup2 is unportable - "
326                  "use gnulib module dup2 for portability");
327 # endif
328 #endif
329
330
331 #if @GNULIB_DUP3@
332 /* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
333    specified flags.
334    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
335    and O_TEXT, O_BINARY (defined in "binary-io.h").
336    Close NEWFD first if it is open.
337    Return newfd if successful, otherwise -1 and errno set.
338    See the Linux man page at
339    <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>.  */
340 # if @HAVE_DUP3@
341 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
342 #   define dup3 rpl_dup3
343 #  endif
344 _GL_FUNCDECL_RPL (dup3, int, (int oldfd, int newfd, int flags));
345 _GL_CXXALIAS_RPL (dup3, int, (int oldfd, int newfd, int flags));
346 # else
347 _GL_FUNCDECL_SYS (dup3, int, (int oldfd, int newfd, int flags));
348 _GL_CXXALIAS_SYS (dup3, int, (int oldfd, int newfd, int flags));
349 # endif
350 _GL_CXXALIASWARN (dup3);
351 #elif defined GNULIB_POSIXCHECK
352 # undef dup3
353 # if HAVE_RAW_DECL_DUP3
354 _GL_WARN_ON_USE (dup3, "dup3 is unportable - "
355                  "use gnulib module dup3 for portability");
356 # endif
357 #endif
358
359
360 #if @GNULIB_ENVIRON@
361 # if !@HAVE_DECL_ENVIRON@
362 /* Set of environment variables and values.  An array of strings of the form
363    "VARIABLE=VALUE", terminated with a NULL.  */
364 #  if defined __APPLE__ && defined __MACH__
365 #   include <crt_externs.h>
366 #   define environ (*_NSGetEnviron ())
367 #  else
368 #   ifdef __cplusplus
369 extern "C" {
370 #   endif
371 extern char **environ;
372 #   ifdef __cplusplus
373 }
374 #   endif
375 #  endif
376 # endif
377 #elif defined GNULIB_POSIXCHECK
378 # if HAVE_RAW_DECL_ENVIRON
379 static inline char ***
380 rpl_environ (void)
381 {
382   return &environ;
383 }
384 _GL_WARN_ON_USE (rpl_environ, "environ is unportable - "
385                  "use gnulib module environ for portability");
386 #  undef environ
387 #  define environ (*rpl_environ ())
388 # endif
389 #endif
390
391
392 #if @GNULIB_EUIDACCESS@
393 /* Like access(), except that it uses the effective user id and group id of
394    the current process.  */
395 # if !@HAVE_EUIDACCESS@
396 _GL_FUNCDECL_SYS (euidaccess, int, (const char *filename, int mode)
397                                    _GL_ARG_NONNULL ((1)));
398 # endif
399 _GL_CXXALIAS_SYS (euidaccess, int, (const char *filename, int mode));
400 _GL_CXXALIASWARN (euidaccess);
401 # if defined GNULIB_POSIXCHECK
402 /* Like access(), this function is a security risk.  */
403 _GL_WARN_ON_USE (euidaccess, "the euidaccess function is a security risk - "
404                  "use the gnulib module faccessat instead");
405 # endif
406 #elif defined GNULIB_POSIXCHECK
407 # undef euidaccess
408 # if HAVE_RAW_DECL_EUIDACCESS
409 _GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - "
410                  "use gnulib module euidaccess for portability");
411 # endif
412 #endif
413
414
415 #if @GNULIB_FACCESSAT@
416 # if !@HAVE_FACCESSAT@
417 _GL_FUNCDECL_SYS (faccessat, int,
418                   (int fd, char const *file, int mode, int flag)
419                   _GL_ARG_NONNULL ((2)));
420 # endif
421 _GL_CXXALIAS_SYS (faccessat, int,
422                   (int fd, char const *file, int mode, int flag));
423 _GL_CXXALIASWARN (faccessat);
424 #elif defined GNULIB_POSIXCHECK
425 # undef faccessat
426 # if HAVE_RAW_DECL_FACCESSAT
427 _GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
428                  "use gnulib module faccessat for portability");
429 # endif
430 #endif
431
432
433 #if @GNULIB_FCHDIR@
434 /* Change the process' current working directory to the directory on which
435    the given file descriptor is open.
436    Return 0 if successful, otherwise -1 and errno set.
437    See the POSIX:2008 specification
438    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fchdir.html>.  */
439 # if ! @HAVE_FCHDIR@
440 _GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
441
442 /* Gnulib internal hooks needed to maintain the fchdir metadata.  */
443 _GL_EXTERN_C int _gl_register_fd (int fd, const char *filename)
444      _GL_ARG_NONNULL ((2));
445 _GL_EXTERN_C void _gl_unregister_fd (int fd);
446 _GL_EXTERN_C int _gl_register_dup (int oldfd, int newfd);
447 _GL_EXTERN_C const char *_gl_directory_name (int fd);
448
449 # else
450 #  if !@HAVE_DECL_FCHDIR@
451 _GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
452 #  endif
453 # endif
454 _GL_CXXALIAS_SYS (fchdir, int, (int /*fd*/));
455 _GL_CXXALIASWARN (fchdir);
456 #elif defined GNULIB_POSIXCHECK
457 # undef fchdir
458 # if HAVE_RAW_DECL_FCHDIR
459 _GL_WARN_ON_USE (fchdir, "fchdir is unportable - "
460                  "use gnulib module fchdir for portability");
461 # endif
462 #endif
463
464
465 #if @GNULIB_FCHOWNAT@
466 # if @REPLACE_FCHOWNAT@
467 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
468 #   undef fchownat
469 #   define fchownat rpl_fchownat
470 #  endif
471 _GL_FUNCDECL_RPL (fchownat, int, (int fd, char const *file,
472                                   uid_t owner, gid_t group, int flag)
473                                  _GL_ARG_NONNULL ((2)));
474 _GL_CXXALIAS_RPL (fchownat, int, (int fd, char const *file,
475                                   uid_t owner, gid_t group, int flag));
476 # else
477 #  if !@HAVE_FCHOWNAT@
478 _GL_FUNCDECL_SYS (fchownat, int, (int fd, char const *file,
479                                   uid_t owner, gid_t group, int flag)
480                                  _GL_ARG_NONNULL ((2)));
481 #  endif
482 _GL_CXXALIAS_SYS (fchownat, int, (int fd, char const *file,
483                                   uid_t owner, gid_t group, int flag));
484 # endif
485 _GL_CXXALIASWARN (fchownat);
486 #elif defined GNULIB_POSIXCHECK
487 # undef fchownat
488 # if HAVE_RAW_DECL_FCHOWNAT
489 _GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
490                  "use gnulib module openat for portability");
491 # endif
492 #endif
493
494
495 #if @GNULIB_FDATASYNC@
496 /* Synchronize changes to a file.
497    Return 0 if successful, otherwise -1 and errno set.
498    See POSIX:2008 specification
499    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html>.  */
500 # if !@HAVE_FDATASYNC@ || !@HAVE_DECL_FDATASYNC@
501 _GL_FUNCDECL_SYS (fdatasync, int, (int fd));
502 # endif
503 _GL_CXXALIAS_SYS (fdatasync, int, (int fd));
504 _GL_CXXALIASWARN (fdatasync);
505 #elif defined GNULIB_POSIXCHECK
506 # undef fdatasync
507 # if HAVE_RAW_DECL_FDATASYNC
508 _GL_WARN_ON_USE (fdatasync, "fdatasync is unportable - "
509                  "use gnulib module fdatasync for portability");
510 # endif
511 #endif
512
513
514 #if @GNULIB_FSYNC@
515 /* Synchronize changes, including metadata, to a file.
516    Return 0 if successful, otherwise -1 and errno set.
517    See POSIX:2008 specification
518    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html>.  */
519 # if !@HAVE_FSYNC@
520 _GL_FUNCDECL_SYS (fsync, int, (int fd));
521 # endif
522 _GL_CXXALIAS_SYS (fsync, int, (int fd));
523 _GL_CXXALIASWARN (fsync);
524 #elif defined GNULIB_POSIXCHECK
525 # undef fsync
526 # if HAVE_RAW_DECL_FSYNC
527 _GL_WARN_ON_USE (fsync, "fsync is unportable - "
528                  "use gnulib module fsync for portability");
529 # endif
530 #endif
531
532
533 #if @GNULIB_FTRUNCATE@
534 /* Change the size of the file to which FD is opened to become equal to LENGTH.
535    Return 0 if successful, otherwise -1 and errno set.
536    See the POSIX:2008 specification
537    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html>.  */
538 # if !@HAVE_FTRUNCATE@
539 _GL_FUNCDECL_SYS (ftruncate, int, (int fd, off_t length));
540 # endif
541 _GL_CXXALIAS_SYS (ftruncate, int, (int fd, off_t length));
542 _GL_CXXALIASWARN (ftruncate);
543 #elif defined GNULIB_POSIXCHECK
544 # undef ftruncate
545 # if HAVE_RAW_DECL_FTRUNCATE
546 _GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
547                  "use gnulib module ftruncate for portability");
548 # endif
549 #endif
550
551
552 #if @GNULIB_GETCWD@
553 /* Get the name of the current working directory, and put it in SIZE bytes
554    of BUF.
555    Return BUF if successful, or NULL if the directory couldn't be determined
556    or SIZE was too small.
557    See the POSIX:2008 specification
558    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/getcwd.html>.
559    Additionally, the gnulib module 'getcwd' guarantees the following GNU
560    extension: If BUF is NULL, an array is allocated with 'malloc'; the array
561    is SIZE bytes long, unless SIZE == 0, in which case it is as big as
562    necessary.  */
563 # if @REPLACE_GETCWD@
564 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
565 #   define getcwd rpl_getcwd
566 #  endif
567 _GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size));
568 _GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size));
569 # else
570 /* Need to cast, because on mingw, the second parameter is
571                                                    int size.  */
572 _GL_CXXALIAS_SYS_CAST (getcwd, char *, (char *buf, size_t size));
573 # endif
574 _GL_CXXALIASWARN (getcwd);
575 #elif defined GNULIB_POSIXCHECK
576 # undef getcwd
577 # if HAVE_RAW_DECL_GETCWD
578 _GL_WARN_ON_USE (getcwd, "getcwd is unportable - "
579                  "use gnulib module getcwd for portability");
580 # endif
581 #endif
582
583
584 #if @GNULIB_GETDOMAINNAME@
585 /* Return the NIS domain name of the machine.
586    WARNING! The NIS domain name is unrelated to the fully qualified host name
587             of the machine.  It is also unrelated to email addresses.
588    WARNING! The NIS domain name is usually the empty string or "(none)" when
589             not using NIS.
590
591    Put up to LEN bytes of the NIS domain name into NAME.
592    Null terminate it if the name is shorter than LEN.
593    If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
594    Return 0 if successful, otherwise set errno and return -1.  */
595 # if @REPLACE_GETDOMAINNAME@
596 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
597 #   undef getdomainname
598 #   define getdomainname rpl_getdomainname
599 #  endif
600 _GL_FUNCDECL_RPL (getdomainname, int, (char *name, size_t len)
601                                       _GL_ARG_NONNULL ((1)));
602 _GL_CXXALIAS_RPL (getdomainname, int, (char *name, size_t len));
603 # else
604 #  if !@HAVE_DECL_GETDOMAINNAME@
605 _GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len)
606                                       _GL_ARG_NONNULL ((1)));
607 #  endif
608 _GL_CXXALIAS_SYS (getdomainname, int, (char *name, size_t len));
609 # endif
610 _GL_CXXALIASWARN (getdomainname);
611 #elif defined GNULIB_POSIXCHECK
612 # undef getdomainname
613 # if HAVE_RAW_DECL_GETDOMAINNAME
614 _GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - "
615                  "use gnulib module getdomainname for portability");
616 # endif
617 #endif
618
619
620 #if @GNULIB_GETDTABLESIZE@
621 /* Return the maximum number of file descriptors in the current process.
622    In POSIX, this is same as sysconf (_SC_OPEN_MAX).  */
623 # if !@HAVE_GETDTABLESIZE@
624 _GL_FUNCDECL_SYS (getdtablesize, int, (void));
625 # endif
626 _GL_CXXALIAS_SYS (getdtablesize, int, (void));
627 _GL_CXXALIASWARN (getdtablesize);
628 #elif defined GNULIB_POSIXCHECK
629 # undef getdtablesize
630 # if HAVE_RAW_DECL_GETDTABLESIZE
631 _GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - "
632                  "use gnulib module getdtablesize for portability");
633 # endif
634 #endif
635
636
637 #if @GNULIB_GETGROUPS@
638 /* Return the supplemental groups that the current process belongs to.
639    It is unspecified whether the effective group id is in the list.
640    If N is 0, return the group count; otherwise, N describes how many
641    entries are available in GROUPS.  Return -1 and set errno if N is
642    not 0 and not large enough.  Fails with ENOSYS on some systems.  */
643 # if @REPLACE_GETGROUPS@
644 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
645 #   undef getgroups
646 #   define getgroups rpl_getgroups
647 #  endif
648 _GL_FUNCDECL_RPL (getgroups, int, (int n, gid_t *groups));
649 _GL_CXXALIAS_RPL (getgroups, int, (int n, gid_t *groups));
650 # else
651 #  if !@HAVE_GETGROUPS@
652 _GL_FUNCDECL_SYS (getgroups, int, (int n, gid_t *groups));
653 #  endif
654 _GL_CXXALIAS_SYS (getgroups, int, (int n, gid_t *groups));
655 # endif
656 _GL_CXXALIASWARN (getgroups);
657 #elif defined GNULIB_POSIXCHECK
658 # undef getgroups
659 # if HAVE_RAW_DECL_GETGROUPS
660 _GL_WARN_ON_USE (getgroups, "getgroups is unportable - "
661                  "use gnulib module getgroups for portability");
662 # endif
663 #endif
664
665
666 #if @GNULIB_GETHOSTNAME@
667 /* Return the standard host name of the machine.
668    WARNING! The host name may or may not be fully qualified.
669
670    Put up to LEN bytes of the host name into NAME.
671    Null terminate it if the name is shorter than LEN.
672    If the host name is longer than LEN, set errno = EINVAL and return -1.
673    Return 0 if successful, otherwise set errno and return -1.  */
674 # if @UNISTD_H_HAVE_WINSOCK2_H@
675 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
676 #   undef gethostname
677 #   define gethostname rpl_gethostname
678 #  endif
679 _GL_FUNCDECL_RPL (gethostname, int, (char *name, size_t len)
680                                     _GL_ARG_NONNULL ((1)));
681 _GL_CXXALIAS_RPL (gethostname, int, (char *name, size_t len));
682 # else
683 #  if !@HAVE_GETHOSTNAME@
684 _GL_FUNCDECL_SYS (gethostname, int, (char *name, size_t len)
685                                     _GL_ARG_NONNULL ((1)));
686 #  endif
687 /* Need to cast, because on Solaris 10 and OSF/1 5.1 systems, the second
688    parameter is
689                                                       int len.  */
690 _GL_CXXALIAS_SYS_CAST (gethostname, int, (char *name, size_t len));
691 # endif
692 _GL_CXXALIASWARN (gethostname);
693 #elif @UNISTD_H_HAVE_WINSOCK2_H@
694 # undef gethostname
695 # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
696 #elif defined GNULIB_POSIXCHECK
697 # undef gethostname
698 # if HAVE_RAW_DECL_GETHOSTNAME
699 _GL_WARN_ON_USE (gethostname, "gethostname is unportable - "
700                  "use gnulib module gethostname for portability");
701 # endif
702 #endif
703
704
705 #if @GNULIB_GETLOGIN@
706 /* Returns the user's login name, or NULL if it cannot be found.  Upon error,
707    returns NULL with errno set.
708
709    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
710
711    Most programs don't need to use this function, because the information is
712    available through environment variables:
713      ${LOGNAME-$USER}        on Unix platforms,
714      $USERNAME               on native Windows platforms.
715  */
716 # if !@HAVE_GETLOGIN@
717 _GL_FUNCDECL_SYS (getlogin, char *, (void));
718 # endif
719 _GL_CXXALIAS_SYS (getlogin, char *, (void));
720 _GL_CXXALIASWARN (getlogin);
721 #elif defined GNULIB_POSIXCHECK
722 # undef getlogin
723 # if HAVE_RAW_DECL_GETLOGIN
724 _GL_WARN_ON_USE (getlogin, "getlogin is unportable - "
725                  "use gnulib module getlogin for portability");
726 # endif
727 #endif
728
729
730 #if @GNULIB_GETLOGIN_R@
731 /* Copies the user's login name to NAME.
732    The array pointed to by NAME has room for SIZE bytes.
733
734    Returns 0 if successful.  Upon error, an error number is returned, or -1 in
735    the case that the login name cannot be found but no specific error is
736    provided (this case is hopefully rare but is left open by the POSIX spec).
737
738    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
739
740    Most programs don't need to use this function, because the information is
741    available through environment variables:
742      ${LOGNAME-$USER}        on Unix platforms,
743      $USERNAME               on native Windows platforms.
744  */
745 # if @REPLACE_GETLOGIN_R@
746 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
747 #   define getlogin_r rpl_getlogin_r
748 #  endif
749 _GL_FUNCDECL_RPL (getlogin_r, int, (char *name, size_t size)
750                                    _GL_ARG_NONNULL ((1)));
751 _GL_CXXALIAS_RPL (getlogin_r, int, (char *name, size_t size));
752 # else
753 #  if !@HAVE_DECL_GETLOGIN_R@
754 _GL_FUNCDECL_SYS (getlogin_r, int, (char *name, size_t size)
755                                    _GL_ARG_NONNULL ((1)));
756 #  endif
757 /* Need to cast, because on Solaris 10 systems, the second argument is
758                                                      int size.  */
759 _GL_CXXALIAS_SYS_CAST (getlogin_r, int, (char *name, size_t size));
760 # endif
761 _GL_CXXALIASWARN (getlogin_r);
762 #elif defined GNULIB_POSIXCHECK
763 # undef getlogin_r
764 # if HAVE_RAW_DECL_GETLOGIN_R
765 _GL_WARN_ON_USE (getlogin_r, "getlogin_r is unportable - "
766                  "use gnulib module getlogin_r for portability");
767 # endif
768 #endif
769
770
771 #if @GNULIB_GETPAGESIZE@
772 # if @REPLACE_GETPAGESIZE@
773 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
774 #   define getpagesize rpl_getpagesize
775 #  endif
776 _GL_FUNCDECL_RPL (getpagesize, int, (void));
777 _GL_CXXALIAS_RPL (getpagesize, int, (void));
778 # else
779 #  if !@HAVE_GETPAGESIZE@
780 #   if !defined getpagesize
781 /* This is for POSIX systems.  */
782 #    if !defined _gl_getpagesize && defined _SC_PAGESIZE
783 #     if ! (defined __VMS && __VMS_VER < 70000000)
784 #      define _gl_getpagesize() sysconf (_SC_PAGESIZE)
785 #     endif
786 #    endif
787 /* This is for older VMS.  */
788 #    if !defined _gl_getpagesize && defined __VMS
789 #     ifdef __ALPHA
790 #      define _gl_getpagesize() 8192
791 #     else
792 #      define _gl_getpagesize() 512
793 #     endif
794 #    endif
795 /* This is for BeOS.  */
796 #    if !defined _gl_getpagesize && @HAVE_OS_H@
797 #     include <OS.h>
798 #     if defined B_PAGE_SIZE
799 #      define _gl_getpagesize() B_PAGE_SIZE
800 #     endif
801 #    endif
802 /* This is for AmigaOS4.0.  */
803 #    if !defined _gl_getpagesize && defined __amigaos4__
804 #     define _gl_getpagesize() 2048
805 #    endif
806 /* This is for older Unix systems.  */
807 #    if !defined _gl_getpagesize && @HAVE_SYS_PARAM_H@
808 #     include <sys/param.h>
809 #     ifdef EXEC_PAGESIZE
810 #      define _gl_getpagesize() EXEC_PAGESIZE
811 #     else
812 #      ifdef NBPG
813 #       ifndef CLSIZE
814 #        define CLSIZE 1
815 #       endif
816 #       define _gl_getpagesize() (NBPG * CLSIZE)
817 #      else
818 #       ifdef NBPC
819 #        define _gl_getpagesize() NBPC
820 #       endif
821 #      endif
822 #     endif
823 #    endif
824 #    if !(defined __cplusplus && defined GNULIB_NAMESPACE)
825 #     define getpagesize() _gl_getpagesize ()
826 #    else
827 #     if !GNULIB_defined_getpagesize_function
828 static inline int
829 getpagesize ()
830 {
831   return _gl_getpagesize ();
832 }
833 #      define GNULIB_defined_getpagesize_function 1
834 #     endif
835 #    endif
836 #   endif
837 #  endif
838 /* Need to cast, because on Cygwin 1.5.x systems, the return type is size_t.  */
839 _GL_CXXALIAS_SYS_CAST (getpagesize, int, (void));
840 # endif
841 # if @HAVE_DECL_GETPAGESIZE@
842 _GL_CXXALIASWARN (getpagesize);
843 # endif
844 #elif defined GNULIB_POSIXCHECK
845 # undef getpagesize
846 # if HAVE_RAW_DECL_GETPAGESIZE
847 _GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - "
848                  "use gnulib module getpagesize for portability");
849 # endif
850 #endif
851
852
853 #if @GNULIB_GETUSERSHELL@
854 /* Return the next valid login shell on the system, or NULL when the end of
855    the list has been reached.  */
856 # if !@HAVE_DECL_GETUSERSHELL@
857 _GL_FUNCDECL_SYS (getusershell, char *, (void));
858 # endif
859 _GL_CXXALIAS_SYS (getusershell, char *, (void));
860 _GL_CXXALIASWARN (getusershell);
861 #elif defined GNULIB_POSIXCHECK
862 # undef getusershell
863 # if HAVE_RAW_DECL_GETUSERSHELL
864 _GL_WARN_ON_USE (getusershell, "getusershell is unportable - "
865                  "use gnulib module getusershell for portability");
866 # endif
867 #endif
868
869 #if @GNULIB_GETUSERSHELL@
870 /* Rewind to pointer that is advanced at each getusershell() call.  */
871 # if !@HAVE_DECL_GETUSERSHELL@
872 _GL_FUNCDECL_SYS (setusershell, void, (void));
873 # endif
874 _GL_CXXALIAS_SYS (setusershell, void, (void));
875 _GL_CXXALIASWARN (setusershell);
876 #elif defined GNULIB_POSIXCHECK
877 # undef setusershell
878 # if HAVE_RAW_DECL_SETUSERSHELL
879 _GL_WARN_ON_USE (setusershell, "setusershell is unportable - "
880                  "use gnulib module getusershell for portability");
881 # endif
882 #endif
883
884 #if @GNULIB_GETUSERSHELL@
885 /* Free the pointer that is advanced at each getusershell() call and
886    associated resources.  */
887 # if !@HAVE_DECL_GETUSERSHELL@
888 _GL_FUNCDECL_SYS (endusershell, void, (void));
889 # endif
890 _GL_CXXALIAS_SYS (endusershell, void, (void));
891 _GL_CXXALIASWARN (endusershell);
892 #elif defined GNULIB_POSIXCHECK
893 # undef endusershell
894 # if HAVE_RAW_DECL_ENDUSERSHELL
895 _GL_WARN_ON_USE (endusershell, "endusershell is unportable - "
896                  "use gnulib module getusershell for portability");
897 # endif
898 #endif
899
900
901 #if @GNULIB_GROUP_MEMBER@
902 /* Determine whether group id is in calling user's group list.  */
903 # if !@HAVE_GROUP_MEMBER@
904 _GL_FUNCDECL_SYS (group_member, int, (gid_t gid));
905 # endif
906 _GL_CXXALIAS_SYS (group_member, int, (gid_t gid));
907 _GL_CXXALIASWARN (group_member);
908 #elif defined GNULIB_POSIXCHECK
909 # undef group_member
910 # if HAVE_RAW_DECL_GROUP_MEMBER
911 _GL_WARN_ON_USE (group_member, "group_member is unportable - "
912                  "use gnulib module group-member for portability");
913 # endif
914 #endif
915
916
917 #if @GNULIB_LCHOWN@
918 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
919    to GID (if GID is not -1).  Do not follow symbolic links.
920    Return 0 if successful, otherwise -1 and errno set.
921    See the POSIX:2008 specification
922    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lchown.html>.  */
923 # if @REPLACE_LCHOWN@
924 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
925 #   undef lchown
926 #   define lchown rpl_lchown
927 #  endif
928 _GL_FUNCDECL_RPL (lchown, int, (char const *file, uid_t owner, gid_t group)
929                                _GL_ARG_NONNULL ((1)));
930 _GL_CXXALIAS_RPL (lchown, int, (char const *file, uid_t owner, gid_t group));
931 # else
932 #  if !@HAVE_LCHOWN@
933 _GL_FUNCDECL_SYS (lchown, int, (char const *file, uid_t owner, gid_t group)
934                                _GL_ARG_NONNULL ((1)));
935 #  endif
936 _GL_CXXALIAS_SYS (lchown, int, (char const *file, uid_t owner, gid_t group));
937 # endif
938 _GL_CXXALIASWARN (lchown);
939 #elif defined GNULIB_POSIXCHECK
940 # undef lchown
941 # if HAVE_RAW_DECL_LCHOWN
942 _GL_WARN_ON_USE (lchown, "lchown is unportable to pre-POSIX.1-2001 systems - "
943                  "use gnulib module lchown for portability");
944 # endif
945 #endif
946
947
948 #if @GNULIB_LINK@
949 /* Create a new hard link for an existing file.
950    Return 0 if successful, otherwise -1 and errno set.
951    See POSIX:2008 specification
952    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/link.html>.  */
953 # if @REPLACE_LINK@
954 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
955 #   define link rpl_link
956 #  endif
957 _GL_FUNCDECL_RPL (link, int, (const char *path1, const char *path2)
958                              _GL_ARG_NONNULL ((1, 2)));
959 _GL_CXXALIAS_RPL (link, int, (const char *path1, const char *path2));
960 # else
961 #  if !@HAVE_LINK@
962 _GL_FUNCDECL_SYS (link, int, (const char *path1, const char *path2)
963                              _GL_ARG_NONNULL ((1, 2)));
964 #  endif
965 _GL_CXXALIAS_SYS (link, int, (const char *path1, const char *path2));
966 # endif
967 _GL_CXXALIASWARN (link);
968 #elif defined GNULIB_POSIXCHECK
969 # undef link
970 # if HAVE_RAW_DECL_LINK
971 _GL_WARN_ON_USE (link, "link is unportable - "
972                  "use gnulib module link for portability");
973 # endif
974 #endif
975
976
977 #if @GNULIB_LINKAT@
978 /* Create a new hard link for an existing file, relative to two
979    directories.  FLAG controls whether symlinks are followed.
980    Return 0 if successful, otherwise -1 and errno set.  */
981 # if @REPLACE_LINKAT@
982 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
983 #   undef linkat
984 #   define linkat rpl_linkat
985 #  endif
986 _GL_FUNCDECL_RPL (linkat, int,
987                   (int fd1, const char *path1, int fd2, const char *path2,
988                    int flag)
989                   _GL_ARG_NONNULL ((2, 4)));
990 _GL_CXXALIAS_RPL (linkat, int,
991                   (int fd1, const char *path1, int fd2, const char *path2,
992                    int flag));
993 # else
994 #  if !@HAVE_LINKAT@
995 _GL_FUNCDECL_SYS (linkat, int,
996                   (int fd1, const char *path1, int fd2, const char *path2,
997                    int flag)
998                   _GL_ARG_NONNULL ((2, 4)));
999 #  endif
1000 _GL_CXXALIAS_SYS (linkat, int,
1001                   (int fd1, const char *path1, int fd2, const char *path2,
1002                    int flag));
1003 # endif
1004 _GL_CXXALIASWARN (linkat);
1005 #elif defined GNULIB_POSIXCHECK
1006 # undef linkat
1007 # if HAVE_RAW_DECL_LINKAT
1008 _GL_WARN_ON_USE (linkat, "linkat is unportable - "
1009                  "use gnulib module linkat for portability");
1010 # endif
1011 #endif
1012
1013
1014 #if @GNULIB_LSEEK@
1015 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
1016    Return the new offset if successful, otherwise -1 and errno set.
1017    See the POSIX:2008 specification
1018    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html>.  */
1019 # if @REPLACE_LSEEK@
1020 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1021 #   define lseek rpl_lseek
1022 #  endif
1023 _GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence));
1024 _GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence));
1025 # else
1026 _GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
1027 # endif
1028 _GL_CXXALIASWARN (lseek);
1029 #elif defined GNULIB_POSIXCHECK
1030 # undef lseek
1031 # if HAVE_RAW_DECL_LSEEK
1032 _GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some "
1033                  "systems - use gnulib module lseek for portability");
1034 # endif
1035 #endif
1036
1037
1038 #if @GNULIB_PIPE@
1039 /* Create a pipe, defaulting to O_BINARY mode.
1040    Store the read-end as fd[0] and the write-end as fd[1].
1041    Return 0 upon success, or -1 with errno set upon failure.  */
1042 # if !@HAVE_PIPE@
1043 _GL_FUNCDECL_SYS (pipe, int, (int fd[2]) _GL_ARG_NONNULL ((1)));
1044 # endif
1045 _GL_CXXALIAS_SYS (pipe, int, (int fd[2]));
1046 _GL_CXXALIASWARN (pipe);
1047 #elif defined GNULIB_POSIXCHECK
1048 # undef pipe
1049 # if HAVE_RAW_DECL_PIPE
1050 _GL_WARN_ON_USE (pipe, "pipe is unportable - "
1051                  "use gnulib module pipe-posix for portability");
1052 # endif
1053 #endif
1054
1055
1056 #if @GNULIB_PIPE2@
1057 /* Create a pipe, applying the given flags when opening the read-end of the
1058    pipe and the write-end of the pipe.
1059    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
1060    and O_TEXT, O_BINARY (defined in "binary-io.h").
1061    Store the read-end as fd[0] and the write-end as fd[1].
1062    Return 0 upon success, or -1 with errno set upon failure.
1063    See also the Linux man page at
1064    <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>.  */
1065 # if @HAVE_PIPE2@
1066 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1067 #   define pipe2 rpl_pipe2
1068 #  endif
1069 _GL_FUNCDECL_RPL (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
1070 _GL_CXXALIAS_RPL (pipe2, int, (int fd[2], int flags));
1071 # else
1072 _GL_FUNCDECL_SYS (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
1073 _GL_CXXALIAS_SYS (pipe2, int, (int fd[2], int flags));
1074 # endif
1075 _GL_CXXALIASWARN (pipe2);
1076 #elif defined GNULIB_POSIXCHECK
1077 # undef pipe2
1078 # if HAVE_RAW_DECL_PIPE2
1079 _GL_WARN_ON_USE (pipe2, "pipe2 is unportable - "
1080                  "use gnulib module pipe2 for portability");
1081 # endif
1082 #endif
1083
1084
1085 #if @GNULIB_PREAD@
1086 /* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
1087    Return the number of bytes placed into BUF if successful, otherwise
1088    set errno and return -1.  0 indicates EOF.
1089    See the POSIX:2008 specification
1090    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pread.html>.  */
1091 # if @REPLACE_PREAD@
1092 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1093 #   undef pread
1094 #   define pread rpl_pread
1095 #  endif
1096 _GL_FUNCDECL_RPL (pread, ssize_t,
1097                   (int fd, void *buf, size_t bufsize, off_t offset)
1098                   _GL_ARG_NONNULL ((2)));
1099 _GL_CXXALIAS_RPL (pread, ssize_t,
1100                   (int fd, void *buf, size_t bufsize, off_t offset));
1101 # else
1102 #  if !@HAVE_PREAD@
1103 _GL_FUNCDECL_SYS (pread, ssize_t,
1104                   (int fd, void *buf, size_t bufsize, off_t offset)
1105                   _GL_ARG_NONNULL ((2)));
1106 #  endif
1107 _GL_CXXALIAS_SYS (pread, ssize_t,
1108                   (int fd, void *buf, size_t bufsize, off_t offset));
1109 # endif
1110 _GL_CXXALIASWARN (pread);
1111 #elif defined GNULIB_POSIXCHECK
1112 # undef pread
1113 # if HAVE_RAW_DECL_PREAD
1114 _GL_WARN_ON_USE (pread, "pread is unportable - "
1115                  "use gnulib module pread for portability");
1116 # endif
1117 #endif
1118
1119
1120 #if @GNULIB_PWRITE@
1121 /* Write at most BUFSIZE bytes from BUF into FD, starting at OFFSET.
1122    Return the number of bytes written if successful, otherwise
1123    set errno and return -1.  0 indicates nothing written.  See the
1124    POSIX:2008 specification
1125    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/pwrite.html>.  */
1126 # if @REPLACE_PWRITE@
1127 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1128 #   undef pwrite
1129 #   define pwrite rpl_pwrite
1130 #  endif
1131 _GL_FUNCDECL_RPL (pwrite, ssize_t,
1132                   (int fd, const void *buf, size_t bufsize, off_t offset)
1133                   _GL_ARG_NONNULL ((2)));
1134 _GL_CXXALIAS_RPL (pwrite, ssize_t,
1135                   (int fd, const void *buf, size_t bufsize, off_t offset));
1136 # else
1137 #  if !@HAVE_PWRITE@
1138 _GL_FUNCDECL_SYS (pwrite, ssize_t,
1139                   (int fd, const void *buf, size_t bufsize, off_t offset)
1140                   _GL_ARG_NONNULL ((2)));
1141 #  endif
1142 _GL_CXXALIAS_SYS (pwrite, ssize_t,
1143                   (int fd, const void *buf, size_t bufsize, off_t offset));
1144 # endif
1145 _GL_CXXALIASWARN (pwrite);
1146 #elif defined GNULIB_POSIXCHECK
1147 # undef pwrite
1148 # if HAVE_RAW_DECL_PWRITE
1149 _GL_WARN_ON_USE (pwrite, "pwrite is unportable - "
1150                  "use gnulib module pwrite for portability");
1151 # endif
1152 #endif
1153
1154
1155 #if @GNULIB_READ@
1156 /* Read up to COUNT bytes from file descriptor FD into the buffer starting
1157    at BUF.  See the POSIX:2008 specification
1158    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html>.  */
1159 # if @REPLACE_READ@ && @GNULIB_UNISTD_H_NONBLOCKING@
1160 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1161 #   undef read
1162 #   define read rpl_read
1163 #  endif
1164 _GL_FUNCDECL_RPL (read, ssize_t, (int fd, void *buf, size_t count)
1165                                  _GL_ARG_NONNULL ((2)));
1166 _GL_CXXALIAS_RPL (read, ssize_t, (int fd, void *buf, size_t count));
1167 # else
1168 /* Need to cast, because on mingw, the third parameter is
1169                                                           unsigned int count
1170    and the return type is 'int'.  */
1171 _GL_CXXALIAS_SYS_CAST (read, ssize_t, (int fd, void *buf, size_t count));
1172 # endif
1173 _GL_CXXALIASWARN (read);
1174 #endif
1175
1176
1177 #if @GNULIB_READLINK@
1178 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
1179    bytes of it into BUF.  Return the number of bytes placed into BUF if
1180    successful, otherwise -1 and errno set.
1181    See the POSIX:2008 specification
1182    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/readlink.html>.  */
1183 # if @REPLACE_READLINK@
1184 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1185 #   define readlink rpl_readlink
1186 #  endif
1187 _GL_FUNCDECL_RPL (readlink, ssize_t,
1188                   (const char *file, char *buf, size_t bufsize)
1189                   _GL_ARG_NONNULL ((1, 2)));
1190 _GL_CXXALIAS_RPL (readlink, ssize_t,
1191                   (const char *file, char *buf, size_t bufsize));
1192 # else
1193 #  if !@HAVE_READLINK@
1194 _GL_FUNCDECL_SYS (readlink, ssize_t,
1195                   (const char *file, char *buf, size_t bufsize)
1196                   _GL_ARG_NONNULL ((1, 2)));
1197 #  endif
1198 _GL_CXXALIAS_SYS (readlink, ssize_t,
1199                   (const char *file, char *buf, size_t bufsize));
1200 # endif
1201 _GL_CXXALIASWARN (readlink);
1202 #elif defined GNULIB_POSIXCHECK
1203 # undef readlink
1204 # if HAVE_RAW_DECL_READLINK
1205 _GL_WARN_ON_USE (readlink, "readlink is unportable - "
1206                  "use gnulib module readlink for portability");
1207 # endif
1208 #endif
1209
1210
1211 #if @GNULIB_READLINKAT@
1212 # if !@HAVE_READLINKAT@
1213 _GL_FUNCDECL_SYS (readlinkat, ssize_t,
1214                   (int fd, char const *file, char *buf, size_t len)
1215                   _GL_ARG_NONNULL ((2, 3)));
1216 # endif
1217 _GL_CXXALIAS_SYS (readlinkat, ssize_t,
1218                   (int fd, char const *file, char *buf, size_t len));
1219 _GL_CXXALIASWARN (readlinkat);
1220 #elif defined GNULIB_POSIXCHECK
1221 # undef readlinkat
1222 # if HAVE_RAW_DECL_READLINKAT
1223 _GL_WARN_ON_USE (readlinkat, "readlinkat is not portable - "
1224                  "use gnulib module readlinkat for portability");
1225 # endif
1226 #endif
1227
1228
1229 #if @GNULIB_RMDIR@
1230 /* Remove the directory DIR.  */
1231 # if @REPLACE_RMDIR@
1232 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1233 #   define rmdir rpl_rmdir
1234 #  endif
1235 _GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1)));
1236 _GL_CXXALIAS_RPL (rmdir, int, (char const *name));
1237 # else
1238 _GL_CXXALIAS_SYS (rmdir, int, (char const *name));
1239 # endif
1240 _GL_CXXALIASWARN (rmdir);
1241 #elif defined GNULIB_POSIXCHECK
1242 # undef rmdir
1243 # if HAVE_RAW_DECL_RMDIR
1244 _GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
1245                  "use gnulib module rmdir for portability");
1246 # endif
1247 #endif
1248
1249
1250 #if @GNULIB_SLEEP@
1251 /* Pause the execution of the current thread for N seconds.
1252    Returns the number of seconds left to sleep.
1253    See the POSIX:2008 specification
1254    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/sleep.html>.  */
1255 # if @REPLACE_SLEEP@
1256 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1257 #   undef sleep
1258 #   define sleep rpl_sleep
1259 #  endif
1260 _GL_FUNCDECL_RPL (sleep, unsigned int, (unsigned int n));
1261 _GL_CXXALIAS_RPL (sleep, unsigned int, (unsigned int n));
1262 # else
1263 #  if !@HAVE_SLEEP@
1264 _GL_FUNCDECL_SYS (sleep, unsigned int, (unsigned int n));
1265 #  endif
1266 _GL_CXXALIAS_SYS (sleep, unsigned int, (unsigned int n));
1267 # endif
1268 _GL_CXXALIASWARN (sleep);
1269 #elif defined GNULIB_POSIXCHECK
1270 # undef sleep
1271 # if HAVE_RAW_DECL_SLEEP
1272 _GL_WARN_ON_USE (sleep, "sleep is unportable - "
1273                  "use gnulib module sleep for portability");
1274 # endif
1275 #endif
1276
1277
1278 #if @GNULIB_SYMLINK@
1279 # if @REPLACE_SYMLINK@
1280 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1281 #   undef symlink
1282 #   define symlink rpl_symlink
1283 #  endif
1284 _GL_FUNCDECL_RPL (symlink, int, (char const *contents, char const *file)
1285                                 _GL_ARG_NONNULL ((1, 2)));
1286 _GL_CXXALIAS_RPL (symlink, int, (char const *contents, char const *file));
1287 # else
1288 #  if !@HAVE_SYMLINK@
1289 _GL_FUNCDECL_SYS (symlink, int, (char const *contents, char const *file)
1290                                 _GL_ARG_NONNULL ((1, 2)));
1291 #  endif
1292 _GL_CXXALIAS_SYS (symlink, int, (char const *contents, char const *file));
1293 # endif
1294 _GL_CXXALIASWARN (symlink);
1295 #elif defined GNULIB_POSIXCHECK
1296 # undef symlink
1297 # if HAVE_RAW_DECL_SYMLINK
1298 _GL_WARN_ON_USE (symlink, "symlink is not portable - "
1299                  "use gnulib module symlink for portability");
1300 # endif
1301 #endif
1302
1303
1304 #if @GNULIB_SYMLINKAT@
1305 # if !@HAVE_SYMLINKAT@
1306 _GL_FUNCDECL_SYS (symlinkat, int,
1307                   (char const *contents, int fd, char const *file)
1308                   _GL_ARG_NONNULL ((1, 3)));
1309 # endif
1310 _GL_CXXALIAS_SYS (symlinkat, int,
1311                   (char const *contents, int fd, char const *file));
1312 _GL_CXXALIASWARN (symlinkat);
1313 #elif defined GNULIB_POSIXCHECK
1314 # undef symlinkat
1315 # if HAVE_RAW_DECL_SYMLINKAT
1316 _GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - "
1317                  "use gnulib module symlinkat for portability");
1318 # endif
1319 #endif
1320
1321
1322 #if @GNULIB_TTYNAME_R@
1323 /* Store at most BUFLEN characters of the pathname of the terminal FD is
1324    open on in BUF.  Return 0 on success, otherwise an error number.  */
1325 # if @REPLACE_TTYNAME_R@
1326 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1327 #   undef ttyname_r
1328 #   define ttyname_r rpl_ttyname_r
1329 #  endif
1330 _GL_FUNCDECL_RPL (ttyname_r, int,
1331                   (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2)));
1332 _GL_CXXALIAS_RPL (ttyname_r, int,
1333                   (int fd, char *buf, size_t buflen));
1334 # else
1335 #  if !@HAVE_DECL_TTYNAME_R@
1336 _GL_FUNCDECL_SYS (ttyname_r, int,
1337                   (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2)));
1338 #  endif
1339 _GL_CXXALIAS_SYS (ttyname_r, int,
1340                   (int fd, char *buf, size_t buflen));
1341 # endif
1342 _GL_CXXALIASWARN (ttyname_r);
1343 #elif defined GNULIB_POSIXCHECK
1344 # undef ttyname_r
1345 # if HAVE_RAW_DECL_TTYNAME_R
1346 _GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - "
1347                  "use gnulib module ttyname_r for portability");
1348 # endif
1349 #endif
1350
1351
1352 #if @GNULIB_UNLINK@
1353 # if @REPLACE_UNLINK@
1354 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1355 #   undef unlink
1356 #   define unlink rpl_unlink
1357 #  endif
1358 _GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1)));
1359 _GL_CXXALIAS_RPL (unlink, int, (char const *file));
1360 # else
1361 _GL_CXXALIAS_SYS (unlink, int, (char const *file));
1362 # endif
1363 _GL_CXXALIASWARN (unlink);
1364 #elif defined GNULIB_POSIXCHECK
1365 # undef unlink
1366 # if HAVE_RAW_DECL_UNLINK
1367 _GL_WARN_ON_USE (unlink, "unlink is not portable - "
1368                  "use gnulib module unlink for portability");
1369 # endif
1370 #endif
1371
1372
1373 #if @GNULIB_UNLINKAT@
1374 # if @REPLACE_UNLINKAT@
1375 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1376 #   undef unlinkat
1377 #   define unlinkat rpl_unlinkat
1378 #  endif
1379 _GL_FUNCDECL_RPL (unlinkat, int, (int fd, char const *file, int flag)
1380                                  _GL_ARG_NONNULL ((2)));
1381 _GL_CXXALIAS_RPL (unlinkat, int, (int fd, char const *file, int flag));
1382 # else
1383 #  if !@HAVE_UNLINKAT@
1384 _GL_FUNCDECL_SYS (unlinkat, int, (int fd, char const *file, int flag)
1385                                  _GL_ARG_NONNULL ((2)));
1386 #  endif
1387 _GL_CXXALIAS_SYS (unlinkat, int, (int fd, char const *file, int flag));
1388 # endif
1389 _GL_CXXALIASWARN (unlinkat);
1390 #elif defined GNULIB_POSIXCHECK
1391 # undef unlinkat
1392 # if HAVE_RAW_DECL_UNLINKAT
1393 _GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
1394                  "use gnulib module openat for portability");
1395 # endif
1396 #endif
1397
1398
1399 #if @GNULIB_USLEEP@
1400 /* Pause the execution of the current thread for N microseconds.
1401    Returns 0 on completion, or -1 on range error.
1402    See the POSIX:2001 specification
1403    <http://www.opengroup.org/susv3xsh/usleep.html>.  */
1404 # if @REPLACE_USLEEP@
1405 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1406 #   undef usleep
1407 #   define usleep rpl_usleep
1408 #  endif
1409 _GL_FUNCDECL_RPL (usleep, int, (useconds_t n));
1410 _GL_CXXALIAS_RPL (usleep, int, (useconds_t n));
1411 # else
1412 #  if !@HAVE_USLEEP@
1413 _GL_FUNCDECL_SYS (usleep, int, (useconds_t n));
1414 #  endif
1415 _GL_CXXALIAS_SYS (usleep, int, (useconds_t n));
1416 # endif
1417 _GL_CXXALIASWARN (usleep);
1418 #elif defined GNULIB_POSIXCHECK
1419 # undef usleep
1420 # if HAVE_RAW_DECL_USLEEP
1421 _GL_WARN_ON_USE (usleep, "usleep is unportable - "
1422                  "use gnulib module usleep for portability");
1423 # endif
1424 #endif
1425
1426
1427 #if @GNULIB_WRITE@
1428 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
1429    See the POSIX:2008 specification
1430    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html>.  */
1431 # if @REPLACE_WRITE@ && (@GNULIB_UNISTD_H_NONBLOCKING@ || @GNULIB_UNISTD_H_SIGPIPE@)
1432 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1433 #   undef write
1434 #   define write rpl_write
1435 #  endif
1436 _GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count)
1437                                   _GL_ARG_NONNULL ((2)));
1438 _GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count));
1439 # else
1440 /* Need to cast, because on mingw, the third parameter is
1441                                                              unsigned int count
1442    and the return type is 'int'.  */
1443 _GL_CXXALIAS_SYS_CAST (write, ssize_t, (int fd, const void *buf, size_t count));
1444 # endif
1445 _GL_CXXALIASWARN (write);
1446 #endif
1447
1448
1449 #endif /* _@GUARD_PREFIX@_UNISTD_H */
1450 #endif /* _@GUARD_PREFIX@_UNISTD_H */