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