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"), \
82 /* Automatically included by modules that need a replacement for close. */
84 # define close rpl_close
85 extern int close (int);
87 #elif @UNISTD_H_HAVE_WINSOCK2_H@
89 # define close close_used_without_requesting_gnulib_module_close
90 #elif defined GNULIB_POSIXCHECK
93 (GL_LINK_WARNING ("close does not portably work on sockets - " \
94 "use gnulib module close for portability"), \
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);
108 #elif defined GNULIB_POSIXCHECK
111 (GL_LINK_WARNING ("dup2 is unportable - " \
112 "use gnulib module dup2 for portability"), \
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 ())
125 extern char **environ;
128 #elif defined GNULIB_POSIXCHECK
131 (GL_LINK_WARNING ("environ is unportable - " \
132 "use gnulib module environ for portability"), \
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);
143 #elif defined GNULIB_POSIXCHECK
145 # define euidaccess(f,m) \
146 (GL_LINK_WARNING ("euidaccess is unportable - " \
147 "use gnulib module euidaccess for portability"), \
153 # if @REPLACE_FCHDIR@
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*/);
163 extern int dup (int);
164 # define dup2 rpl_dup2
165 extern int dup2 (int, int);
168 #elif defined GNULIB_POSIXCHECK
171 (GL_LINK_WARNING ("fchdir is unportable - " \
172 "use gnulib module fchdir for portability"), \
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>. */
183 extern int fsync (int fd);
185 #elif defined GNULIB_POSIXCHECK
188 (GL_LINK_WARNING ("fsync is unportable - " \
189 "use gnulib module fsync for portability"), \
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);
202 #elif defined GNULIB_POSIXCHECK
204 # define ftruncate(f,l) \
205 (GL_LINK_WARNING ("ftruncate is unportable - " \
206 "use gnulib module ftruncate for portability"), \
212 /* Include the headers that might declare getcwd so that they will not
213 cause confusion if included after this file. */
215 # if @REPLACE_GETCWD@
216 /* Get the name of the current working directory, and put it in SIZE bytes
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
226 # define getcwd rpl_getcwd
227 extern char * getcwd (char *buf, size_t size);
229 #elif defined GNULIB_POSIXCHECK
231 # define getcwd(b,s) \
232 (GL_LINK_WARNING ("getcwd is unportable - " \
233 "use gnulib module getcwd for portability"), \
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
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);
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))
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);
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"), \
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.
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);
286 #elif defined GNULIB_POSIXCHECK
288 # define gethostname(n,l) \
289 (GL_LINK_WARNING ("gethostname is unportable - " \
290 "use gnulib module gethostname for portability"), \
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.
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).
303 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
305 # if !@HAVE_DECL_GETLOGIN_R@
307 extern int getlogin_r (char *name, size_t size);
309 #elif defined GNULIB_POSIXCHECK
311 # define getlogin_r(n,s) \
312 (GL_LINK_WARNING ("getlogin_r is unportable - " \
313 "use gnulib module getlogin_r for portability"), \
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)
329 /* This is for older VMS. */
330 # if !defined getpagesize && defined __VMS
332 # define getpagesize() 8192
334 # define getpagesize() 512
337 /* This is for BeOS. */
338 # if !defined getpagesize && @HAVE_OS_H@
340 # if defined B_PAGE_SIZE
341 # define getpagesize() B_PAGE_SIZE
344 /* This is for AmigaOS4.0. */
345 # if !defined getpagesize && defined __amigaos4__
346 # define getpagesize() 2048
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
358 # define getpagesize() (NBPG * CLSIZE)
361 # define getpagesize() NBPC
367 #elif defined GNULIB_POSIXCHECK
369 # define getpagesize() \
370 (GL_LINK_WARNING ("getpagesize is unportable - " \
371 "use gnulib module getpagesize for portability"), \
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);
387 #elif defined GNULIB_POSIXCHECK
389 # define getusershell() \
390 (GL_LINK_WARNING ("getusershell is unportable - " \
391 "use gnulib module getusershell for portability"), \
394 # define setusershell() \
395 (GL_LINK_WARNING ("setusershell is unportable - " \
396 "use gnulib module getusershell for portability"), \
399 # define endusershell() \
400 (GL_LINK_WARNING ("endusershell is unportable - " \
401 "use gnulib module getusershell for portability"), \
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);
416 #elif defined GNULIB_POSIXCHECK
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"), \
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);
434 #elif defined GNULIB_POSIXCHECK
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"), \
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@
451 extern int readlink (const char *file, char *buf, size_t bufsize);
453 #elif defined GNULIB_POSIXCHECK
455 # define readlink(f,b,s) \
456 (GL_LINK_WARNING ("readlink is unportable - " \
457 "use gnulib module readlink for portability"), \
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>. */
468 extern unsigned int sleep (unsigned int n);
470 #elif defined GNULIB_POSIXCHECK
473 (GL_LINK_WARNING ("sleep is unportable - " \
474 "use gnulib module sleep for portability"), \
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>. */
484 # define write rpl_write
485 extern ssize_t write (int fd, const void *buf, size_t count);
489 #ifdef FCHDIR_REPLACEMENT
490 /* gnulib internal function. */
491 extern void _gl_unregister_fd (int fd);
500 #endif /* _GL_UNISTD_H */
501 #endif /* _GL_UNISTD_H */