stdio, unistd: guarantee ssize_t
[gnulib.git] / lib / unistd.in.h
1 /* Substitute for and wrapper around <unistd.h>.
2    Copyright (C) 2003-2010 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2, or (at your option)
7    any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
17
18 #ifndef _GL_UNISTD_H
19
20 #if __GNUC__ >= 3
21 @PRAGMA_SYSTEM_HEADER@
22 #endif
23
24 /* The include_next requires a split double-inclusion guard.  */
25 #if @HAVE_UNISTD_H@
26 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
27 #endif
28
29 #ifndef _GL_UNISTD_H
30 #define _GL_UNISTD_H
31
32 /* NetBSD 5.0 mis-defines NULL.  Also get size_t.  */
33 #include <stddef.h>
34
35 /* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>.  */
36 /* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>.  */
37 /* But avoid namespace pollution on glibc systems.  */
38 #if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
39      || (@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK)) \
40     && ! defined __GLIBC__
41 # include <stdio.h>
42 #endif
43
44 /* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>.  */
45 /* But avoid namespace pollution on glibc systems.  */
46 #if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) && ! defined __GLIBC__
47 # include <fcntl.h>
48 #endif
49
50 /* mingw fails to declare _exit in <unistd.h>.  */
51 /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>.  */
52 /* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>.  */
53 /* But avoid namespace pollution on glibc systems.  */
54 #ifndef __GLIBC__
55 # include <stdlib.h>
56 #endif
57
58 /* mingw declares getcwd in <io.h>, not in <unistd.h>.  */
59 #if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \
60      && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
61 # include <io.h>
62 #endif
63
64 #if (@GNULIB_WRITE@ || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \
65      || @GNULIB_PREAD@ || defined GNULIB_POSIXCHECK)
66 /* Get ssize_t.  */
67 # include <sys/types.h>
68 #endif
69
70 /* Get getopt(), optarg, optind, opterr, optopt.
71    But avoid namespace pollution on glibc systems.  */
72 #if @GNULIB_UNISTD_H_GETOPT@ && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT
73 # include <getopt.h>
74 #endif
75
76 #if @GNULIB_GETHOSTNAME@
77 /* Get all possible declarations of gethostname().  */
78 # if @UNISTD_H_HAVE_WINSOCK2_H@
79 #  include <winsock2.h>
80 #  if !defined _GL_SYS_SOCKET_H
81 #   undef socket
82 #   define socket               socket_used_without_including_sys_socket_h
83 #   undef connect
84 #   define connect              connect_used_without_including_sys_socket_h
85 #   undef accept
86 #   define accept               accept_used_without_including_sys_socket_h
87 #   undef bind
88 #   define bind                 bind_used_without_including_sys_socket_h
89 #   undef getpeername
90 #   define getpeername          getpeername_used_without_including_sys_socket_h
91 #   undef getsockname
92 #   define getsockname          getsockname_used_without_including_sys_socket_h
93 #   undef getsockopt
94 #   define getsockopt           getsockopt_used_without_including_sys_socket_h
95 #   undef listen
96 #   define listen               listen_used_without_including_sys_socket_h
97 #   undef recv
98 #   define recv                 recv_used_without_including_sys_socket_h
99 #   undef send
100 #   define send                 send_used_without_including_sys_socket_h
101 #   undef recvfrom
102 #   define recvfrom             recvfrom_used_without_including_sys_socket_h
103 #   undef sendto
104 #   define sendto               sendto_used_without_including_sys_socket_h
105 #   undef setsockopt
106 #   define setsockopt           setsockopt_used_without_including_sys_socket_h
107 #   undef shutdown
108 #   define shutdown             shutdown_used_without_including_sys_socket_h
109 #  endif
110 #  if !defined _GL_SYS_SELECT_H
111 #   undef select
112 #   define select               select_used_without_including_sys_select_h
113 #  endif
114 # endif
115 #endif
116
117 /* The definition of GL_LINK_WARNING is copied here.  */
118
119 /* The definition of _GL_ARG_NONNULL is copied here.  */
120
121
122 /* OS/2 EMX lacks these macros.  */
123 #ifndef STDIN_FILENO
124 # define STDIN_FILENO 0
125 #endif
126 #ifndef STDOUT_FILENO
127 # define STDOUT_FILENO 1
128 #endif
129 #ifndef STDERR_FILENO
130 # define STDERR_FILENO 2
131 #endif
132
133 /* Ensure *_OK macros exist.  */
134 #ifndef F_OK
135 # define F_OK 0
136 # define X_OK 1
137 # define W_OK 2
138 # define R_OK 4
139 #endif
140
141
142 /* Declare overridden functions.  */
143
144 #ifdef __cplusplus
145 extern "C" {
146 #endif
147
148
149 #if @GNULIB_CHOWN@
150 # if @REPLACE_CHOWN@
151 #  undef chown
152 #  define chown rpl_chown
153 # endif
154 # if !@HAVE_CHOWN@ || @REPLACE_CHOWN@
155 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
156    to GID (if GID is not -1).  Follow symbolic links.
157    Return 0 if successful, otherwise -1 and errno set.
158    See the POSIX:2001 specification
159    <http://www.opengroup.org/susv3xsh/chown.html>.  */
160 extern int chown (const char *file, uid_t uid, gid_t gid)
161      _GL_ARG_NONNULL ((1));
162 # endif
163 #elif defined GNULIB_POSIXCHECK
164 # undef chown
165 # define chown(f,u,g) \
166     (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
167                       "doesn't treat a uid or gid of -1 on some systems - " \
168                       "use gnulib module chown for portability"), \
169      chown (f, u, g))
170 #endif
171
172
173 #if @GNULIB_CLOSE@
174 # if @REPLACE_CLOSE@
175 /* Automatically included by modules that need a replacement for close.  */
176 #  undef close
177 #  define close rpl_close
178 extern int close (int);
179 # endif
180 #elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
181 # undef close
182 # define close close_used_without_requesting_gnulib_module_close
183 #elif defined GNULIB_POSIXCHECK
184 # undef close
185 # define close(f) \
186     (GL_LINK_WARNING ("close does not portably work on sockets - " \
187                       "use gnulib module close for portability"), \
188      close (f))
189 #endif
190
191
192 #if @REPLACE_DUP@
193 # define dup rpl_dup
194 extern int dup (int);
195 #endif
196
197
198 #if @GNULIB_DUP2@
199 # if @REPLACE_DUP2@
200 #  define dup2 rpl_dup2
201 # endif
202 # if !@HAVE_DUP2@ || @REPLACE_DUP2@
203 /* Copy the file descriptor OLDFD into file descriptor NEWFD.  Do nothing if
204    NEWFD = OLDFD, otherwise close NEWFD first if it is open.
205    Return newfd if successful, otherwise -1 and errno set.
206    See the POSIX:2001 specification
207    <http://www.opengroup.org/susv3xsh/dup2.html>.  */
208 extern int dup2 (int oldfd, int newfd);
209 # endif
210 #elif defined GNULIB_POSIXCHECK
211 # undef dup2
212 # define dup2(o,n) \
213     (GL_LINK_WARNING ("dup2 is unportable - " \
214                       "use gnulib module dup2 for portability"), \
215      dup2 (o, n))
216 #endif
217
218
219 #if @GNULIB_DUP3@
220 /* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
221    specified flags.
222    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
223    and O_TEXT, O_BINARY (defined in "binary-io.h").
224    Close NEWFD first if it is open.
225    Return newfd if successful, otherwise -1 and errno set.
226    See the Linux man page at
227    <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>.  */
228 # if @HAVE_DUP3@
229 #  define dup3 rpl_dup3
230 # endif
231 extern int dup3 (int oldfd, int newfd, int flags);
232 #elif defined GNULIB_POSIXCHECK
233 # undef dup3
234 # define dup3(o,n,f) \
235     (GL_LINK_WARNING ("dup3 is unportable - " \
236                       "use gnulib module dup3 for portability"), \
237      dup3 (o, n, f))
238 #endif
239
240
241 #if @GNULIB_ENVIRON@
242 # if !@HAVE_DECL_ENVIRON@
243 /* Set of environment variables and values.  An array of strings of the form
244    "VARIABLE=VALUE", terminated with a NULL.  */
245 #  if defined __APPLE__ && defined __MACH__
246 #   include <crt_externs.h>
247 #   define environ (*_NSGetEnviron ())
248 #  else
249 extern char **environ;
250 #  endif
251 # endif
252 #elif defined GNULIB_POSIXCHECK
253 # undef environ
254 # define environ \
255     (GL_LINK_WARNING ("environ is unportable - " \
256                       "use gnulib module environ for portability"), \
257      environ)
258 #endif
259
260
261 #if @GNULIB_EUIDACCESS@
262 # if !@HAVE_EUIDACCESS@
263 /* Like access(), except that it uses the effective user id and group id of
264    the current process.  */
265 extern int euidaccess (const char *filename, int mode) _GL_ARG_NONNULL ((1));
266 # endif
267 #elif defined GNULIB_POSIXCHECK
268 # undef euidaccess
269 # define euidaccess(f,m) \
270     (GL_LINK_WARNING ("euidaccess is unportable - " \
271                       "use gnulib module euidaccess for portability"), \
272      euidaccess (f, m))
273 #endif
274
275
276 #if @GNULIB_FACCESSAT@
277 # if !@HAVE_FACCESSAT@
278 extern int faccessat (int fd, char const *file, int mode, int flag)
279      _GL_ARG_NONNULL ((2));
280 # endif
281 #elif defined GNULIB_POSIXCHECK
282 # undef faccessat
283 # define faccessat(d,n,m,f)                         \
284     (GL_LINK_WARNING ("faccessat is not portable - " \
285                       "use gnulib module faccessat for portability"), \
286      faccessat (d, n, m, f))
287 #endif
288
289
290 #if @GNULIB_FCHDIR@
291 # if @REPLACE_FCHDIR@
292 /* Change the process' current working directory to the directory on which
293    the given file descriptor is open.
294    Return 0 if successful, otherwise -1 and errno set.
295    See the POSIX:2001 specification
296    <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
297 extern int fchdir (int /*fd*/);
298
299 /* Gnulib internal hooks needed to maintain the fchdir metadata.  */
300 extern int _gl_register_fd (int fd, const char *filename)
301      _GL_ARG_NONNULL ((2));
302 extern void _gl_unregister_fd (int fd);
303 extern int _gl_register_dup (int oldfd, int newfd);
304 extern const char *_gl_directory_name (int fd);
305
306 # endif
307 #elif defined GNULIB_POSIXCHECK
308 # undef fchdir
309 # define fchdir(f) \
310     (GL_LINK_WARNING ("fchdir is unportable - " \
311                       "use gnulib module fchdir for portability"), \
312      fchdir (f))
313 #endif
314
315
316 #if @GNULIB_FCHOWNAT@
317 # if @REPLACE_FCHOWNAT@
318 #  undef fchownat
319 #  define fchownat rpl_fchownat
320 # endif
321 # if !@HAVE_FCHOWNAT@ || @REPLACE_FCHOWNAT@
322 extern int fchownat (int fd, char const *file, uid_t owner, gid_t group, int flag)
323      _GL_ARG_NONNULL ((2));
324 # endif
325 #elif defined GNULIB_POSIXCHECK
326 # undef fchownat
327 # define fchownat(d,n,o,g,f)                        \
328     (GL_LINK_WARNING ("fchownat is not portable - " \
329                       "use gnulib module openat for portability"), \
330      fchownat (d, n, o, g, f))
331 #endif
332
333
334 #if @GNULIB_FSYNC@
335 /* Synchronize changes to a file.
336    Return 0 if successful, otherwise -1 and errno set.
337    See POSIX:2001 specification
338    <http://www.opengroup.org/susv3xsh/fsync.html>.  */
339 # if !@HAVE_FSYNC@
340 extern int fsync (int fd);
341 # endif
342 #elif defined GNULIB_POSIXCHECK
343 # undef fsync
344 # define fsync(fd) \
345     (GL_LINK_WARNING ("fsync is unportable - " \
346                       "use gnulib module fsync for portability"), \
347      fsync (fd))
348 #endif
349
350
351 #if @GNULIB_FTRUNCATE@
352 # if !@HAVE_FTRUNCATE@
353 /* Change the size of the file to which FD is opened to become equal to LENGTH.
354    Return 0 if successful, otherwise -1 and errno set.
355    See the POSIX:2001 specification
356    <http://www.opengroup.org/susv3xsh/ftruncate.html>.  */
357 extern int ftruncate (int fd, off_t length);
358 # endif
359 #elif defined GNULIB_POSIXCHECK
360 # undef ftruncate
361 # define ftruncate(f,l) \
362     (GL_LINK_WARNING ("ftruncate is unportable - " \
363                       "use gnulib module ftruncate for portability"), \
364      ftruncate (f, l))
365 #endif
366
367
368 #if @GNULIB_GETCWD@
369 # if @REPLACE_GETCWD@
370 /* Get the name of the current working directory, and put it in SIZE bytes
371    of BUF.
372    Return BUF if successful, or NULL if the directory couldn't be determined
373    or SIZE was too small.
374    See the POSIX:2001 specification
375    <http://www.opengroup.org/susv3xsh/getcwd.html>.
376    Additionally, the gnulib module 'getcwd' guarantees the following GNU
377    extension: If BUF is NULL, an array is allocated with 'malloc'; the array
378    is SIZE bytes long, unless SIZE == 0, in which case it is as big as
379    necessary.  */
380 #  define getcwd rpl_getcwd
381 extern char * getcwd (char *buf, size_t size);
382 # endif
383 #elif defined GNULIB_POSIXCHECK
384 # undef getcwd
385 # define getcwd(b,s) \
386     (GL_LINK_WARNING ("getcwd is unportable - " \
387                       "use gnulib module getcwd for portability"), \
388      getcwd (b, s))
389 #endif
390
391
392 #if @GNULIB_GETDOMAINNAME@
393 /* Return the NIS domain name of the machine.
394    WARNING! The NIS domain name is unrelated to the fully qualified host name
395             of the machine.  It is also unrelated to email addresses.
396    WARNING! The NIS domain name is usually the empty string or "(none)" when
397             not using NIS.
398
399    Put up to LEN bytes of the NIS domain name into NAME.
400    Null terminate it if the name is shorter than LEN.
401    If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
402    Return 0 if successful, otherwise set errno and return -1.  */
403 # if !@HAVE_GETDOMAINNAME@
404 extern int getdomainname(char *name, size_t len) _GL_ARG_NONNULL ((1));
405 # endif
406 #elif defined GNULIB_POSIXCHECK
407 # undef getdomainname
408 # define getdomainname(n,l) \
409     (GL_LINK_WARNING ("getdomainname is unportable - " \
410                       "use gnulib module getdomainname for portability"), \
411      getdomainname (n, l))
412 #endif
413
414
415 #if @GNULIB_GETDTABLESIZE@
416 # if !@HAVE_GETDTABLESIZE@
417 /* Return the maximum number of file descriptors in the current process.
418    In POSIX, this is same as sysconf (_SC_OPEN_MAX).  */
419 extern int getdtablesize (void);
420 # endif
421 #elif defined GNULIB_POSIXCHECK
422 # undef getdtablesize
423 # define getdtablesize() \
424     (GL_LINK_WARNING ("getdtablesize is unportable - " \
425                       "use gnulib module getdtablesize for portability"), \
426      getdtablesize ())
427 #endif
428
429
430 #if @GNULIB_GETGROUPS@
431 # if @REPLACE_GETGROUPS@
432 #  undef getgroups
433 #  define getgroups rpl_getgroups
434 # endif
435 # if !@HAVE_GETGROUPS@ || @REPLACE_GETGROUPS@
436 /* Return the supplemental groups that the current process belongs to.
437    It is unspecified whether the effective group id is in the list.
438    If N is 0, return the group count; otherwise, N describes how many
439    entries are available in GROUPS.  Return -1 and set errno if N is
440    not 0 and not large enough.  Fails with ENOSYS on some systems.  */
441 int getgroups (int n, gid_t *groups);
442 # endif
443 #elif defined GNULIB_POSIXCHECK
444 # undef getgroups
445 # define getgroups(n,g)                                                 \
446     (GL_LINK_WARNING ("getgroups is unportable - "                      \
447                       "use gnulib module getgroups for portability"),   \
448      getgroups (n, g))
449 #endif
450
451
452 #if @GNULIB_GETHOSTNAME@
453 /* Return the standard host name of the machine.
454    WARNING! The host name may or may not be fully qualified.
455
456    Put up to LEN bytes of the host name into NAME.
457    Null terminate it if the name is shorter than LEN.
458    If the host name is longer than LEN, set errno = EINVAL and return -1.
459    Return 0 if successful, otherwise set errno and return -1.  */
460 # if @UNISTD_H_HAVE_WINSOCK2_H@
461 #  undef gethostname
462 #  define gethostname rpl_gethostname
463 # endif
464 # if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@
465 extern int gethostname(char *name, size_t len) _GL_ARG_NONNULL ((1));
466 # endif
467 #elif @UNISTD_H_HAVE_WINSOCK2_H@
468 # undef gethostname
469 # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
470 #elif defined GNULIB_POSIXCHECK
471 # undef gethostname
472 # define gethostname(n,l) \
473     (GL_LINK_WARNING ("gethostname is unportable - " \
474                       "use gnulib module gethostname for portability"), \
475      gethostname (n, l))
476 #endif
477
478
479 #if @GNULIB_GETLOGIN_R@
480 /* Copies the user's login name to NAME.
481    The array pointed to by NAME has room for SIZE bytes.
482
483    Returns 0 if successful.  Upon error, an error number is returned, or -1 in
484    the case that the login name cannot be found but no specific error is
485    provided (this case is hopefully rare but is left open by the POSIX spec).
486
487    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
488  */
489 # if !@HAVE_DECL_GETLOGIN_R@
490 extern int getlogin_r (char *name, size_t size) _GL_ARG_NONNULL ((1));
491 # endif
492 #elif defined GNULIB_POSIXCHECK
493 # undef getlogin_r
494 # define getlogin_r(n,s) \
495     (GL_LINK_WARNING ("getlogin_r is unportable - " \
496                       "use gnulib module getlogin_r for portability"), \
497      getlogin_r (n, s))
498 #endif
499
500
501 #if @GNULIB_GETPAGESIZE@
502 # if @REPLACE_GETPAGESIZE@
503 #  define getpagesize rpl_getpagesize
504 extern int getpagesize (void);
505 # elif !@HAVE_GETPAGESIZE@
506 /* This is for POSIX systems.  */
507 #  if !defined getpagesize && defined _SC_PAGESIZE
508 #   if ! (defined __VMS && __VMS_VER < 70000000)
509 #    define getpagesize() sysconf (_SC_PAGESIZE)
510 #   endif
511 #  endif
512 /* This is for older VMS.  */
513 #  if !defined getpagesize && defined __VMS
514 #   ifdef __ALPHA
515 #    define getpagesize() 8192
516 #   else
517 #    define getpagesize() 512
518 #   endif
519 #  endif
520 /* This is for BeOS.  */
521 #  if !defined getpagesize && @HAVE_OS_H@
522 #   include <OS.h>
523 #   if defined B_PAGE_SIZE
524 #    define getpagesize() B_PAGE_SIZE
525 #   endif
526 #  endif
527 /* This is for AmigaOS4.0.  */
528 #  if !defined getpagesize && defined __amigaos4__
529 #   define getpagesize() 2048
530 #  endif
531 /* This is for older Unix systems.  */
532 #  if !defined getpagesize && @HAVE_SYS_PARAM_H@
533 #   include <sys/param.h>
534 #   ifdef EXEC_PAGESIZE
535 #    define getpagesize() EXEC_PAGESIZE
536 #   else
537 #    ifdef NBPG
538 #     ifndef CLSIZE
539 #      define CLSIZE 1
540 #     endif
541 #     define getpagesize() (NBPG * CLSIZE)
542 #    else
543 #     ifdef NBPC
544 #      define getpagesize() NBPC
545 #     endif
546 #    endif
547 #   endif
548 #  endif
549 # endif
550 #elif defined GNULIB_POSIXCHECK
551 # undef getpagesize
552 # define getpagesize() \
553     (GL_LINK_WARNING ("getpagesize is unportable - " \
554                       "use gnulib module getpagesize for portability"), \
555      getpagesize ())
556 #endif
557
558
559 #if @GNULIB_GETUSERSHELL@
560 # if !@HAVE_GETUSERSHELL@
561 /* Return the next valid login shell on the system, or NULL when the end of
562    the list has been reached.  */
563 extern char *getusershell (void);
564 /* Rewind to pointer that is advanced at each getusershell() call.  */
565 extern void setusershell (void);
566 /* Free the pointer that is advanced at each getusershell() call and
567    associated resources.  */
568 extern void endusershell (void);
569 # endif
570 #elif defined GNULIB_POSIXCHECK
571 # undef getusershell
572 # define getusershell() \
573     (GL_LINK_WARNING ("getusershell is unportable - " \
574                       "use gnulib module getusershell for portability"), \
575      getusershell ())
576 # undef setusershell
577 # define setusershell() \
578     (GL_LINK_WARNING ("setusershell is unportable - " \
579                       "use gnulib module getusershell for portability"), \
580      setusershell ())
581 # undef endusershell
582 # define endusershell() \
583     (GL_LINK_WARNING ("endusershell is unportable - " \
584                       "use gnulib module getusershell for portability"), \
585      endusershell ())
586 #endif
587
588
589 #if @GNULIB_LCHOWN@
590 # if @REPLACE_LCHOWN@
591 #  undef lchown
592 #  define lchown rpl_lchown
593 # endif
594 # if !@HAVE_LCHOWN@ || @REPLACE_LCHOWN@
595 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
596    to GID (if GID is not -1).  Do not follow symbolic links.
597    Return 0 if successful, otherwise -1 and errno set.
598    See the POSIX:2001 specification
599    <http://www.opengroup.org/susv3xsh/lchown.html>.  */
600 extern int lchown (char const *file, uid_t owner, gid_t group)
601      _GL_ARG_NONNULL ((1));
602 # endif
603 #elif defined GNULIB_POSIXCHECK
604 # undef lchown
605 # define lchown(f,u,g) \
606     (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
607                       "systems - use gnulib module lchown for portability"), \
608      lchown (f, u, g))
609 #endif
610
611
612 #if @GNULIB_LINK@
613 # if @REPLACE_LINK@
614 #  define link rpl_link
615 # endif
616 /* Create a new hard link for an existing file.
617    Return 0 if successful, otherwise -1 and errno set.
618    See POSIX:2001 specification
619    <http://www.opengroup.org/susv3xsh/link.html>.  */
620 # if !@HAVE_LINK@ || @REPLACE_LINK@
621 extern int link (const char *path1, const char *path2)
622      _GL_ARG_NONNULL ((1, 2));
623 # endif
624 #elif defined GNULIB_POSIXCHECK
625 # undef link
626 # define link(path1,path2) \
627     (GL_LINK_WARNING ("link is unportable - " \
628                       "use gnulib module link for portability"), \
629      link (path1, path2))
630 #endif
631
632 #if @GNULIB_LINKAT@
633 # if @REPLACE_LINKAT@
634 #  undef linkat
635 #  define linkat rpl_linkat
636 # endif
637 /* Create a new hard link for an existing file, relative to two
638    directories.  FLAG controls whether symlinks are followed.
639    Return 0 if successful, otherwise -1 and errno set.  */
640 # if !@HAVE_LINKAT@ || @REPLACE_LINKAT@
641 extern int linkat (int fd1, const char *path1, int fd2, const char *path2,
642                    int flag)
643      _GL_ARG_NONNULL ((2, 4));
644 # endif
645 #elif defined GNULIB_POSIXCHECK
646 # undef linkat
647 # define linkat(f1,path1,f2,path2,f)              \
648     (GL_LINK_WARNING ("linkat is unportable - " \
649                       "use gnulib module linkat for portability"), \
650      linkat (f1, path1, f2, path2,f))
651 #endif
652
653 #if @GNULIB_LSEEK@
654 # if @REPLACE_LSEEK@
655 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
656    Return the new offset if successful, otherwise -1 and errno set.
657    See the POSIX:2001 specification
658    <http://www.opengroup.org/susv3xsh/lseek.html>.  */
659 #  define lseek rpl_lseek
660    extern off_t lseek (int fd, off_t offset, int whence);
661 # endif
662 #elif defined GNULIB_POSIXCHECK
663 # undef lseek
664 # define lseek(f,o,w) \
665     (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
666                       "systems - use gnulib module lseek for portability"), \
667      lseek (f, o, w))
668 #endif
669
670
671 #if @GNULIB_PIPE2@
672 /* Create a pipe, applying the given flags when opening the read-end of the
673    pipe and the write-end of the pipe.
674    The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
675    and O_TEXT, O_BINARY (defined in "binary-io.h").
676    Store the read-end as fd[0] and the write-end as fd[1].
677    Return 0 upon success, or -1 with errno set upon failure.
678    See also the Linux man page at
679    <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>.  */
680 # if @HAVE_PIPE2@
681 #  define pipe2 rpl_pipe2
682 # endif
683 extern int pipe2 (int fd[2], int flags) _GL_ARG_NONNULL ((1));
684 #elif defined GNULIB_POSIXCHECK
685 # undef pipe2
686 # define pipe2(f,o) \
687     (GL_LINK_WARNING ("pipe2 is unportable - " \
688                       "use gnulib module pipe2 for portability"), \
689      pipe2 (f, o))
690 #endif
691
692
693 #if @GNULIB_PREAD@
694 # if @REPLACE_PREAD@
695 #  define pread rpl_pread
696 # endif
697 /* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
698    Return the number of bytes placed into BUF if successful, otherwise
699    set errno and return -1.  0 indicates EOF.  See the POSIX:2001
700    specification <http://www.opengroup.org/susv3xsh/pread.html>.  */
701 # if !@HAVE_PREAD@ || @REPLACE_PREAD@
702   extern ssize_t pread (int fd, void *buf, size_t bufsize, off_t offset)
703        _GL_ARG_NONNULL ((2));
704 # endif
705 #elif defined GNULIB_POSIXCHECK
706 # undef pread
707 # define pread(f,b,s,o)                        \
708     (GL_LINK_WARNING ("pread is unportable - " \
709                       "use gnulib module pread for portability"), \
710      pread (f, b, s, o))
711 #endif
712
713
714 #if @GNULIB_READLINK@
715 # if @REPLACE_READLINK@
716 #  define readlink rpl_readlink
717 # endif
718 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
719    bytes of it into BUF.  Return the number of bytes placed into BUF if
720    successful, otherwise -1 and errno set.
721    See the POSIX:2001 specification
722    <http://www.opengroup.org/susv3xsh/readlink.html>.  */
723 # if !@HAVE_READLINK@ || @REPLACE_READLINK@
724 extern ssize_t readlink (const char *file, char *buf, size_t bufsize)
725      _GL_ARG_NONNULL ((1, 2));
726 # endif
727 #elif defined GNULIB_POSIXCHECK
728 # undef readlink
729 # define readlink(f,b,s) \
730     (GL_LINK_WARNING ("readlink is unportable - " \
731                       "use gnulib module readlink for portability"), \
732      readlink (f, b, s))
733 #endif
734
735
736 #if @GNULIB_READLINKAT@
737 # if !@HAVE_READLINKAT@
738 extern ssize_t readlinkat (int fd, char const *file, char *buf, size_t len)
739      _GL_ARG_NONNULL ((2, 3));
740 # endif
741 #elif defined GNULIB_POSIXCHECK
742 # undef readlinkat
743 # define readlinkat(d,n,b,l)                         \
744     (GL_LINK_WARNING ("readlinkat is not portable - " \
745                       "use gnulib module symlinkat for portability"), \
746      readlinkat (d, n, b, l))
747 #endif
748
749
750 #if @GNULIB_RMDIR@
751 # if @REPLACE_RMDIR@
752 #  define rmdir rpl_rmdir
753 /* Remove the directory DIR.  */
754 extern int rmdir (char const *name) _GL_ARG_NONNULL ((1));
755 # endif
756 #elif defined GNULIB_POSIXCHECK
757 # undef rmdir
758 # define rmdir(n) \
759     (GL_LINK_WARNING ("rmdir is unportable - " \
760                       "use gnulib module rmdir for portability"), \
761      rmdir (n))
762 #endif
763
764
765 #if @GNULIB_SLEEP@
766 # if @REPLACE_SLEEP@
767 #  undef sleep
768 #  define sleep rpl_sleep
769 # endif
770 /* Pause the execution of the current thread for N seconds.
771    Returns the number of seconds left to sleep.
772    See the POSIX:2001 specification
773    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
774 # if !@HAVE_SLEEP@ || @REPLACE_SLEEP@
775 extern unsigned int sleep (unsigned int n);
776 # endif
777 #elif defined GNULIB_POSIXCHECK
778 # undef sleep
779 # define sleep(n) \
780     (GL_LINK_WARNING ("sleep is unportable - " \
781                       "use gnulib module sleep for portability"), \
782      sleep (n))
783 #endif
784
785
786 #if @GNULIB_SYMLINK@
787 # if @REPLACE_SYMLINK@
788 #  undef symlink
789 #  define symlink rpl_symlink
790 # endif
791 # if !@HAVE_SYMLINK@ || @REPLACE_SYMLINK@
792 extern int symlink (char const *contents, char const *file)
793      _GL_ARG_NONNULL ((1, 2));
794 # endif
795 #elif defined GNULIB_POSIXCHECK
796 # undef symlink
797 # define symlink(c,n)                        \
798     (GL_LINK_WARNING ("symlink is not portable - " \
799                       "use gnulib module symlink for portability"), \
800      symlink (c, n))
801 #endif
802
803
804 #if @GNULIB_SYMLINKAT@
805 # if !@HAVE_SYMLINKAT@
806 extern int symlinkat (char const *contents, int fd, char const *file)
807      _GL_ARG_NONNULL ((1, 3));
808 # endif
809 #elif defined GNULIB_POSIXCHECK
810 # undef symlinkat
811 # define symlinkat(c,d,n)                            \
812     (GL_LINK_WARNING ("symlinkat is not portable - " \
813                       "use gnulib module symlinkat for portability"), \
814      symlinkat (c, d, n))
815 #endif
816
817
818 #if @GNULIB_UNLINK@
819 # if @REPLACE_UNLINK@
820 #  undef unlink
821 #  define unlink rpl_unlink
822 extern int unlink (char const *file) _GL_ARG_NONNULL ((1));
823 # endif
824 #elif defined GNULIB_POSIXCHECK
825 # undef unlink
826 # define unlink(n)                         \
827     (GL_LINK_WARNING ("unlink is not portable - " \
828                       "use gnulib module unlink for portability"), \
829      unlink (n))
830 #endif
831
832
833 #if @GNULIB_UNLINKAT@
834 # if @REPLACE_UNLINKAT@
835 #  undef unlinkat
836 #  define unlinkat rpl_unlinkat
837 # endif
838 # if !@HAVE_UNLINKAT@ || @REPLACE_UNLINKAT@
839 extern int unlinkat (int fd, char const *file, int flag) _GL_ARG_NONNULL ((2));
840 # endif
841 #elif defined GNULIB_POSIXCHECK
842 # undef unlinkat
843 # define unlinkat(d,n,f)                         \
844     (GL_LINK_WARNING ("unlinkat is not portable - " \
845                       "use gnulib module openat for portability"), \
846      unlinkat (d, n, f))
847 #endif
848
849
850 #if @GNULIB_USLEEP@
851 # if @REPLACE_USLEEP@
852 #  undef usleep
853 #  define usleep rpl_usleep
854 # endif
855 # if !@HAVE_USLEEP@ || @REPLACE_USLEEP@
856 /* Pause the execution of the current thread for N microseconds.
857    Returns 0 on completion, or -1 on range error.
858    See the POSIX:2001 specification
859    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
860 extern int usleep (useconds_t n);
861 # endif
862 #elif defined GNULIB_POSIXCHECK
863 # undef usleep
864 # define usleep(n) \
865     (GL_LINK_WARNING ("usleep is unportable - " \
866                       "use gnulib module usleep for portability"), \
867      usleep (n))
868 #endif
869
870
871 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
872 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
873    See the POSIX:2001 specification
874    <http://www.opengroup.org/susv3xsh/write.html>.  */
875 # undef write
876 # define write rpl_write
877 extern ssize_t write (int fd, const void *buf, size_t count)
878      _GL_ARG_NONNULL ((2));
879 #endif
880
881
882 #ifdef __cplusplus
883 }
884 #endif
885
886
887 #endif /* _GL_UNISTD_H */
888 #endif /* _GL_UNISTD_H */