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