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. */
20 @PRAGMA_SYSTEM_HEADER@
22 /* The include_next requires a split double-inclusion guard. */
24 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
30 /* mingw doesn't define the SEEK_* macros in <unistd.h>. */
31 #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
35 /* mingw fails to declare _exit in <unistd.h>. */
38 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
40 # include <sys/types.h>
43 /* The definition of GL_LINK_WARNING is copied here. */
46 /* Declare overridden functions. */
55 # ifndef REPLACE_CHOWN
56 # define REPLACE_CHOWN 1
59 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
60 to GID (if GID is not -1). Follow symbolic links.
61 Return 0 if successful, otherwise -1 and errno set.
62 See the POSIX:2001 specification
63 <http://www.opengroup.org/susv3xsh/chown.html>. */
64 # define chown rpl_chown
65 extern int chown (const char *file, uid_t uid, gid_t gid);
68 #elif defined GNULIB_POSIXCHECK
70 # define chown(f,u,g) \
71 (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
72 "doesn't treat a uid or gid of -1 on some systems - " \
73 "use gnulib module chown for portability"), \
80 /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
81 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
82 Return 0 if successful, otherwise -1 and errno set.
83 See the POSIX:2001 specification
84 <http://www.opengroup.org/susv3xsh/dup2.html>. */
85 extern int dup2 (int oldfd, int newfd);
87 #elif defined GNULIB_POSIXCHECK
90 (GL_LINK_WARNING ("dup2 is unportable - " \
91 "use gnulib module dup2 for portability"), \
97 # if !@HAVE_DECL_ENVIRON@
98 /* Set of environment variables and values. An array of strings of the form
99 "VARIABLE=VALUE", terminated with a NULL. */
100 # if defined __APPLE__ && defined __MACH__
101 # include <crt_externs.h>
102 # define environ (*_NSGetEnviron ())
104 extern char **environ;
107 #elif defined GNULIB_POSIXCHECK
110 (GL_LINK_WARNING ("environ is unportable - " \
111 "use gnulib module environ for portability"), \
117 # if @REPLACE_FCHDIR@
119 /* Change the process' current working directory to the directory on which
120 the given file descriptor is open.
121 Return 0 if successful, otherwise -1 and errno set.
122 See the POSIX:2001 specification
123 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
124 extern int fchdir (int /*fd*/);
126 # define close rpl_close
127 extern int close (int);
129 extern int dup (int);
130 # define dup2 rpl_dup2
131 extern int dup2 (int, int);
134 #elif defined GNULIB_POSIXCHECK
137 (GL_LINK_WARNING ("fchdir is unportable - " \
138 "use gnulib module fchdir for portability"), \
144 /* Synchronize changes to a file.
145 Return 0 if successful, otherwise -1 and errno set.
146 See POSIX:2001 specification
147 <http://www.opengroup.org/susv3xsh/fsync.html>. */
149 extern int fsync (int fd);
151 #elif defined GNULIB_POSIXCHECK
154 (GL_LINK_WARNING ("fsync is unportable - " \
155 "use gnulib module fsync for portability"), \
160 #if @GNULIB_FTRUNCATE@
161 # if !@HAVE_FTRUNCATE@
162 /* Change the size of the file to which FD is opened to become equal to LENGTH.
163 Return 0 if successful, otherwise -1 and errno set.
164 See the POSIX:2001 specification
165 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
166 extern int ftruncate (int fd, off_t length);
168 #elif defined GNULIB_POSIXCHECK
170 # define ftruncate(f,l) \
171 (GL_LINK_WARNING ("ftruncate is unportable - " \
172 "use gnulib module ftruncate for portability"), \
178 /* Include the headers that might declare getcwd so that they will not
179 cause confusion if included after this file. */
181 # if @REPLACE_GETCWD@
182 /* Get the name of the current working directory, and put it in SIZE bytes
184 Return BUF if successful, or NULL if the directory couldn't be determined
185 or SIZE was too small.
186 See the POSIX:2001 specification
187 <http://www.opengroup.org/susv3xsh/getcwd.html>.
188 Additionally, the gnulib module 'getcwd' guarantees the following GNU
189 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
190 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
192 # define getcwd rpl_getcwd
193 extern char * getcwd (char *buf, size_t size);
195 #elif defined GNULIB_POSIXCHECK
197 # define getcwd(b,s) \
198 (GL_LINK_WARNING ("getcwd is unportable - " \
199 "use gnulib module getcwd for portability"), \
204 #if @GNULIB_GETLOGIN_R@
205 /* Copies the user's login name to NAME.
206 The array pointed to by NAME has room for SIZE bytes.
208 Returns 0 if successful. Upon error, an error number is returned, or -1 in
209 the case that the login name cannot be found but no specific error is
210 provided (this case is hopefully rare but is left open by the POSIX spec).
212 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
214 # if !@HAVE_DECL_GETLOGIN_R@
216 extern int getlogin_r (char *name, size_t size);
218 #elif defined GNULIB_POSIXCHECK
220 # define getlogin_r(n,s) \
221 (GL_LINK_WARNING ("getlogin_r is unportable - " \
222 "use gnulib module getlogin_r for portability"), \
227 #if @GNULIB_GETPAGESIZE@
228 # if @REPLACE_GETPAGESIZE@
229 # define getpagesize rpl_getpagesize
230 extern int getpagesize (void);
231 # elif !@HAVE_GETPAGESIZE@
232 /* This is for POSIX systems. */
233 # if !defined getpagesize && defined _SC_PAGESIZE
234 # if ! (defined __VMS && __VMS_VER < 70000000)
235 # define getpagesize() sysconf (_SC_PAGESIZE)
238 /* This is for older VMS. */
239 # if !defined getpagesize && defined __VMS
241 # define getpagesize() 8192
243 # define getpagesize() 512
246 /* This is for BeOS. */
247 # if !defined getpagesize && @HAVE_OS_H@
249 # if defined B_PAGE_SIZE
250 # define getpagesize() B_PAGE_SIZE
253 /* This is for AmigaOS4.0. */
254 # if !defined getpagesize && defined __amigaos4__
255 # define getpagesize() 2048
257 /* This is for older Unix systems. */
258 # if !defined getpagesize && @HAVE_SYS_PARAM_H@
259 # include <sys/param.h>
260 # ifdef EXEC_PAGESIZE
261 # define getpagesize() EXEC_PAGESIZE
267 # define getpagesize() (NBPG * CLSIZE)
270 # define getpagesize() NBPC
276 #elif defined GNULIB_POSIXCHECK
278 # define getpagesize() \
279 (GL_LINK_WARNING ("getpagesize is unportable - " \
280 "use gnulib module getpagesize for portability"), \
286 # if @REPLACE_LCHOWN@
287 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
288 to GID (if GID is not -1). Do not follow symbolic links.
289 Return 0 if successful, otherwise -1 and errno set.
290 See the POSIX:2001 specification
291 <http://www.opengroup.org/susv3xsh/lchown.html>. */
292 # define lchown rpl_lchown
293 extern int lchown (char const *file, uid_t owner, gid_t group);
295 #elif defined GNULIB_POSIXCHECK
297 # define lchown(f,u,g) \
298 (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
299 "systems - use gnulib module lchown for portability"), \
306 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
307 Return the new offset if successful, otherwise -1 and errno set.
308 See the POSIX:2001 specification
309 <http://www.opengroup.org/susv3xsh/lseek.html>. */
310 # define lseek rpl_lseek
311 extern off_t lseek (int fd, off_t offset, int whence);
313 #elif defined GNULIB_POSIXCHECK
315 # define lseek(f,o,w) \
316 (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
317 "systems - use gnulib module lseek for portability"), \
322 #if @GNULIB_READLINK@
323 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
324 bytes of it into BUF. Return the number of bytes placed into BUF if
325 successful, otherwise -1 and errno set.
326 See the POSIX:2001 specification
327 <http://www.opengroup.org/susv3xsh/readlink.html>. */
328 # if !@HAVE_READLINK@
330 extern int readlink (const char *file, char *buf, size_t bufsize);
332 #elif defined GNULIB_POSIXCHECK
334 # define readlink(f,b,s) \
335 (GL_LINK_WARNING ("readlink is unportable - " \
336 "use gnulib module readlink for portability"), \
342 /* Pause the execution of the current thread for N seconds.
343 Returns the number of seconds left to sleep.
344 See the POSIX:2001 specification
345 <http://www.opengroup.org/susv3xsh/sleep.html>. */
347 extern unsigned int sleep (unsigned int n);
349 #elif defined GNULIB_POSIXCHECK
352 (GL_LINK_WARNING ("sleep is unportable - " \
353 "use gnulib module sleep for portability"), \
358 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
359 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
360 See the POSIX:2001 specification
361 <http://www.opengroup.org/susv3xsh/write.html>. */
363 # define write rpl_write
364 extern ssize_t write (int fd, const void *buf, size_t count);
373 #endif /* _GL_UNISTD_H */
374 #endif /* _GL_UNISTD_H */