1 /* Substitute for and wrapper around <unistd.h>.
2 Copyright (C) 2003-2008 Free Software Foundation, Inc.
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)
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.
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. */
21 @PRAGMA_SYSTEM_HEADER@
24 /* The include_next requires a split double-inclusion guard. */
26 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
32 /* mingw doesn't define the SEEK_* macros in <unistd.h>. */
33 #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
37 /* mingw fails to declare _exit in <unistd.h>. */
40 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
42 # include <sys/types.h>
45 /* The definition of GL_LINK_WARNING is copied here. */
48 /* Declare overridden functions. */
57 # ifndef REPLACE_CHOWN
58 # define REPLACE_CHOWN 1
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);
70 #elif defined GNULIB_POSIXCHECK
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"), \
81 # if @UNISTD_H_HAVE_WINSOCK2_H@
82 /* Need a gnulib internal function. */
83 # define HAVE__GL_CLOSE_FD_MAYBE_SOCKET 1
86 /* Automatically included by modules that need a replacement for close. */
88 # define close rpl_close
89 extern int close (int);
91 #elif @UNISTD_H_HAVE_WINSOCK2_H@
93 # define close close_used_without_requesting_gnulib_module_close
94 #elif defined GNULIB_POSIXCHECK
97 (GL_LINK_WARNING ("close does not portably work on sockets - " \
98 "use gnulib module close for portability"), \
105 /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
106 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
107 Return 0 if successful, otherwise -1 and errno set.
108 See the POSIX:2001 specification
109 <http://www.opengroup.org/susv3xsh/dup2.html>. */
110 extern int dup2 (int oldfd, int newfd);
112 #elif defined GNULIB_POSIXCHECK
115 (GL_LINK_WARNING ("dup2 is unportable - " \
116 "use gnulib module dup2 for portability"), \
122 # if !@HAVE_DECL_ENVIRON@
123 /* Set of environment variables and values. An array of strings of the form
124 "VARIABLE=VALUE", terminated with a NULL. */
125 # if defined __APPLE__ && defined __MACH__
126 # include <crt_externs.h>
127 # define environ (*_NSGetEnviron ())
129 extern char **environ;
132 #elif defined GNULIB_POSIXCHECK
135 (GL_LINK_WARNING ("environ is unportable - " \
136 "use gnulib module environ for portability"), \
141 #if @GNULIB_EUIDACCESS@
142 # if !@HAVE_EUIDACCESS@
143 /* Like access(), except that is uses the effective user id and group id of
144 the current process. */
145 extern int euidaccess (const char *filename, int mode);
147 #elif defined GNULIB_POSIXCHECK
149 # define euidaccess(f,m) \
150 (GL_LINK_WARNING ("euidaccess is unportable - " \
151 "use gnulib module euidaccess for portability"), \
157 # if @REPLACE_FCHDIR@
159 /* Change the process' current working directory to the directory on which
160 the given file descriptor is open.
161 Return 0 if successful, otherwise -1 and errno set.
162 See the POSIX:2001 specification
163 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
164 extern int fchdir (int /*fd*/);
167 extern int dup (int);
168 # define dup2 rpl_dup2
169 extern int dup2 (int, int);
172 #elif defined GNULIB_POSIXCHECK
175 (GL_LINK_WARNING ("fchdir is unportable - " \
176 "use gnulib module fchdir for portability"), \
182 /* Synchronize changes to a file.
183 Return 0 if successful, otherwise -1 and errno set.
184 See POSIX:2001 specification
185 <http://www.opengroup.org/susv3xsh/fsync.html>. */
187 extern int fsync (int fd);
189 #elif defined GNULIB_POSIXCHECK
192 (GL_LINK_WARNING ("fsync is unportable - " \
193 "use gnulib module fsync for portability"), \
198 #if @GNULIB_FTRUNCATE@
199 # if !@HAVE_FTRUNCATE@
200 /* Change the size of the file to which FD is opened to become equal to LENGTH.
201 Return 0 if successful, otherwise -1 and errno set.
202 See the POSIX:2001 specification
203 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
204 extern int ftruncate (int fd, off_t length);
206 #elif defined GNULIB_POSIXCHECK
208 # define ftruncate(f,l) \
209 (GL_LINK_WARNING ("ftruncate is unportable - " \
210 "use gnulib module ftruncate for portability"), \
216 /* Include the headers that might declare getcwd so that they will not
217 cause confusion if included after this file. */
219 # if @REPLACE_GETCWD@
220 /* Get the name of the current working directory, and put it in SIZE bytes
222 Return BUF if successful, or NULL if the directory couldn't be determined
223 or SIZE was too small.
224 See the POSIX:2001 specification
225 <http://www.opengroup.org/susv3xsh/getcwd.html>.
226 Additionally, the gnulib module 'getcwd' guarantees the following GNU
227 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
228 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
230 # define getcwd rpl_getcwd
231 extern char * getcwd (char *buf, size_t size);
233 #elif defined GNULIB_POSIXCHECK
235 # define getcwd(b,s) \
236 (GL_LINK_WARNING ("getcwd is unportable - " \
237 "use gnulib module getcwd for portability"), \
242 #if @GNULIB_GETDOMAINNAME@
243 /* Return the NIS domain name of the machine.
244 WARNING! The NIS domain name is unrelated to the fully qualified host name
245 of the machine. It is also unrelated to email addresses.
246 WARNING! The NIS domain name is usually the empty string or "(none)" when
249 Put up to LEN bytes of the NIS domain name into NAME.
250 Null terminate it if the name is shorter than LEN.
251 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
252 Return 0 if successful, otherwise set errno and return -1. */
253 # if !@HAVE_GETDOMAINNAME@
254 extern int getdomainname(char *name, size_t len);
256 #elif defined GNULIB_POSIXCHECK
257 # undef getdomainname
258 # define getdomainname(n,l) \
259 (GL_LINK_WARNING ("getdomainname is unportable - " \
260 "use gnulib module getdomainname for portability"), \
261 getdomainname (n, l))
265 #if @GNULIB_GETDTABLESIZE@
266 # if !@HAVE_GETDTABLESIZE@
267 /* Return the maximum number of file descriptors in the current process. */
268 extern int getdtablesize (void);
270 #elif defined GNULIB_POSIXCHECK
271 # undef getdtablesize
272 # define getdtablesize() \
273 (GL_LINK_WARNING ("getdtablesize is unportable - " \
274 "use gnulib module getdtablesize for portability"), \
279 #if @GNULIB_GETHOSTNAME@
280 /* Return the standard host name of the machine.
281 WARNING! The host name may or may not be fully qualified.
283 Put up to LEN bytes of the host name into NAME.
284 Null terminate it if the name is shorter than LEN.
285 If the host name is longer than LEN, set errno = EINVAL and return -1.
286 Return 0 if successful, otherwise set errno and return -1. */
287 # if !@HAVE_GETHOSTNAME@
288 extern int gethostname(char *name, size_t len);
290 #elif defined GNULIB_POSIXCHECK
292 # define gethostname(n,l) \
293 (GL_LINK_WARNING ("gethostname is unportable - " \
294 "use gnulib module gethostname for portability"), \
299 #if @GNULIB_GETLOGIN_R@
300 /* Copies the user's login name to NAME.
301 The array pointed to by NAME has room for SIZE bytes.
303 Returns 0 if successful. Upon error, an error number is returned, or -1 in
304 the case that the login name cannot be found but no specific error is
305 provided (this case is hopefully rare but is left open by the POSIX spec).
307 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
309 # if !@HAVE_DECL_GETLOGIN_R@
311 extern int getlogin_r (char *name, size_t size);
313 #elif defined GNULIB_POSIXCHECK
315 # define getlogin_r(n,s) \
316 (GL_LINK_WARNING ("getlogin_r is unportable - " \
317 "use gnulib module getlogin_r for portability"), \
322 #if @GNULIB_GETPAGESIZE@
323 # if @REPLACE_GETPAGESIZE@
324 # define getpagesize rpl_getpagesize
325 extern int getpagesize (void);
326 # elif !@HAVE_GETPAGESIZE@
327 /* This is for POSIX systems. */
328 # if !defined getpagesize && defined _SC_PAGESIZE
329 # if ! (defined __VMS && __VMS_VER < 70000000)
330 # define getpagesize() sysconf (_SC_PAGESIZE)
333 /* This is for older VMS. */
334 # if !defined getpagesize && defined __VMS
336 # define getpagesize() 8192
338 # define getpagesize() 512
341 /* This is for BeOS. */
342 # if !defined getpagesize && @HAVE_OS_H@
344 # if defined B_PAGE_SIZE
345 # define getpagesize() B_PAGE_SIZE
348 /* This is for AmigaOS4.0. */
349 # if !defined getpagesize && defined __amigaos4__
350 # define getpagesize() 2048
352 /* This is for older Unix systems. */
353 # if !defined getpagesize && @HAVE_SYS_PARAM_H@
354 # include <sys/param.h>
355 # ifdef EXEC_PAGESIZE
356 # define getpagesize() EXEC_PAGESIZE
362 # define getpagesize() (NBPG * CLSIZE)
365 # define getpagesize() NBPC
371 #elif defined GNULIB_POSIXCHECK
373 # define getpagesize() \
374 (GL_LINK_WARNING ("getpagesize is unportable - " \
375 "use gnulib module getpagesize for portability"), \
380 #if @GNULIB_GETUSERSHELL@
381 # if !@HAVE_GETUSERSHELL@
382 /* Return the next valid login shell on the system, or NULL when the end of
383 the list has been reached. */
384 extern char *getusershell (void);
385 /* Rewind to pointer that is advanced at each getusershell() call. */
386 extern void setusershell (void);
387 /* Free the pointer that is advanced at each getusershell() call and
388 associated resources. */
389 extern void endusershell (void);
391 #elif defined GNULIB_POSIXCHECK
393 # define getusershell() \
394 (GL_LINK_WARNING ("getusershell is unportable - " \
395 "use gnulib module getusershell for portability"), \
398 # define setusershell() \
399 (GL_LINK_WARNING ("setusershell is unportable - " \
400 "use gnulib module getusershell for portability"), \
403 # define endusershell() \
404 (GL_LINK_WARNING ("endusershell is unportable - " \
405 "use gnulib module getusershell for portability"), \
411 # if @REPLACE_LCHOWN@
412 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
413 to GID (if GID is not -1). Do not follow symbolic links.
414 Return 0 if successful, otherwise -1 and errno set.
415 See the POSIX:2001 specification
416 <http://www.opengroup.org/susv3xsh/lchown.html>. */
417 # define lchown rpl_lchown
418 extern int lchown (char const *file, uid_t owner, gid_t group);
420 #elif defined GNULIB_POSIXCHECK
422 # define lchown(f,u,g) \
423 (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
424 "systems - use gnulib module lchown for portability"), \
431 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
432 Return the new offset if successful, otherwise -1 and errno set.
433 See the POSIX:2001 specification
434 <http://www.opengroup.org/susv3xsh/lseek.html>. */
435 # define lseek rpl_lseek
436 extern off_t lseek (int fd, off_t offset, int whence);
438 #elif defined GNULIB_POSIXCHECK
440 # define lseek(f,o,w) \
441 (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
442 "systems - use gnulib module lseek for portability"), \
447 #if @GNULIB_READLINK@
448 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
449 bytes of it into BUF. Return the number of bytes placed into BUF if
450 successful, otherwise -1 and errno set.
451 See the POSIX:2001 specification
452 <http://www.opengroup.org/susv3xsh/readlink.html>. */
453 # if !@HAVE_READLINK@
455 extern int readlink (const char *file, char *buf, size_t bufsize);
457 #elif defined GNULIB_POSIXCHECK
459 # define readlink(f,b,s) \
460 (GL_LINK_WARNING ("readlink is unportable - " \
461 "use gnulib module readlink for portability"), \
467 /* Pause the execution of the current thread for N seconds.
468 Returns the number of seconds left to sleep.
469 See the POSIX:2001 specification
470 <http://www.opengroup.org/susv3xsh/sleep.html>. */
472 extern unsigned int sleep (unsigned int n);
474 #elif defined GNULIB_POSIXCHECK
477 (GL_LINK_WARNING ("sleep is unportable - " \
478 "use gnulib module sleep for portability"), \
483 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
484 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
485 See the POSIX:2001 specification
486 <http://www.opengroup.org/susv3xsh/write.html>. */
488 # define write rpl_write
489 extern ssize_t write (int fd, const void *buf, size_t count);
493 #ifdef FCHDIR_REPLACEMENT
494 /* gnulib internal function. */
495 extern void _gl_unregister_fd (int fd);
504 #endif /* _GL_UNISTD_H */
505 #endif /* _GL_UNISTD_H */