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