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"), \
138 # if @REPLACE_FCHDIR@
140 /* Change the process' current working directory to the directory on which
141 the given file descriptor is open.
142 Return 0 if successful, otherwise -1 and errno set.
143 See the POSIX:2001 specification
144 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
145 extern int fchdir (int /*fd*/);
148 extern int dup (int);
149 # define dup2 rpl_dup2
150 extern int dup2 (int, int);
153 #elif defined GNULIB_POSIXCHECK
156 (GL_LINK_WARNING ("fchdir is unportable - " \
157 "use gnulib module fchdir for portability"), \
163 /* Synchronize changes to a file.
164 Return 0 if successful, otherwise -1 and errno set.
165 See POSIX:2001 specification
166 <http://www.opengroup.org/susv3xsh/fsync.html>. */
168 extern int fsync (int fd);
170 #elif defined GNULIB_POSIXCHECK
173 (GL_LINK_WARNING ("fsync is unportable - " \
174 "use gnulib module fsync for portability"), \
179 #if @GNULIB_FTRUNCATE@
180 # if !@HAVE_FTRUNCATE@
181 /* Change the size of the file to which FD is opened to become equal to LENGTH.
182 Return 0 if successful, otherwise -1 and errno set.
183 See the POSIX:2001 specification
184 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
185 extern int ftruncate (int fd, off_t length);
187 #elif defined GNULIB_POSIXCHECK
189 # define ftruncate(f,l) \
190 (GL_LINK_WARNING ("ftruncate is unportable - " \
191 "use gnulib module ftruncate for portability"), \
197 /* Include the headers that might declare getcwd so that they will not
198 cause confusion if included after this file. */
200 # if @REPLACE_GETCWD@
201 /* Get the name of the current working directory, and put it in SIZE bytes
203 Return BUF if successful, or NULL if the directory couldn't be determined
204 or SIZE was too small.
205 See the POSIX:2001 specification
206 <http://www.opengroup.org/susv3xsh/getcwd.html>.
207 Additionally, the gnulib module 'getcwd' guarantees the following GNU
208 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
209 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
211 # define getcwd rpl_getcwd
212 extern char * getcwd (char *buf, size_t size);
214 #elif defined GNULIB_POSIXCHECK
216 # define getcwd(b,s) \
217 (GL_LINK_WARNING ("getcwd is unportable - " \
218 "use gnulib module getcwd for portability"), \
223 #if @GNULIB_GETDOMAINNAME@
224 /* Return the NIS domain name of the machine.
225 WARNING! The NIS domain name is unrelated to the fully qualified host name
226 of the machine. It is also unrelated to email addresses.
227 WARNING! The NIS domain name is usually the empty string or "(none)" when
230 Put up to LEN bytes of the NIS domain name into NAME.
231 Null terminate it if the name is shorter than LEN.
232 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
233 Return 0 if successful, otherwise set errno and return -1. */
234 # if !@HAVE_GETDOMAINNAME@
235 extern int getdomainname(char *name, size_t len);
237 #elif defined GNULIB_POSIXCHECK
238 # undef getdomainname
239 # define getdomainname(n,l) \
240 (GL_LINK_WARNING ("getdomainname is unportable - " \
241 "use gnulib module getdomainname for portability"), \
242 getdomainname (n, l))
246 #if @GNULIB_GETDTABLESIZE@
247 # if !@HAVE_GETDTABLESIZE@
248 /* Return the maximum number of file descriptors in the current process. */
249 extern int getdtablesize (void);
251 #elif defined GNULIB_POSIXCHECK
252 # undef getdtablesize
253 # define getdtablesize() \
254 (GL_LINK_WARNING ("getdtablesize is unportable - " \
255 "use gnulib module getdtablesize for portability"), \
260 #if @GNULIB_GETLOGIN_R@
261 /* Copies the user's login name to NAME.
262 The array pointed to by NAME has room for SIZE bytes.
264 Returns 0 if successful. Upon error, an error number is returned, or -1 in
265 the case that the login name cannot be found but no specific error is
266 provided (this case is hopefully rare but is left open by the POSIX spec).
268 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
270 # if !@HAVE_DECL_GETLOGIN_R@
272 extern int getlogin_r (char *name, size_t size);
274 #elif defined GNULIB_POSIXCHECK
276 # define getlogin_r(n,s) \
277 (GL_LINK_WARNING ("getlogin_r is unportable - " \
278 "use gnulib module getlogin_r for portability"), \
283 #if @GNULIB_GETPAGESIZE@
284 # if @REPLACE_GETPAGESIZE@
285 # define getpagesize rpl_getpagesize
286 extern int getpagesize (void);
287 # elif !@HAVE_GETPAGESIZE@
288 /* This is for POSIX systems. */
289 # if !defined getpagesize && defined _SC_PAGESIZE
290 # if ! (defined __VMS && __VMS_VER < 70000000)
291 # define getpagesize() sysconf (_SC_PAGESIZE)
294 /* This is for older VMS. */
295 # if !defined getpagesize && defined __VMS
297 # define getpagesize() 8192
299 # define getpagesize() 512
302 /* This is for BeOS. */
303 # if !defined getpagesize && @HAVE_OS_H@
305 # if defined B_PAGE_SIZE
306 # define getpagesize() B_PAGE_SIZE
309 /* This is for AmigaOS4.0. */
310 # if !defined getpagesize && defined __amigaos4__
311 # define getpagesize() 2048
313 /* This is for older Unix systems. */
314 # if !defined getpagesize && @HAVE_SYS_PARAM_H@
315 # include <sys/param.h>
316 # ifdef EXEC_PAGESIZE
317 # define getpagesize() EXEC_PAGESIZE
323 # define getpagesize() (NBPG * CLSIZE)
326 # define getpagesize() NBPC
332 #elif defined GNULIB_POSIXCHECK
334 # define getpagesize() \
335 (GL_LINK_WARNING ("getpagesize is unportable - " \
336 "use gnulib module getpagesize for portability"), \
342 # if @REPLACE_LCHOWN@
343 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
344 to GID (if GID is not -1). Do not follow symbolic links.
345 Return 0 if successful, otherwise -1 and errno set.
346 See the POSIX:2001 specification
347 <http://www.opengroup.org/susv3xsh/lchown.html>. */
348 # define lchown rpl_lchown
349 extern int lchown (char const *file, uid_t owner, gid_t group);
351 #elif defined GNULIB_POSIXCHECK
353 # define lchown(f,u,g) \
354 (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
355 "systems - use gnulib module lchown for portability"), \
362 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
363 Return the new offset if successful, otherwise -1 and errno set.
364 See the POSIX:2001 specification
365 <http://www.opengroup.org/susv3xsh/lseek.html>. */
366 # define lseek rpl_lseek
367 extern off_t lseek (int fd, off_t offset, int whence);
369 #elif defined GNULIB_POSIXCHECK
371 # define lseek(f,o,w) \
372 (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
373 "systems - use gnulib module lseek for portability"), \
378 #if @GNULIB_READLINK@
379 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
380 bytes of it into BUF. Return the number of bytes placed into BUF if
381 successful, otherwise -1 and errno set.
382 See the POSIX:2001 specification
383 <http://www.opengroup.org/susv3xsh/readlink.html>. */
384 # if !@HAVE_READLINK@
386 extern int readlink (const char *file, char *buf, size_t bufsize);
388 #elif defined GNULIB_POSIXCHECK
390 # define readlink(f,b,s) \
391 (GL_LINK_WARNING ("readlink is unportable - " \
392 "use gnulib module readlink for portability"), \
398 /* Pause the execution of the current thread for N seconds.
399 Returns the number of seconds left to sleep.
400 See the POSIX:2001 specification
401 <http://www.opengroup.org/susv3xsh/sleep.html>. */
403 extern unsigned int sleep (unsigned int n);
405 #elif defined GNULIB_POSIXCHECK
408 (GL_LINK_WARNING ("sleep is unportable - " \
409 "use gnulib module sleep for portability"), \
414 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
415 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
416 See the POSIX:2001 specification
417 <http://www.opengroup.org/susv3xsh/write.html>. */
419 # define write rpl_write
420 extern ssize_t write (int fd, const void *buf, size_t count);
424 #ifdef FCHDIR_REPLACEMENT
425 /* gnulib internal function. */
426 extern void _gl_unregister_fd (int fd);
435 #endif /* _GL_UNISTD_H */
436 #endif /* _GL_UNISTD_H */