Add a getloadavg() declaration to <stdlib.h>.
[gnulib.git] / 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 @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_EUIDACCESS@
138 # if !@HAVE_EUIDACCESS@
139 /* Like access(), except that is uses the effective user id and group id of
140    the current process.  */
141 extern int euidaccess (const char *filename, int mode);
142 # endif
143 #elif defined GNULIB_POSIXCHECK
144 # undef euidaccess
145 # define euidaccess(f,m) \
146     (GL_LINK_WARNING ("euidaccess is unportable - " \
147                       "use gnulib module euidaccess for portability"), \
148      euidaccess (f, m))
149 #endif
150
151
152 #if @GNULIB_FCHDIR@
153 # if @REPLACE_FCHDIR@
154
155 /* Change the process' current working directory to the directory on which
156    the given file descriptor is open.
157    Return 0 if successful, otherwise -1 and errno set.
158    See the POSIX:2001 specification
159    <http://www.opengroup.org/susv3xsh/fchdir.html>.  */
160 extern int fchdir (int /*fd*/);
161
162 #  define dup rpl_dup
163 extern int dup (int);
164 #  define dup2 rpl_dup2
165 extern int dup2 (int, int);
166
167 # endif
168 #elif defined GNULIB_POSIXCHECK
169 # undef fchdir
170 # define fchdir(f) \
171     (GL_LINK_WARNING ("fchdir is unportable - " \
172                       "use gnulib module fchdir for portability"), \
173      fchdir (f))
174 #endif
175
176
177 #if @GNULIB_FSYNC@
178 /* Synchronize changes to a file.
179    Return 0 if successful, otherwise -1 and errno set.
180    See POSIX:2001 specification
181    <http://www.opengroup.org/susv3xsh/fsync.html>.  */
182 # if !@HAVE_FSYNC@
183 extern int fsync (int fd);
184 # endif
185 #elif defined GNULIB_POSIXCHECK
186 # undef fsync
187 # define fsync(fd) \
188     (GL_LINK_WARNING ("fsync is unportable - " \
189                       "use gnulib module fsync for portability"), \
190      fsync (fd))
191 #endif
192
193
194 #if @GNULIB_FTRUNCATE@
195 # if !@HAVE_FTRUNCATE@
196 /* Change the size of the file to which FD is opened to become equal to LENGTH.
197    Return 0 if successful, otherwise -1 and errno set.
198    See the POSIX:2001 specification
199    <http://www.opengroup.org/susv3xsh/ftruncate.html>.  */
200 extern int ftruncate (int fd, off_t length);
201 # endif
202 #elif defined GNULIB_POSIXCHECK
203 # undef ftruncate
204 # define ftruncate(f,l) \
205     (GL_LINK_WARNING ("ftruncate is unportable - " \
206                       "use gnulib module ftruncate for portability"), \
207      ftruncate (f, l))
208 #endif
209
210
211 #if @GNULIB_GETCWD@
212 /* Include the headers that might declare getcwd so that they will not
213    cause confusion if included after this file.  */
214 # include <stdlib.h>
215 # if @REPLACE_GETCWD@
216 /* Get the name of the current working directory, and put it in SIZE bytes
217    of BUF.
218    Return BUF if successful, or NULL if the directory couldn't be determined
219    or SIZE was too small.
220    See the POSIX:2001 specification
221    <http://www.opengroup.org/susv3xsh/getcwd.html>.
222    Additionally, the gnulib module 'getcwd' guarantees the following GNU
223    extension: If BUF is NULL, an array is allocated with 'malloc'; the array
224    is SIZE bytes long, unless SIZE == 0, in which case it is as big as
225    necessary.  */
226 #  define getcwd rpl_getcwd
227 extern char * getcwd (char *buf, size_t size);
228 # endif
229 #elif defined GNULIB_POSIXCHECK
230 # undef getcwd
231 # define getcwd(b,s) \
232     (GL_LINK_WARNING ("getcwd is unportable - " \
233                       "use gnulib module getcwd for portability"), \
234      getcwd (b, s))
235 #endif
236
237
238 #if @GNULIB_GETDOMAINNAME@
239 /* Return the NIS domain name of the machine.
240    WARNING! The NIS domain name is unrelated to the fully qualified host name
241             of the machine.  It is also unrelated to email addresses.
242    WARNING! The NIS domain name is usually the empty string or "(none)" when
243             not using NIS.
244
245    Put up to LEN bytes of the NIS domain name into NAME.
246    Null terminate it if the name is shorter than LEN.
247    If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
248    Return 0 if successful, otherwise set errno and return -1.  */
249 # if !@HAVE_GETDOMAINNAME@
250 extern int getdomainname(char *name, size_t len);
251 # endif
252 #elif defined GNULIB_POSIXCHECK
253 # undef getdomainname
254 # define getdomainname(n,l) \
255     (GL_LINK_WARNING ("getdomainname is unportable - " \
256                       "use gnulib module getdomainname for portability"), \
257      getdomainname (n, l))
258 #endif
259
260
261 #if @GNULIB_GETDTABLESIZE@
262 # if !@HAVE_GETDTABLESIZE@
263 /* Return the maximum number of file descriptors in the current process.  */
264 extern int getdtablesize (void);
265 # endif
266 #elif defined GNULIB_POSIXCHECK
267 # undef getdtablesize
268 # define getdtablesize() \
269     (GL_LINK_WARNING ("getdtablesize is unportable - " \
270                       "use gnulib module getdtablesize for portability"), \
271      getdtablesize ())
272 #endif
273
274
275 #if @GNULIB_GETLOGIN_R@
276 /* Copies the user's login name to NAME.
277    The array pointed to by NAME has room for SIZE bytes.
278
279    Returns 0 if successful.  Upon error, an error number is returned, or -1 in
280    the case that the login name cannot be found but no specific error is
281    provided (this case is hopefully rare but is left open by the POSIX spec).
282
283    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
284  */
285 # if !@HAVE_DECL_GETLOGIN_R@
286 #  include <stddef.h>
287 extern int getlogin_r (char *name, size_t size);
288 # endif
289 #elif defined GNULIB_POSIXCHECK
290 # undef getlogin_r
291 # define getlogin_r(n,s) \
292     (GL_LINK_WARNING ("getlogin_r is unportable - " \
293                       "use gnulib module getlogin_r for portability"), \
294      getlogin_r (n, s))
295 #endif
296
297
298 #if @GNULIB_GETPAGESIZE@
299 # if @REPLACE_GETPAGESIZE@
300 #  define getpagesize rpl_getpagesize
301 extern int getpagesize (void);
302 # elif !@HAVE_GETPAGESIZE@
303 /* This is for POSIX systems.  */
304 #  if !defined getpagesize && defined _SC_PAGESIZE
305 #   if ! (defined __VMS && __VMS_VER < 70000000)
306 #    define getpagesize() sysconf (_SC_PAGESIZE)
307 #   endif
308 #  endif
309 /* This is for older VMS.  */
310 #  if !defined getpagesize && defined __VMS
311 #   ifdef __ALPHA
312 #    define getpagesize() 8192
313 #   else
314 #    define getpagesize() 512
315 #   endif
316 #  endif
317 /* This is for BeOS.  */
318 #  if !defined getpagesize && @HAVE_OS_H@
319 #   include <OS.h>
320 #   if defined B_PAGE_SIZE
321 #    define getpagesize() B_PAGE_SIZE
322 #   endif
323 #  endif
324 /* This is for AmigaOS4.0.  */
325 #  if !defined getpagesize && defined __amigaos4__
326 #   define getpagesize() 2048
327 #  endif
328 /* This is for older Unix systems.  */
329 #  if !defined getpagesize && @HAVE_SYS_PARAM_H@
330 #   include <sys/param.h>
331 #   ifdef EXEC_PAGESIZE
332 #    define getpagesize() EXEC_PAGESIZE
333 #   else
334 #    ifdef NBPG
335 #     ifndef CLSIZE
336 #      define CLSIZE 1
337 #     endif
338 #     define getpagesize() (NBPG * CLSIZE)
339 #    else
340 #     ifdef NBPC
341 #      define getpagesize() NBPC
342 #     endif
343 #    endif
344 #   endif
345 #  endif
346 # endif
347 #elif defined GNULIB_POSIXCHECK
348 # undef getpagesize
349 # define getpagesize() \
350     (GL_LINK_WARNING ("getpagesize is unportable - " \
351                       "use gnulib module getpagesize for portability"), \
352      getpagesize ())
353 #endif
354
355
356 #if @GNULIB_LCHOWN@
357 # if @REPLACE_LCHOWN@
358 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
359    to GID (if GID is not -1).  Do not follow symbolic links.
360    Return 0 if successful, otherwise -1 and errno set.
361    See the POSIX:2001 specification
362    <http://www.opengroup.org/susv3xsh/lchown.html>.  */
363 #  define lchown rpl_lchown
364 extern int lchown (char const *file, uid_t owner, gid_t group);
365 # endif
366 #elif defined GNULIB_POSIXCHECK
367 # undef lchown
368 # define lchown(f,u,g) \
369     (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
370                       "systems - use gnulib module lchown for portability"), \
371      lchown (f, u, g))
372 #endif
373
374
375 #if @GNULIB_LSEEK@
376 # if @REPLACE_LSEEK@
377 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
378    Return the new offset if successful, otherwise -1 and errno set.
379    See the POSIX:2001 specification
380    <http://www.opengroup.org/susv3xsh/lseek.html>.  */
381 #  define lseek rpl_lseek
382    extern off_t lseek (int fd, off_t offset, int whence);
383 # endif
384 #elif defined GNULIB_POSIXCHECK
385 # undef lseek
386 # define lseek(f,o,w) \
387     (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
388                       "systems - use gnulib module lseek for portability"), \
389      lseek (f, o, w))
390 #endif
391
392
393 #if @GNULIB_READLINK@
394 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
395    bytes of it into BUF.  Return the number of bytes placed into BUF if
396    successful, otherwise -1 and errno set.
397    See the POSIX:2001 specification
398    <http://www.opengroup.org/susv3xsh/readlink.html>.  */
399 # if !@HAVE_READLINK@
400 #  include <stddef.h>
401 extern int readlink (const char *file, char *buf, size_t bufsize);
402 # endif
403 #elif defined GNULIB_POSIXCHECK
404 # undef readlink
405 # define readlink(f,b,s) \
406     (GL_LINK_WARNING ("readlink is unportable - " \
407                       "use gnulib module readlink for portability"), \
408      readlink (f, b, s))
409 #endif
410
411
412 #if @GNULIB_SLEEP@
413 /* Pause the execution of the current thread for N seconds.
414    Returns the number of seconds left to sleep.
415    See the POSIX:2001 specification
416    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
417 # if !@HAVE_SLEEP@
418 extern unsigned int sleep (unsigned int n);
419 # endif
420 #elif defined GNULIB_POSIXCHECK
421 # undef sleep
422 # define sleep(n) \
423     (GL_LINK_WARNING ("sleep is unportable - " \
424                       "use gnulib module sleep for portability"), \
425      sleep (n))
426 #endif
427
428
429 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
430 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
431    See the POSIX:2001 specification
432    <http://www.opengroup.org/susv3xsh/write.html>.  */
433 # undef write
434 # define write rpl_write
435 extern ssize_t write (int fd, const void *buf, size_t count);
436 #endif
437
438
439 #ifdef FCHDIR_REPLACEMENT
440 /* gnulib internal function.  */
441 extern void _gl_unregister_fd (int fd);
442 #endif
443
444
445 #ifdef __cplusplus
446 }
447 #endif
448
449
450 #endif /* _GL_UNISTD_H */
451 #endif /* _GL_UNISTD_H */