Add gethostname() declaration to <unistd.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_GETHOSTNAME@
276 /* Return the standard host name of the machine.
277    WARNING! The host name may or may not be fully qualified.
278
279    Put up to LEN bytes of the host name into NAME.
280    Null terminate it if the name is shorter than LEN.
281    If the host name is longer than LEN, set errno = EINVAL and return -1.
282    Return 0 if successful, otherwise set errno and return -1.  */
283 # if !@HAVE_GETHOSTNAME@
284 extern int gethostname(char *name, size_t len);
285 # endif
286 #elif defined GNULIB_POSIXCHECK
287 # undef gethostname
288 # define gethostname(n,l) \
289     (GL_LINK_WARNING ("gethostname is unportable - " \
290                       "use gnulib module gethostname for portability"), \
291      gethostname (n, l))
292 #endif
293
294
295 #if @GNULIB_GETLOGIN_R@
296 /* Copies the user's login name to NAME.
297    The array pointed to by NAME has room for SIZE bytes.
298
299    Returns 0 if successful.  Upon error, an error number is returned, or -1 in
300    the case that the login name cannot be found but no specific error is
301    provided (this case is hopefully rare but is left open by the POSIX spec).
302
303    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
304  */
305 # if !@HAVE_DECL_GETLOGIN_R@
306 #  include <stddef.h>
307 extern int getlogin_r (char *name, size_t size);
308 # endif
309 #elif defined GNULIB_POSIXCHECK
310 # undef getlogin_r
311 # define getlogin_r(n,s) \
312     (GL_LINK_WARNING ("getlogin_r is unportable - " \
313                       "use gnulib module getlogin_r for portability"), \
314      getlogin_r (n, s))
315 #endif
316
317
318 #if @GNULIB_GETPAGESIZE@
319 # if @REPLACE_GETPAGESIZE@
320 #  define getpagesize rpl_getpagesize
321 extern int getpagesize (void);
322 # elif !@HAVE_GETPAGESIZE@
323 /* This is for POSIX systems.  */
324 #  if !defined getpagesize && defined _SC_PAGESIZE
325 #   if ! (defined __VMS && __VMS_VER < 70000000)
326 #    define getpagesize() sysconf (_SC_PAGESIZE)
327 #   endif
328 #  endif
329 /* This is for older VMS.  */
330 #  if !defined getpagesize && defined __VMS
331 #   ifdef __ALPHA
332 #    define getpagesize() 8192
333 #   else
334 #    define getpagesize() 512
335 #   endif
336 #  endif
337 /* This is for BeOS.  */
338 #  if !defined getpagesize && @HAVE_OS_H@
339 #   include <OS.h>
340 #   if defined B_PAGE_SIZE
341 #    define getpagesize() B_PAGE_SIZE
342 #   endif
343 #  endif
344 /* This is for AmigaOS4.0.  */
345 #  if !defined getpagesize && defined __amigaos4__
346 #   define getpagesize() 2048
347 #  endif
348 /* This is for older Unix systems.  */
349 #  if !defined getpagesize && @HAVE_SYS_PARAM_H@
350 #   include <sys/param.h>
351 #   ifdef EXEC_PAGESIZE
352 #    define getpagesize() EXEC_PAGESIZE
353 #   else
354 #    ifdef NBPG
355 #     ifndef CLSIZE
356 #      define CLSIZE 1
357 #     endif
358 #     define getpagesize() (NBPG * CLSIZE)
359 #    else
360 #     ifdef NBPC
361 #      define getpagesize() NBPC
362 #     endif
363 #    endif
364 #   endif
365 #  endif
366 # endif
367 #elif defined GNULIB_POSIXCHECK
368 # undef getpagesize
369 # define getpagesize() \
370     (GL_LINK_WARNING ("getpagesize is unportable - " \
371                       "use gnulib module getpagesize for portability"), \
372      getpagesize ())
373 #endif
374
375
376 #if @GNULIB_GETUSERSHELL@
377 # if !@HAVE_GETUSERSHELL@
378 /* Return the next valid login shell on the system, or NULL when the end of
379    the list has been reached.  */
380 extern char *getusershell (void);
381 /* Rewind to pointer that is advanced at each getusershell() call.  */
382 extern void setusershell (void);
383 /* Free the pointer that is advanced at each getusershell() call and
384    associated resources.  */
385 extern void endusershell (void);
386 # endif
387 #elif defined GNULIB_POSIXCHECK
388 # undef getusershell
389 # define getusershell() \
390     (GL_LINK_WARNING ("getusershell is unportable - " \
391                       "use gnulib module getusershell for portability"), \
392      getusershell ())
393 # undef setusershell
394 # define setusershell() \
395     (GL_LINK_WARNING ("setusershell is unportable - " \
396                       "use gnulib module getusershell for portability"), \
397      setusershell ())
398 # undef endusershell
399 # define endusershell() \
400     (GL_LINK_WARNING ("endusershell is unportable - " \
401                       "use gnulib module getusershell for portability"), \
402      endusershell ())
403 #endif
404
405
406 #if @GNULIB_LCHOWN@
407 # if @REPLACE_LCHOWN@
408 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
409    to GID (if GID is not -1).  Do not follow symbolic links.
410    Return 0 if successful, otherwise -1 and errno set.
411    See the POSIX:2001 specification
412    <http://www.opengroup.org/susv3xsh/lchown.html>.  */
413 #  define lchown rpl_lchown
414 extern int lchown (char const *file, uid_t owner, gid_t group);
415 # endif
416 #elif defined GNULIB_POSIXCHECK
417 # undef lchown
418 # define lchown(f,u,g) \
419     (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
420                       "systems - use gnulib module lchown for portability"), \
421      lchown (f, u, g))
422 #endif
423
424
425 #if @GNULIB_LSEEK@
426 # if @REPLACE_LSEEK@
427 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
428    Return the new offset if successful, otherwise -1 and errno set.
429    See the POSIX:2001 specification
430    <http://www.opengroup.org/susv3xsh/lseek.html>.  */
431 #  define lseek rpl_lseek
432    extern off_t lseek (int fd, off_t offset, int whence);
433 # endif
434 #elif defined GNULIB_POSIXCHECK
435 # undef lseek
436 # define lseek(f,o,w) \
437     (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
438                       "systems - use gnulib module lseek for portability"), \
439      lseek (f, o, w))
440 #endif
441
442
443 #if @GNULIB_READLINK@
444 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
445    bytes of it into BUF.  Return the number of bytes placed into BUF if
446    successful, otherwise -1 and errno set.
447    See the POSIX:2001 specification
448    <http://www.opengroup.org/susv3xsh/readlink.html>.  */
449 # if !@HAVE_READLINK@
450 #  include <stddef.h>
451 extern int readlink (const char *file, char *buf, size_t bufsize);
452 # endif
453 #elif defined GNULIB_POSIXCHECK
454 # undef readlink
455 # define readlink(f,b,s) \
456     (GL_LINK_WARNING ("readlink is unportable - " \
457                       "use gnulib module readlink for portability"), \
458      readlink (f, b, s))
459 #endif
460
461
462 #if @GNULIB_SLEEP@
463 /* Pause the execution of the current thread for N seconds.
464    Returns the number of seconds left to sleep.
465    See the POSIX:2001 specification
466    <http://www.opengroup.org/susv3xsh/sleep.html>.  */
467 # if !@HAVE_SLEEP@
468 extern unsigned int sleep (unsigned int n);
469 # endif
470 #elif defined GNULIB_POSIXCHECK
471 # undef sleep
472 # define sleep(n) \
473     (GL_LINK_WARNING ("sleep is unportable - " \
474                       "use gnulib module sleep for portability"), \
475      sleep (n))
476 #endif
477
478
479 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
480 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
481    See the POSIX:2001 specification
482    <http://www.opengroup.org/susv3xsh/write.html>.  */
483 # undef write
484 # define write rpl_write
485 extern ssize_t write (int fd, const void *buf, size_t count);
486 #endif
487
488
489 #ifdef FCHDIR_REPLACEMENT
490 /* gnulib internal function.  */
491 extern void _gl_unregister_fd (int fd);
492 #endif
493
494
495 #ifdef __cplusplus
496 }
497 #endif
498
499
500 #endif /* _GL_UNISTD_H */
501 #endif /* _GL_UNISTD_H */