New module 'close'.
[pspp] / lib / unistd.in.h
1 /* Substitute for and wrapper around <unistd.h>.
2    Copyright (C) 2004-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 @PRAGMA_SYSTEM_HEADER@
21
22 /* The include_next requires a split double-inclusion guard.  */
23 #if @HAVE_UNISTD_H@
24 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
25 #endif
26
27 #ifndef _GL_UNISTD_H
28 #define _GL_UNISTD_H
29
30 /* mingw doesn't define the SEEK_* macros in <unistd.h>.  */
31 #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
32 # include <stdio.h>
33 #endif
34
35 /* mingw fails to declare _exit in <unistd.h>.  */
36 #include <stdlib.h>
37
38 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
39 /* Get ssize_t.  */
40 # include <sys/types.h>
41 #endif
42
43 /* The definition of GL_LINK_WARNING is copied here.  */
44
45
46 /* Declare overridden functions.  */
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52
53 #if @GNULIB_CHOWN@
54 # if @REPLACE_CHOWN@
55 #  ifndef REPLACE_CHOWN
56 #   define REPLACE_CHOWN 1
57 #  endif
58 #  if REPLACE_CHOWN
59 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
60    to GID (if GID is not -1).  Follow symbolic links.
61    Return 0 if successful, otherwise -1 and errno set.
62    See the POSIX:2001 specification
63    <http://www.opengroup.org/susv3xsh/chown.html>.  */
64 #   define chown rpl_chown
65 extern int chown (const char *file, uid_t uid, gid_t gid);
66 #  endif
67 # endif
68 #elif defined GNULIB_POSIXCHECK
69 # undef chown
70 # define chown(f,u,g) \
71     (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
72                       "doesn't treat a uid or gid of -1 on some systems - " \
73                       "use gnulib module chown for portability"), \
74      chown (f, u, g))
75 #endif
76
77
78 #if @GNULIB_CLOSE@
79 # if @REPLACE_CLOSE@
80 /* Automatically included by modules that need a replacement for close.  */
81 #  undef close
82 #  define close rpl_close
83 extern int close (int);
84 # endif
85 #endif
86
87
88 #if @GNULIB_DUP2@
89 # if !@HAVE_DUP2@
90 /* Copy the file descriptor OLDFD into file descriptor NEWFD.  Do nothing if
91    NEWFD = OLDFD, otherwise close NEWFD first if it is open.
92    Return 0 if successful, otherwise -1 and errno set.
93    See the POSIX:2001 specification
94    <http://www.opengroup.org/susv3xsh/dup2.html>.  */
95 extern int dup2 (int oldfd, int newfd);
96 # endif
97 #elif defined GNULIB_POSIXCHECK
98 # undef dup2
99 # define dup2(o,n) \
100     (GL_LINK_WARNING ("dup2 is unportable - " \
101                       "use gnulib module dup2 for portability"), \
102      dup2 (o, n))
103 #endif
104
105
106 #if @GNULIB_ENVIRON@
107 # if !@HAVE_DECL_ENVIRON@
108 /* Set of environment variables and values.  An array of strings of the form
109    "VARIABLE=VALUE", terminated with a NULL.  */
110 #  if defined __APPLE__ && defined __MACH__
111 #   include <crt_externs.h>
112 #   define environ (*_NSGetEnviron ())
113 #  else
114 extern char **environ;
115 #  endif
116 # endif
117 #elif defined GNULIB_POSIXCHECK
118 # undef environ
119 # define environ \
120     (GL_LINK_WARNING ("environ is unportable - " \
121                       "use gnulib module environ for portability"), \
122      environ)
123 #endif
124
125
126 #if @GNULIB_FCHDIR@
127 # if @REPLACE_FCHDIR@
128
129 /* Change the process' current working directory to the directory on which
130    the given file descriptor is open.
131    Return 0 if successful, otherwise -1 and errno set.
132    See the POSIX:2001 specification
133    <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
134 extern int fchdir (int /*fd*/);
135
136 #  define dup rpl_dup
137 extern int dup (int);
138 #  define dup2 rpl_dup2
139 extern int dup2 (int, int);
140
141 # endif
142 #elif defined GNULIB_POSIXCHECK
143 # undef fchdir
144 # define fchdir(f) \
145     (GL_LINK_WARNING ("fchdir is unportable - " \
146                       "use gnulib module fchdir for portability"), \
147      fchdir (f))
148 #endif
149
150
151 #if @GNULIB_FSYNC@
152 /* Synchronize changes to a file.
153    Return 0 if successful, otherwise -1 and errno set.
154    See POSIX:2001 specification
155    <http://www.opengroup.org/susv3xsh/fsync.html>.  */
156 # if !@HAVE_FSYNC@
157 extern int fsync (int fd);
158 # endif
159 #elif defined GNULIB_POSIXCHECK
160 # undef fsync
161 # define fsync(fd) \
162     (GL_LINK_WARNING ("fsync is unportable - " \
163                       "use gnulib module fsync for portability"), \
164      fsync (fd))
165 #endif
166
167
168 #if @GNULIB_FTRUNCATE@
169 # if !@HAVE_FTRUNCATE@
170 /* Change the size of the file to which FD is opened to become equal to LENGTH.
171    Return 0 if successful, otherwise -1 and errno set.
172    See the POSIX:2001 specification
173    <http://www.opengroup.org/susv3xsh/ftruncate.html>.  */
174 extern int ftruncate (int fd, off_t length);
175 # endif
176 #elif defined GNULIB_POSIXCHECK
177 # undef ftruncate
178 # define ftruncate(f,l) \
179     (GL_LINK_WARNING ("ftruncate is unportable - " \
180                       "use gnulib module ftruncate for portability"), \
181      ftruncate (f, l))
182 #endif
183
184
185 #if @GNULIB_GETCWD@
186 /* Include the headers that might declare getcwd so that they will not
187    cause confusion if included after this file.  */
188 # include <stdlib.h>
189 # if @REPLACE_GETCWD@
190 /* Get the name of the current working directory, and put it in SIZE bytes
191    of BUF.
192    Return BUF if successful, or NULL if the directory couldn't be determined
193    or SIZE was too small.
194    See the POSIX:2001 specification
195    <http://www.opengroup.org/susv3xsh/getcwd.html>.
196    Additionally, the gnulib module 'getcwd' guarantees the following GNU
197    extension: If BUF is NULL, an array is allocated with 'malloc'; the array
198    is SIZE bytes long, unless SIZE == 0, in which case it is as big as
199    necessary.  */
200 #  define getcwd rpl_getcwd
201 extern char * getcwd (char *buf, size_t size);
202 # endif
203 #elif defined GNULIB_POSIXCHECK
204 # undef getcwd
205 # define getcwd(b,s) \
206     (GL_LINK_WARNING ("getcwd is unportable - " \
207                       "use gnulib module getcwd for portability"), \
208      getcwd (b, s))
209 #endif
210
211
212 #if @GNULIB_GETDTABLESIZE@
213 # if !@HAVE_GETDTABLESIZE@
214 /* Return the maximum number of file descriptors in the current process.  */
215 extern int getdtablesize (void);
216 # endif
217 #elif defined GNULIB_POSIXCHECK
218 # undef getdtablesize
219 # define getdtablesize() \
220     (GL_LINK_WARNING ("getdtablesize is unportable - " \
221                       "use gnulib module getdtablesize for portability"), \
222      getdtablesize ())
223 #endif
224
225
226 #if @GNULIB_GETLOGIN_R@
227 /* Copies the user's login name to NAME.
228    The array pointed to by NAME has room for SIZE bytes.
229
230    Returns 0 if successful.  Upon error, an error number is returned, or -1 in
231    the case that the login name cannot be found but no specific error is
232    provided (this case is hopefully rare but is left open by the POSIX spec).
233
234    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
235  */
236 # if !@HAVE_DECL_GETLOGIN_R@
237 #  include <stddef.h>
238 extern int getlogin_r (char *name, size_t size);
239 # endif
240 #elif defined GNULIB_POSIXCHECK
241 # undef getlogin_r
242 # define getlogin_r(n,s) \
243     (GL_LINK_WARNING ("getlogin_r is unportable - " \
244                       "use gnulib module getlogin_r for portability"), \
245      getlogin_r (n, s))
246 #endif
247
248
249 #if @GNULIB_GETPAGESIZE@
250 # if @REPLACE_GETPAGESIZE@
251 #  define getpagesize rpl_getpagesize
252 extern int getpagesize (void);
253 # elif !@HAVE_GETPAGESIZE@
254 /* This is for POSIX systems.  */
255 #  if !defined getpagesize && defined _SC_PAGESIZE
256 #   if ! (defined __VMS && __VMS_VER < 70000000)
257 #    define getpagesize() sysconf (_SC_PAGESIZE)
258 #   endif
259 #  endif
260 /* This is for older VMS.  */
261 #  if !defined getpagesize && defined __VMS
262 #   ifdef __ALPHA
263 #    define getpagesize() 8192
264 #   else
265 #    define getpagesize() 512
266 #   endif
267 #  endif
268 /* This is for BeOS.  */
269 #  if !defined getpagesize && @HAVE_OS_H@
270 #   include <OS.h>
271 #   if defined B_PAGE_SIZE
272 #    define getpagesize() B_PAGE_SIZE
273 #   endif
274 #  endif
275 /* This is for AmigaOS4.0.  */
276 #  if !defined getpagesize && defined __amigaos4__
277 #   define getpagesize() 2048
278 #  endif
279 /* This is for older Unix systems.  */
280 #  if !defined getpagesize && @HAVE_SYS_PARAM_H@
281 #   include <sys/param.h>
282 #   ifdef EXEC_PAGESIZE
283 #    define getpagesize() EXEC_PAGESIZE
284 #   else
285 #    ifdef NBPG
286 #     ifndef CLSIZE
287 #      define CLSIZE 1
288 #     endif
289 #     define getpagesize() (NBPG * CLSIZE)
290 #    else
291 #     ifdef NBPC
292 #      define getpagesize() NBPC
293 #     endif
294 #    endif
295 #   endif
296 #  endif
297 # endif
298 #elif defined GNULIB_POSIXCHECK
299 # undef getpagesize
300 # define getpagesize() \
301     (GL_LINK_WARNING ("getpagesize is unportable - " \
302                       "use gnulib module getpagesize for portability"), \
303      getpagesize ())
304 #endif
305
306
307 #if @GNULIB_LCHOWN@
308 # if @REPLACE_LCHOWN@
309 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
310    to GID (if GID is not -1).  Do not follow symbolic links.
311    Return 0 if successful, otherwise -1 and errno set.
312    See the POSIX:2001 specification
313    <http://www.opengroup.org/susv3xsh/lchown.html>.  */
314 #  define lchown rpl_lchown
315 extern int lchown (char const *file, uid_t owner, gid_t group);
316 # endif
317 #elif defined GNULIB_POSIXCHECK
318 # undef lchown
319 # define lchown(f,u,g) \
320     (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
321                       "systems - use gnulib module lchown for portability"), \
322      lchown (f, u, g))
323 #endif
324
325
326 #if @GNULIB_LSEEK@
327 # if @REPLACE_LSEEK@
328 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
329    Return the new offset if successful, otherwise -1 and errno set.
330    See the POSIX:2001 specification
331    <http://www.opengroup.org/susv3xsh/lseek.html>.  */
332 #  define lseek rpl_lseek
333    extern off_t lseek (int fd, off_t offset, int whence);
334 # endif
335 #elif defined GNULIB_POSIXCHECK
336 # undef lseek
337 # define lseek(f,o,w) \
338     (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
339                       "systems - use gnulib module lseek for portability"), \
340      lseek (f, o, w))
341 #endif
342
343
344 #if @GNULIB_READLINK@
345 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
346    bytes of it into BUF.  Return the number of bytes placed into BUF if
347    successful, otherwise -1 and errno set.
348    See the POSIX:2001 specification
349    <http://www.opengroup.org/susv3xsh/readlink.html>.  */
350 # if !@HAVE_READLINK@
351 #  include <stddef.h>
352 extern int readlink (const char *file, char *buf, size_t bufsize);
353 # endif
354 #elif defined GNULIB_POSIXCHECK
355 # undef readlink
356 # define readlink(f,b,s) \
357     (GL_LINK_WARNING ("readlink is unportable - " \
358                       "use gnulib module readlink for portability"), \
359      readlink (f, b, s))
360 #endif
361
362
363 #if @GNULIB_SLEEP@
364 /* Pause the execution of the current thread for N seconds.
365    Returns the number of seconds left to sleep.
366    See the POSIX:2001 specification
367    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
368 # if !@HAVE_SLEEP@
369 extern unsigned int sleep (unsigned int n);
370 # endif
371 #elif defined GNULIB_POSIXCHECK
372 # undef sleep
373 # define sleep(n) \
374     (GL_LINK_WARNING ("sleep is unportable - " \
375                       "use gnulib module sleep for portability"), \
376      sleep (n))
377 #endif
378
379
380 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
381 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
382    See the POSIX:2001 specification
383    <http://www.opengroup.org/susv3xsh/write.html>.  */
384 # undef write
385 # define write rpl_write
386 extern ssize_t write (int fd, const void *buf, size_t count);
387 #endif
388
389
390 #ifdef FCHDIR_REPLACEMENT
391 /* gnulib internal function.  */
392 extern void _gl_unregister_fd (int fd);
393 #endif
394
395
396 #ifdef __cplusplus
397 }
398 #endif
399
400
401 #endif /* _GL_UNISTD_H */
402 #endif /* _GL_UNISTD_H */