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