d8276b1e1885fbb36a5e45d382963ff341ba91c4
[debian/amanda] / gnulib / unistd.in.h
1 /* Substitute for and wrapper around <unistd.h>.
2    Copyright (C) 2003-2009 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 /* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>.  */
33 #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
34 # include <stdio.h>
35 #endif
36
37 /* mingw fails to declare _exit in <unistd.h>.  */
38 /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>.  */
39 #include <stdlib.h>
40
41 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
42 /* Get ssize_t.  */
43 # include <sys/types.h>
44 #endif
45
46 #if @GNULIB_GETHOSTNAME@
47 /* Get all possible declarations of gethostname().  */
48 # if @UNISTD_H_HAVE_WINSOCK2_H@
49 #  include <winsock2.h>
50 #  if !defined _GL_SYS_SOCKET_H
51 #   undef socket
52 #   define socket               socket_used_without_including_sys_socket_h
53 #   undef connect
54 #   define connect              connect_used_without_including_sys_socket_h
55 #   undef accept
56 #   define accept               accept_used_without_including_sys_socket_h
57 #   undef bind
58 #   define bind                 bind_used_without_including_sys_socket_h
59 #   undef getpeername
60 #   define getpeername          getpeername_used_without_including_sys_socket_h
61 #   undef getsockname
62 #   define getsockname          getsockname_used_without_including_sys_socket_h
63 #   undef getsockopt
64 #   define getsockopt           getsockopt_used_without_including_sys_socket_h
65 #   undef listen
66 #   define listen               listen_used_without_including_sys_socket_h
67 #   undef recv
68 #   define recv                 recv_used_without_including_sys_socket_h
69 #   undef send
70 #   define send                 send_used_without_including_sys_socket_h
71 #   undef recvfrom
72 #   define recvfrom             recvfrom_used_without_including_sys_socket_h
73 #   undef sendto
74 #   define sendto               sendto_used_without_including_sys_socket_h
75 #   undef setsockopt
76 #   define setsockopt           setsockopt_used_without_including_sys_socket_h
77 #   undef shutdown
78 #   define shutdown             shutdown_used_without_including_sys_socket_h
79 #  endif
80 #  if !defined _GL_SYS_SELECT_H
81 #   undef select
82 #   define select               select_used_without_including_sys_select_h
83 #  endif
84 # endif
85 #endif
86
87 /* The definition of GL_LINK_WARNING is copied here.  */
88
89
90 /* OS/2 EMX lacks these macros.  */
91 #ifndef STDIN_FILENO
92 # define STDIN_FILENO 0
93 #endif
94 #ifndef STDOUT_FILENO
95 # define STDOUT_FILENO 1
96 #endif
97 #ifndef STDERR_FILENO
98 # define STDERR_FILENO 2
99 #endif
100
101 /* Declare overridden functions.  */
102
103 #ifdef __cplusplus
104 extern "C" {
105 #endif
106
107
108 #if @GNULIB_CHOWN@
109 # if @REPLACE_CHOWN@
110 #  ifndef REPLACE_CHOWN
111 #   define REPLACE_CHOWN 1
112 #  endif
113 #  if REPLACE_CHOWN
114 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
115    to GID (if GID is not -1).  Follow symbolic links.
116    Return 0 if successful, otherwise -1 and errno set.
117    See the POSIX:2001 specification
118    <http://www.opengroup.org/susv3xsh/chown.html>.  */
119 #   define chown rpl_chown
120 extern int chown (const char *file, uid_t uid, gid_t gid);
121 #  endif
122 # endif
123 #elif defined GNULIB_POSIXCHECK
124 # undef chown
125 # define chown(f,u,g) \
126     (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
127                       "doesn't treat a uid or gid of -1 on some systems - " \
128                       "use gnulib module chown for portability"), \
129      chown (f, u, g))
130 #endif
131
132
133 #if @GNULIB_CLOSE@
134 # if @UNISTD_H_HAVE_WINSOCK2_H@
135 /* Need a gnulib internal function.  */
136 #  define HAVE__GL_CLOSE_FD_MAYBE_SOCKET 1
137 # endif
138 # if @REPLACE_CLOSE@
139 /* Automatically included by modules that need a replacement for close.  */
140 #  undef close
141 #  define close rpl_close
142 extern int close (int);
143 # endif
144 #elif @UNISTD_H_HAVE_WINSOCK2_H@
145 # undef close
146 # define close close_used_without_requesting_gnulib_module_close
147 #elif defined GNULIB_POSIXCHECK
148 # undef close
149 # define close(f) \
150     (GL_LINK_WARNING ("close does not portably work on sockets - " \
151                       "use gnulib module close for portability"), \
152      close (f))
153 #endif
154
155
156 #if @GNULIB_DUP2@
157 # if !@HAVE_DUP2@
158 /* Copy the file descriptor OLDFD into file descriptor NEWFD.  Do nothing if
159    NEWFD = OLDFD, otherwise close NEWFD first if it is open.
160    Return 0 if successful, otherwise -1 and errno set.
161    See the POSIX:2001 specification
162    <http://www.opengroup.org/susv3xsh/dup2.html>.  */
163 extern int dup2 (int oldfd, int newfd);
164 # endif
165 #elif defined GNULIB_POSIXCHECK
166 # undef dup2
167 # define dup2(o,n) \
168     (GL_LINK_WARNING ("dup2 is unportable - " \
169                       "use gnulib module dup2 for portability"), \
170      dup2 (o, n))
171 #endif
172
173
174 #if @GNULIB_ENVIRON@
175 # if !@HAVE_DECL_ENVIRON@
176 /* Set of environment variables and values.  An array of strings of the form
177    "VARIABLE=VALUE", terminated with a NULL.  */
178 #  if defined __APPLE__ && defined __MACH__
179 #   include <crt_externs.h>
180 #   define environ (*_NSGetEnviron ())
181 #  else
182 extern char **environ;
183 #  endif
184 # endif
185 #elif defined GNULIB_POSIXCHECK
186 # undef environ
187 # define environ \
188     (GL_LINK_WARNING ("environ is unportable - " \
189                       "use gnulib module environ for portability"), \
190      environ)
191 #endif
192
193
194 #if @GNULIB_EUIDACCESS@
195 # if !@HAVE_EUIDACCESS@
196 /* Like access(), except that is uses the effective user id and group id of
197    the current process.  */
198 extern int euidaccess (const char *filename, int mode);
199 # endif
200 #elif defined GNULIB_POSIXCHECK
201 # undef euidaccess
202 # define euidaccess(f,m) \
203     (GL_LINK_WARNING ("euidaccess is unportable - " \
204                       "use gnulib module euidaccess for portability"), \
205      euidaccess (f, m))
206 #endif
207
208
209 #if @GNULIB_FCHDIR@
210 # if @REPLACE_FCHDIR@
211
212 /* Change the process' current working directory to the directory on which
213    the given file descriptor is open.
214    Return 0 if successful, otherwise -1 and errno set.
215    See the POSIX:2001 specification
216    <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
217 extern int fchdir (int /*fd*/);
218
219 #  define dup rpl_dup
220 extern int dup (int);
221 #  define dup2 rpl_dup2
222 extern int dup2 (int, int);
223
224 # endif
225 #elif defined GNULIB_POSIXCHECK
226 # undef fchdir
227 # define fchdir(f) \
228     (GL_LINK_WARNING ("fchdir is unportable - " \
229                       "use gnulib module fchdir for portability"), \
230      fchdir (f))
231 #endif
232
233
234 #if @GNULIB_FSYNC@
235 /* Synchronize changes to a file.
236    Return 0 if successful, otherwise -1 and errno set.
237    See POSIX:2001 specification
238    <http://www.opengroup.org/susv3xsh/fsync.html>.  */
239 # if !@HAVE_FSYNC@
240 extern int fsync (int fd);
241 # endif
242 #elif defined GNULIB_POSIXCHECK
243 # undef fsync
244 # define fsync(fd) \
245     (GL_LINK_WARNING ("fsync is unportable - " \
246                       "use gnulib module fsync for portability"), \
247      fsync (fd))
248 #endif
249
250
251 #if @GNULIB_FTRUNCATE@
252 # if !@HAVE_FTRUNCATE@
253 /* Change the size of the file to which FD is opened to become equal to LENGTH.
254    Return 0 if successful, otherwise -1 and errno set.
255    See the POSIX:2001 specification
256    <http://www.opengroup.org/susv3xsh/ftruncate.html>.  */
257 extern int ftruncate (int fd, off_t length);
258 # endif
259 #elif defined GNULIB_POSIXCHECK
260 # undef ftruncate
261 # define ftruncate(f,l) \
262     (GL_LINK_WARNING ("ftruncate is unportable - " \
263                       "use gnulib module ftruncate for portability"), \
264      ftruncate (f, l))
265 #endif
266
267
268 #if @GNULIB_GETCWD@
269 /* Include the headers that might declare getcwd so that they will not
270    cause confusion if included after this file.  */
271 # include <stdlib.h>
272 # if @REPLACE_GETCWD@
273 /* Get the name of the current working directory, and put it in SIZE bytes
274    of BUF.
275    Return BUF if successful, or NULL if the directory couldn't be determined
276    or SIZE was too small.
277    See the POSIX:2001 specification
278    <http://www.opengroup.org/susv3xsh/getcwd.html>.
279    Additionally, the gnulib module 'getcwd' guarantees the following GNU
280    extension: If BUF is NULL, an array is allocated with 'malloc'; the array
281    is SIZE bytes long, unless SIZE == 0, in which case it is as big as
282    necessary.  */
283 #  define getcwd rpl_getcwd
284 extern char * getcwd (char *buf, size_t size);
285 # endif
286 #elif defined GNULIB_POSIXCHECK
287 # undef getcwd
288 # define getcwd(b,s) \
289     (GL_LINK_WARNING ("getcwd is unportable - " \
290                       "use gnulib module getcwd for portability"), \
291      getcwd (b, s))
292 #endif
293
294
295 #if @GNULIB_GETDOMAINNAME@
296 /* Return the NIS domain name of the machine.
297    WARNING! The NIS domain name is unrelated to the fully qualified host name
298             of the machine.  It is also unrelated to email addresses.
299    WARNING! The NIS domain name is usually the empty string or "(none)" when
300             not using NIS.
301
302    Put up to LEN bytes of the NIS domain name into NAME.
303    Null terminate it if the name is shorter than LEN.
304    If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
305    Return 0 if successful, otherwise set errno and return -1.  */
306 # if !@HAVE_GETDOMAINNAME@
307 extern int getdomainname(char *name, size_t len);
308 # endif
309 #elif defined GNULIB_POSIXCHECK
310 # undef getdomainname
311 # define getdomainname(n,l) \
312     (GL_LINK_WARNING ("getdomainname is unportable - " \
313                       "use gnulib module getdomainname for portability"), \
314      getdomainname (n, l))
315 #endif
316
317
318 #if @GNULIB_GETDTABLESIZE@
319 # if !@HAVE_GETDTABLESIZE@
320 /* Return the maximum number of file descriptors in the current process.  */
321 extern int getdtablesize (void);
322 # endif
323 #elif defined GNULIB_POSIXCHECK
324 # undef getdtablesize
325 # define getdtablesize() \
326     (GL_LINK_WARNING ("getdtablesize is unportable - " \
327                       "use gnulib module getdtablesize for portability"), \
328      getdtablesize ())
329 #endif
330
331
332 #if @GNULIB_GETHOSTNAME@
333 /* Return the standard host name of the machine.
334    WARNING! The host name may or may not be fully qualified.
335
336    Put up to LEN bytes of the host name into NAME.
337    Null terminate it if the name is shorter than LEN.
338    If the host name is longer than LEN, set errno = EINVAL and return -1.
339    Return 0 if successful, otherwise set errno and return -1.  */
340 # if @UNISTD_H_HAVE_WINSOCK2_H@
341 #  undef gethostname
342 #  define gethostname rpl_gethostname
343 # endif
344 # if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@
345 extern int gethostname(char *name, size_t len);
346 # endif
347 #elif @UNISTD_H_HAVE_WINSOCK2_H@
348 # undef gethostname
349 # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
350 #elif defined GNULIB_POSIXCHECK
351 # undef gethostname
352 # define gethostname(n,l) \
353     (GL_LINK_WARNING ("gethostname is unportable - " \
354                       "use gnulib module gethostname for portability"), \
355      gethostname (n, l))
356 #endif
357
358
359 #if @GNULIB_GETLOGIN_R@
360 /* Copies the user's login name to NAME.
361    The array pointed to by NAME has room for SIZE bytes.
362
363    Returns 0 if successful.  Upon error, an error number is returned, or -1 in
364    the case that the login name cannot be found but no specific error is
365    provided (this case is hopefully rare but is left open by the POSIX spec).
366
367    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
368  */
369 # if !@HAVE_DECL_GETLOGIN_R@
370 #  include <stddef.h>
371 extern int getlogin_r (char *name, size_t size);
372 # endif
373 #elif defined GNULIB_POSIXCHECK
374 # undef getlogin_r
375 # define getlogin_r(n,s) \
376     (GL_LINK_WARNING ("getlogin_r is unportable - " \
377                       "use gnulib module getlogin_r for portability"), \
378      getlogin_r (n, s))
379 #endif
380
381
382 #if @GNULIB_GETPAGESIZE@
383 # if @REPLACE_GETPAGESIZE@
384 #  define getpagesize rpl_getpagesize
385 extern int getpagesize (void);
386 # elif !@HAVE_GETPAGESIZE@
387 /* This is for POSIX systems.  */
388 #  if !defined getpagesize && defined _SC_PAGESIZE
389 #   if ! (defined __VMS && __VMS_VER < 70000000)
390 #    define getpagesize() sysconf (_SC_PAGESIZE)
391 #   endif
392 #  endif
393 /* This is for older VMS.  */
394 #  if !defined getpagesize && defined __VMS
395 #   ifdef __ALPHA
396 #    define getpagesize() 8192
397 #   else
398 #    define getpagesize() 512
399 #   endif
400 #  endif
401 /* This is for BeOS.  */
402 #  if !defined getpagesize && @HAVE_OS_H@
403 #   include <OS.h>
404 #   if defined B_PAGE_SIZE
405 #    define getpagesize() B_PAGE_SIZE
406 #   endif
407 #  endif
408 /* This is for AmigaOS4.0.  */
409 #  if !defined getpagesize && defined __amigaos4__
410 #   define getpagesize() 2048
411 #  endif
412 /* This is for older Unix systems.  */
413 #  if !defined getpagesize && @HAVE_SYS_PARAM_H@
414 #   include <sys/param.h>
415 #   ifdef EXEC_PAGESIZE
416 #    define getpagesize() EXEC_PAGESIZE
417 #   else
418 #    ifdef NBPG
419 #     ifndef CLSIZE
420 #      define CLSIZE 1
421 #     endif
422 #     define getpagesize() (NBPG * CLSIZE)
423 #    else
424 #     ifdef NBPC
425 #      define getpagesize() NBPC
426 #     endif
427 #    endif
428 #   endif
429 #  endif
430 # endif
431 #elif defined GNULIB_POSIXCHECK
432 # undef getpagesize
433 # define getpagesize() \
434     (GL_LINK_WARNING ("getpagesize is unportable - " \
435                       "use gnulib module getpagesize for portability"), \
436      getpagesize ())
437 #endif
438
439
440 #if @GNULIB_GETUSERSHELL@
441 # if !@HAVE_GETUSERSHELL@
442 /* Return the next valid login shell on the system, or NULL when the end of
443    the list has been reached.  */
444 extern char *getusershell (void);
445 /* Rewind to pointer that is advanced at each getusershell() call.  */
446 extern void setusershell (void);
447 /* Free the pointer that is advanced at each getusershell() call and
448    associated resources.  */
449 extern void endusershell (void);
450 # endif
451 #elif defined GNULIB_POSIXCHECK
452 # undef getusershell
453 # define getusershell() \
454     (GL_LINK_WARNING ("getusershell is unportable - " \
455                       "use gnulib module getusershell for portability"), \
456      getusershell ())
457 # undef setusershell
458 # define setusershell() \
459     (GL_LINK_WARNING ("setusershell is unportable - " \
460                       "use gnulib module getusershell for portability"), \
461      setusershell ())
462 # undef endusershell
463 # define endusershell() \
464     (GL_LINK_WARNING ("endusershell is unportable - " \
465                       "use gnulib module getusershell for portability"), \
466      endusershell ())
467 #endif
468
469
470 #if @GNULIB_LCHOWN@
471 # if @REPLACE_LCHOWN@
472 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
473    to GID (if GID is not -1).  Do not follow symbolic links.
474    Return 0 if successful, otherwise -1 and errno set.
475    See the POSIX:2001 specification
476    <http://www.opengroup.org/susv3xsh/lchown.html>.  */
477 #  define lchown rpl_lchown
478 extern int lchown (char const *file, uid_t owner, gid_t group);
479 # endif
480 #elif defined GNULIB_POSIXCHECK
481 # undef lchown
482 # define lchown(f,u,g) \
483     (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
484                       "systems - use gnulib module lchown for portability"), \
485      lchown (f, u, g))
486 #endif
487
488
489 #if @GNULIB_LINK@
490 /* Create a new hard link for an existing file.
491    Return 0 if successful, otherwise -1 and errno set.
492    See POSIX:2001 specification
493    <http://www.opengroup.org/susv3xsh/link.html>.  */
494 # if !@HAVE_LINK@
495 extern int link (const char *path1, const char *path2);
496 # endif
497 #elif defined GNULIB_POSIXCHECK
498 # undef link
499 # define link(path1,path2) \
500     (GL_LINK_WARNING ("link is unportable - " \
501                       "use gnulib module link for portability"), \
502      link (path1, path2))
503 #endif
504
505
506 #if @GNULIB_LSEEK@
507 # if @REPLACE_LSEEK@
508 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
509    Return the new offset if successful, otherwise -1 and errno set.
510    See the POSIX:2001 specification
511    <http://www.opengroup.org/susv3xsh/lseek.html>.  */
512 #  define lseek rpl_lseek
513    extern off_t lseek (int fd, off_t offset, int whence);
514 # endif
515 #elif defined GNULIB_POSIXCHECK
516 # undef lseek
517 # define lseek(f,o,w) \
518     (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
519                       "systems - use gnulib module lseek for portability"), \
520      lseek (f, o, w))
521 #endif
522
523
524 #if @GNULIB_READLINK@
525 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
526    bytes of it into BUF.  Return the number of bytes placed into BUF if
527    successful, otherwise -1 and errno set.
528    See the POSIX:2001 specification
529    <http://www.opengroup.org/susv3xsh/readlink.html>.  */
530 # if !@HAVE_READLINK@
531 #  include <stddef.h>
532 extern int readlink (const char *file, char *buf, size_t bufsize);
533 # endif
534 #elif defined GNULIB_POSIXCHECK
535 # undef readlink
536 # define readlink(f,b,s) \
537     (GL_LINK_WARNING ("readlink is unportable - " \
538                       "use gnulib module readlink for portability"), \
539      readlink (f, b, s))
540 #endif
541
542
543 #if @GNULIB_SLEEP@
544 /* Pause the execution of the current thread for N seconds.
545    Returns the number of seconds left to sleep.
546    See the POSIX:2001 specification
547    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
548 # if !@HAVE_SLEEP@
549 extern unsigned int sleep (unsigned int n);
550 # endif
551 #elif defined GNULIB_POSIXCHECK
552 # undef sleep
553 # define sleep(n) \
554     (GL_LINK_WARNING ("sleep is unportable - " \
555                       "use gnulib module sleep for portability"), \
556      sleep (n))
557 #endif
558
559
560 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
561 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
562    See the POSIX:2001 specification
563    <http://www.opengroup.org/susv3xsh/write.html>.  */
564 # undef write
565 # define write rpl_write
566 extern ssize_t write (int fd, const void *buf, size_t count);
567 #endif
568
569
570 #ifdef FCHDIR_REPLACEMENT
571 /* gnulib internal function.  */
572 extern void _gl_unregister_fd (int fd);
573 #endif
574
575
576 #ifdef __cplusplus
577 }
578 #endif
579
580
581 #endif /* _GL_UNISTD_H */
582 #endif /* _GL_UNISTD_H */