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