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