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 /* Automatically included by modules that need a replacement for close. */
82 # define close rpl_close
83 extern int close (int);
85 #elif @UNISTD_H_HAVE_WINSOCK2_H@
87 # define close close_used_without_requesting_gnulib_module_close
88 #elif defined GNULIB_POSIXCHECK
91 (GL_LINK_WARNING ("close does not portably work on sockets - " \
92 "use gnulib module close for portability"), \
99 /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
100 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
101 Return 0 if successful, otherwise -1 and errno set.
102 See the POSIX:2001 specification
103 <http://www.opengroup.org/susv3xsh/dup2.html>. */
104 extern int dup2 (int oldfd, int newfd);
106 #elif defined GNULIB_POSIXCHECK
109 (GL_LINK_WARNING ("dup2 is unportable - " \
110 "use gnulib module dup2 for portability"), \
116 # if !@HAVE_DECL_ENVIRON@
117 /* Set of environment variables and values. An array of strings of the form
118 "VARIABLE=VALUE", terminated with a NULL. */
119 # if defined __APPLE__ && defined __MACH__
120 # include <crt_externs.h>
121 # define environ (*_NSGetEnviron ())
123 extern char **environ;
126 #elif defined GNULIB_POSIXCHECK
129 (GL_LINK_WARNING ("environ is unportable - " \
130 "use gnulib module environ for portability"), \
136 # if @REPLACE_FCHDIR@
138 /* Change the process' current working directory to the directory on which
139 the given file descriptor is open.
140 Return 0 if successful, otherwise -1 and errno set.
141 See the POSIX:2001 specification
142 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
143 extern int fchdir (int /*fd*/);
146 extern int dup (int);
147 # define dup2 rpl_dup2
148 extern int dup2 (int, int);
151 #elif defined GNULIB_POSIXCHECK
154 (GL_LINK_WARNING ("fchdir is unportable - " \
155 "use gnulib module fchdir for portability"), \
161 /* Synchronize changes to a file.
162 Return 0 if successful, otherwise -1 and errno set.
163 See POSIX:2001 specification
164 <http://www.opengroup.org/susv3xsh/fsync.html>. */
166 extern int fsync (int fd);
168 #elif defined GNULIB_POSIXCHECK
171 (GL_LINK_WARNING ("fsync is unportable - " \
172 "use gnulib module fsync for portability"), \
177 #if @GNULIB_FTRUNCATE@
178 # if !@HAVE_FTRUNCATE@
179 /* Change the size of the file to which FD is opened to become equal to LENGTH.
180 Return 0 if successful, otherwise -1 and errno set.
181 See the POSIX:2001 specification
182 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
183 extern int ftruncate (int fd, off_t length);
185 #elif defined GNULIB_POSIXCHECK
187 # define ftruncate(f,l) \
188 (GL_LINK_WARNING ("ftruncate is unportable - " \
189 "use gnulib module ftruncate for portability"), \
195 /* Include the headers that might declare getcwd so that they will not
196 cause confusion if included after this file. */
198 # if @REPLACE_GETCWD@
199 /* Get the name of the current working directory, and put it in SIZE bytes
201 Return BUF if successful, or NULL if the directory couldn't be determined
202 or SIZE was too small.
203 See the POSIX:2001 specification
204 <http://www.opengroup.org/susv3xsh/getcwd.html>.
205 Additionally, the gnulib module 'getcwd' guarantees the following GNU
206 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
207 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
209 # define getcwd rpl_getcwd
210 extern char * getcwd (char *buf, size_t size);
212 #elif defined GNULIB_POSIXCHECK
214 # define getcwd(b,s) \
215 (GL_LINK_WARNING ("getcwd is unportable - " \
216 "use gnulib module getcwd for portability"), \
221 #if @GNULIB_GETDTABLESIZE@
222 # if !@HAVE_GETDTABLESIZE@
223 /* Return the maximum number of file descriptors in the current process. */
224 extern int getdtablesize (void);
226 #elif defined GNULIB_POSIXCHECK
227 # undef getdtablesize
228 # define getdtablesize() \
229 (GL_LINK_WARNING ("getdtablesize is unportable - " \
230 "use gnulib module getdtablesize for portability"), \
235 #if @GNULIB_GETLOGIN_R@
236 /* Copies the user's login name to NAME.
237 The array pointed to by NAME has room for SIZE bytes.
239 Returns 0 if successful. Upon error, an error number is returned, or -1 in
240 the case that the login name cannot be found but no specific error is
241 provided (this case is hopefully rare but is left open by the POSIX spec).
243 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
245 # if !@HAVE_DECL_GETLOGIN_R@
247 extern int getlogin_r (char *name, size_t size);
249 #elif defined GNULIB_POSIXCHECK
251 # define getlogin_r(n,s) \
252 (GL_LINK_WARNING ("getlogin_r is unportable - " \
253 "use gnulib module getlogin_r for portability"), \
258 #if @GNULIB_GETPAGESIZE@
259 # if @REPLACE_GETPAGESIZE@
260 # define getpagesize rpl_getpagesize
261 extern int getpagesize (void);
262 # elif !@HAVE_GETPAGESIZE@
263 /* This is for POSIX systems. */
264 # if !defined getpagesize && defined _SC_PAGESIZE
265 # if ! (defined __VMS && __VMS_VER < 70000000)
266 # define getpagesize() sysconf (_SC_PAGESIZE)
269 /* This is for older VMS. */
270 # if !defined getpagesize && defined __VMS
272 # define getpagesize() 8192
274 # define getpagesize() 512
277 /* This is for BeOS. */
278 # if !defined getpagesize && @HAVE_OS_H@
280 # if defined B_PAGE_SIZE
281 # define getpagesize() B_PAGE_SIZE
284 /* This is for AmigaOS4.0. */
285 # if !defined getpagesize && defined __amigaos4__
286 # define getpagesize() 2048
288 /* This is for older Unix systems. */
289 # if !defined getpagesize && @HAVE_SYS_PARAM_H@
290 # include <sys/param.h>
291 # ifdef EXEC_PAGESIZE
292 # define getpagesize() EXEC_PAGESIZE
298 # define getpagesize() (NBPG * CLSIZE)
301 # define getpagesize() NBPC
307 #elif defined GNULIB_POSIXCHECK
309 # define getpagesize() \
310 (GL_LINK_WARNING ("getpagesize is unportable - " \
311 "use gnulib module getpagesize for portability"), \
317 # if @REPLACE_LCHOWN@
318 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
319 to GID (if GID is not -1). Do not follow symbolic links.
320 Return 0 if successful, otherwise -1 and errno set.
321 See the POSIX:2001 specification
322 <http://www.opengroup.org/susv3xsh/lchown.html>. */
323 # define lchown rpl_lchown
324 extern int lchown (char const *file, uid_t owner, gid_t group);
326 #elif defined GNULIB_POSIXCHECK
328 # define lchown(f,u,g) \
329 (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
330 "systems - use gnulib module lchown for portability"), \
337 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
338 Return the new offset if successful, otherwise -1 and errno set.
339 See the POSIX:2001 specification
340 <http://www.opengroup.org/susv3xsh/lseek.html>. */
341 # define lseek rpl_lseek
342 extern off_t lseek (int fd, off_t offset, int whence);
344 #elif defined GNULIB_POSIXCHECK
346 # define lseek(f,o,w) \
347 (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
348 "systems - use gnulib module lseek for portability"), \
353 #if @GNULIB_READLINK@
354 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
355 bytes of it into BUF. Return the number of bytes placed into BUF if
356 successful, otherwise -1 and errno set.
357 See the POSIX:2001 specification
358 <http://www.opengroup.org/susv3xsh/readlink.html>. */
359 # if !@HAVE_READLINK@
361 extern int readlink (const char *file, char *buf, size_t bufsize);
363 #elif defined GNULIB_POSIXCHECK
365 # define readlink(f,b,s) \
366 (GL_LINK_WARNING ("readlink is unportable - " \
367 "use gnulib module readlink for portability"), \
373 /* Pause the execution of the current thread for N seconds.
374 Returns the number of seconds left to sleep.
375 See the POSIX:2001 specification
376 <http://www.opengroup.org/susv3xsh/sleep.html>. */
378 extern unsigned int sleep (unsigned int n);
380 #elif defined GNULIB_POSIXCHECK
383 (GL_LINK_WARNING ("sleep is unportable - " \
384 "use gnulib module sleep for portability"), \
389 #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
390 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
391 See the POSIX:2001 specification
392 <http://www.opengroup.org/susv3xsh/write.html>. */
394 # define write rpl_write
395 extern ssize_t write (int fd, const void *buf, size_t count);
399 #ifdef FCHDIR_REPLACEMENT
400 /* gnulib internal function. */
401 extern void _gl_unregister_fd (int fd);
410 #endif /* _GL_UNISTD_H */
411 #endif /* _GL_UNISTD_H */