1 /* Substitute for and wrapper around <unistd.h>.
2 Copyright (C) 2004-2007 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 /* The include_next requires a split double-inclusion guard. */
22 # if @HAVE_INCLUDE_NEXT@
23 # include_next <unistd.h>
25 # include @ABSOLUTE_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 /* The definition of GL_LINK_WARNING is copied here. */
43 /* Declare overridden functions. */
52 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
53 to GID (if GID is not -1).
54 Return 0 if successful, otherwise -1 and errno set.
55 See the POSIX:2001 specification
56 <http://www.opengroup.org/susv3xsh/chown.html>. */
57 # define chown rpl_chown
58 extern int chown (const char *file, uid_t uid, gid_t gid);
60 #elif defined GNULIB_POSIXCHECK
62 # define chown(f,u,g) \
63 (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
64 "doesn't treat a uid or gid of -1 on some systems - " \
65 "use gnulib module chown for portability"), \
72 /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
73 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
74 Return 0 if successful, otherwise -1 and errno set.
75 See the POSIX:2001 specification
76 <http://www.opengroup.org/susv3xsh/dup2.html>. */
77 extern int dup2 (int oldfd, int newfd);
79 #elif defined GNULIB_POSIXCHECK
82 (GL_LINK_WARNING ("dup2 is unportable - " \
83 "use gnulib module dup2 for portability"), \
91 /* Change the process' current working directory to the directory on which
92 the given file descriptor is open.
93 Return 0 if successful, otherwise -1 and errno set.
94 See the POSIX:2001 specification
95 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
96 extern int fchdir (int /*fd*/);
98 # define close rpl_close
99 extern int close (int);
101 extern int dup (int);
102 # define dup2 rpl_dup2
103 extern int dup2 (int, int);
106 #elif defined GNULIB_POSIXCHECK
109 (GL_LINK_WARNING ("fchdir is unportable - " \
110 "use gnulib module fchdir for portability"), \
115 #if @GNULIB_FTRUNCATE@
116 # if !@HAVE_FTRUNCATE@
117 /* Change the size of the file to which FD is opened to become equal to LENGTH.
118 Return 0 if successful, otherwise -1 and errno set.
119 See the POSIX:2001 specification
120 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
121 extern int ftruncate (int fd, off_t length);
123 #elif defined GNULIB_POSIXCHECK
125 # define ftruncate(f,l) \
126 (GL_LINK_WARNING ("ftruncate is unportable - " \
127 "use gnulib module ftruncate for portability"), \
133 /* Include the headers that might declare getcwd so that they will not
134 cause confusion if included after this file. */
136 # if @REPLACE_GETCWD@
137 /* Get the name of the current working directory, and put it in SIZE bytes
139 Return BUF if successful, or NULL if the directory couldn't be determined
140 or SIZE was too small.
141 See the POSIX:2001 specification
142 <http://www.opengroup.org/susv3xsh/getcwd.html>.
143 Additionally, the gnulib module 'getcwd' guarantees the following GNU
144 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
145 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
147 # define getcwd rpl_getcwd
148 extern char * getcwd (char *buf, size_t size);
150 #elif defined GNULIB_POSIXCHECK
152 # define getcwd(b,s) \
153 (GL_LINK_WARNING ("getcwd is unportable - " \
154 "use gnulib module getcwd for portability"), \
159 #if @GNULIB_GETLOGIN_R@
160 /* Copies the user's login name to NAME.
161 The array pointed to by NAME has room for SIZE bytes.
163 Returns 0 if successful. Upon error, an error number is returned, or -1 in
164 the case that the login name cannot be found but no specific error is
165 provided (this case is hopefully rare but is left open by the POSIX spec).
167 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
169 # if !@HAVE_DECL_GETLOGIN_R@
171 extern int getlogin_r (char *name, size_t size);
173 #elif defined GNULIB_POSIXCHECK
175 # define getlogin_r(n,s) \
176 (GL_LINK_WARNING ("getlogin_r is unportable - " \
177 "use gnulib module getlogin_r for portability"), \
184 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
185 Return the new offset if successful, otherwise -1 and errno set.
186 See the POSIX:2001 specification
187 <http://www.opengroup.org/susv3xsh/lseek.html>. */
188 # define lseek rpl_lseek
189 extern off_t lseek (int fd, off_t offset, int whence);
191 #elif defined GNULIB_POSIXCHECK
193 # define lseek(f,o,w) \
194 (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
195 "systems - use gnulib module lseek for portability"), \
200 #if @GNULIB_READLINK@
201 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
202 bytes of it into BUF. Return the number of bytes placed into BUF if
203 successful, otherwise -1 and errno set.
204 See the POSIX:2001 specification
205 <http://www.opengroup.org/susv3xsh/readlink.html>. */
206 # if !@HAVE_READLINK@
208 extern int readlink (const char *file, char *buf, size_t bufsize);
210 #elif defined GNULIB_POSIXCHECK
212 # define readlink(f,b,s) \
213 (GL_LINK_WARNING ("readlink is unportable - " \
214 "use gnulib module readlink for portability"), \
220 /* Pause the execution of the current thread for N seconds.
221 Returns the number of seconds left to sleep.
222 See the POSIX:2001 specification
223 <http://www.opengroup.org/susv3xsh/sleep.html>. */
225 extern unsigned int sleep (unsigned int n);
227 #elif defined GNULIB_POSIXCHECK
230 (GL_LINK_WARNING ("sleep is unportable - " \
231 "use gnulib module sleep for portability"), \
241 #endif /* _GL_UNISTD_H */
242 #endif /* _GL_UNISTD_H */