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