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_GETLOGIN_R@
276 /* Copies the user's login name to NAME.
277 The array pointed to by NAME has room for SIZE bytes.
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).
283 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
285 # if !@HAVE_DECL_GETLOGIN_R@
287 extern int getlogin_r (char *name, size_t size);
289 #elif defined GNULIB_POSIXCHECK
291 # define getlogin_r(n,s) \
292 (GL_LINK_WARNING ("getlogin_r is unportable - " \
293 "use gnulib module getlogin_r for portability"), \
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)
309 /* This is for older VMS. */
310 # if !defined getpagesize && defined __VMS
312 # define getpagesize() 8192
314 # define getpagesize() 512
317 /* This is for BeOS. */
318 # if !defined getpagesize && @HAVE_OS_H@
320 # if defined B_PAGE_SIZE
321 # define getpagesize() B_PAGE_SIZE
324 /* This is for AmigaOS4.0. */
325 # if !defined getpagesize && defined __amigaos4__
326 # define getpagesize() 2048
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
338 # define getpagesize() (NBPG * CLSIZE)
341 # define getpagesize() NBPC
347 #elif defined GNULIB_POSIXCHECK
349 # define getpagesize() \
350 (GL_LINK_WARNING ("getpagesize is unportable - " \
351 "use gnulib module getpagesize for portability"), \
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);
366 #elif defined GNULIB_POSIXCHECK
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"), \
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);
384 #elif defined GNULIB_POSIXCHECK
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"), \
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@
401 extern int readlink (const char *file, char *buf, size_t bufsize);
403 #elif defined GNULIB_POSIXCHECK
405 # define readlink(f,b,s) \
406 (GL_LINK_WARNING ("readlink is unportable - " \
407 "use gnulib module readlink for portability"), \
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>. */
418 extern unsigned int sleep (unsigned int n);
420 #elif defined GNULIB_POSIXCHECK
423 (GL_LINK_WARNING ("sleep is unportable - " \
424 "use gnulib module sleep for portability"), \
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>. */
434 # define write rpl_write
435 extern ssize_t write (int fd, const void *buf, size_t count);
439 #ifdef FCHDIR_REPLACEMENT
440 /* gnulib internal function. */
441 extern void _gl_unregister_fd (int fd);
450 #endif /* _GL_UNISTD_H */
451 #endif /* _GL_UNISTD_H */