1 /* Substitute for and wrapper around <unistd.h>.
2 Copyright (C) 2004-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_GETDTABLESIZE@
224 # if !@HAVE_GETDTABLESIZE@
225 /* Return the maximum number of file descriptors in the current process. */
226 extern int getdtablesize (void);
228 #elif defined GNULIB_POSIXCHECK
229 # undef getdtablesize
230 # define getdtablesize() \
231 (GL_LINK_WARNING ("getdtablesize is unportable - " \
232 "use gnulib module getdtablesize for portability"), \
237 #if @GNULIB_GETLOGIN_R@
238 /* Copies the user's login name to NAME.
239 The array pointed to by NAME has room for SIZE bytes.
241 Returns 0 if successful. Upon error, an error number is returned, or -1 in
242 the case that the login name cannot be found but no specific error is
243 provided (this case is hopefully rare but is left open by the POSIX spec).
245 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
247 # if !@HAVE_DECL_GETLOGIN_R@
249 extern int getlogin_r (char *name, size_t size);
251 #elif defined GNULIB_POSIXCHECK
253 # define getlogin_r(n,s) \
254 (GL_LINK_WARNING ("getlogin_r is unportable - " \
255 "use gnulib module getlogin_r for portability"), \
260 #if @GNULIB_GETPAGESIZE@
261 # if @REPLACE_GETPAGESIZE@
262 # define getpagesize rpl_getpagesize
263 extern int getpagesize (void);
264 # elif !@HAVE_GETPAGESIZE@
265 /* This is for POSIX systems. */
266 # if !defined getpagesize && defined _SC_PAGESIZE
267 # if ! (defined __VMS && __VMS_VER < 70000000)
268 # define getpagesize() sysconf (_SC_PAGESIZE)
271 /* This is for older VMS. */
272 # if !defined getpagesize && defined __VMS
274 # define getpagesize() 8192
276 # define getpagesize() 512
279 /* This is for BeOS. */
280 # if !defined getpagesize && @HAVE_OS_H@
282 # if defined B_PAGE_SIZE
283 # define getpagesize() B_PAGE_SIZE
286 /* This is for AmigaOS4.0. */
287 # if !defined getpagesize && defined __amigaos4__
288 # define getpagesize() 2048
290 /* This is for older Unix systems. */
291 # if !defined getpagesize && @HAVE_SYS_PARAM_H@
292 # include <sys/param.h>
293 # ifdef EXEC_PAGESIZE
294 # define getpagesize() EXEC_PAGESIZE
300 # define getpagesize() (NBPG * CLSIZE)
303 # define getpagesize() NBPC
309 #elif defined GNULIB_POSIXCHECK
311 # define getpagesize() \
312 (GL_LINK_WARNING ("getpagesize is unportable - " \
313 "use gnulib module getpagesize for portability"), \
319 # if @REPLACE_LCHOWN@
320 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
321 to GID (if GID is not -1). Do not follow symbolic links.
322 Return 0 if successful, otherwise -1 and errno set.
323 See the POSIX:2001 specification
324 <http://www.opengroup.org/susv3xsh/lchown.html>. */
325 # define lchown rpl_lchown
326 extern int lchown (char const *file, uid_t owner, gid_t group);
328 #elif defined GNULIB_POSIXCHECK
330 # define lchown(f,u,g) \
331 (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
332 "systems - use gnulib module lchown for portability"), \
339 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
340 Return the new offset if successful, otherwise -1 and errno set.
341 See the POSIX:2001 specification
342 <http://www.opengroup.org/susv3xsh/lseek.html>. */
343 # define lseek rpl_lseek
344 extern off_t lseek (int fd, off_t offset, int whence);
346 #elif defined GNULIB_POSIXCHECK
348 # define lseek(f,o,w) \
349 (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
350 "systems - use gnulib module lseek for portability"), \
355 #if @GNULIB_READLINK@
356 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
357 bytes of it into BUF. Return the number of bytes placed into BUF if
358 successful, otherwise -1 and errno set.
359 See the POSIX:2001 specification
360 <http://www.opengroup.org/susv3xsh/readlink.html>. */
361 # if !@HAVE_READLINK@
363 extern int readlink (const char *file, char *buf, size_t bufsize);
365 #elif defined GNULIB_POSIXCHECK
367 # define readlink(f,b,s) \
368 (GL_LINK_WARNING ("readlink is unportable - " \
369 "use gnulib module readlink for portability"), \
375 /* Pause the execution of the current thread for N seconds.
376 Returns the number of seconds left to sleep.
377 See the POSIX:2001 specification
378 <http://www.opengroup.org/susv3xsh/sleep.html>. */
380 extern unsigned int sleep (unsigned int n);
382 #elif defined GNULIB_POSIXCHECK
385 (GL_LINK_WARNING ("sleep is unportable - " \
386 "use gnulib module sleep for portability"), \
391 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
392 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
393 See the POSIX:2001 specification
394 <http://www.opengroup.org/susv3xsh/write.html>. */
396 # define write rpl_write
397 extern ssize_t write (int fd, const void *buf, size_t count);
401 #ifdef FCHDIR_REPLACEMENT
402 /* gnulib internal function. */
403 extern void _gl_unregister_fd (int fd);
412 #endif /* _GL_UNISTD_H */
413 #endif /* _GL_UNISTD_H */