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