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 3, 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 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
28 /* mingw doesn't define the SEEK_* macros in <unistd.h>. */
29 #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
33 /* mingw fails to declare _exit in <unistd.h>. */
36 /* The definition of GL_LINK_WARNING is copied here. */
39 /* Declare overridden functions. */
48 # ifndef REPLACE_CHOWN
49 # define REPLACE_CHOWN 1
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). Follow symbolic links.
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
);
61 #elif defined GNULIB_POSIXCHECK
63 # define chown(f,u,g) \
64 (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
65 "doesn't treat a uid or gid of -1 on some systems - " \
66 "use gnulib module chown for portability"), \
73 /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
74 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
75 Return 0 if successful, otherwise -1 and errno set.
76 See the POSIX:2001 specification
77 <http://www.opengroup.org/susv3xsh/dup2.html>. */
78 extern int dup2 (int oldfd
, int newfd
);
80 #elif defined GNULIB_POSIXCHECK
83 (GL_LINK_WARNING ("dup2 is unportable - " \
84 "use gnulib module dup2 for portability"), \
92 /* Change the process' current working directory to the directory on which
93 the given file descriptor is open.
94 Return 0 if successful, otherwise -1 and errno set.
95 See the POSIX:2001 specification
96 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
97 extern int fchdir (int /*fd*/);
99 # define close rpl_close
100 extern int close (int);
102 extern int dup (int);
103 # define dup2 rpl_dup2
104 extern int dup2 (int, int);
107 #elif defined GNULIB_POSIXCHECK
110 (GL_LINK_WARNING ("fchdir is unportable - " \
111 "use gnulib module fchdir for portability"), \
116 #if @GNULIB_FTRUNCATE@
117 # if !@HAVE_FTRUNCATE@
118 /* Change the size of the file to which FD is opened to become equal to LENGTH.
119 Return 0 if successful, otherwise -1 and errno set.
120 See the POSIX:2001 specification
121 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
122 extern int ftruncate (int fd
, off_t length
);
124 #elif defined GNULIB_POSIXCHECK
126 # define ftruncate(f,l) \
127 (GL_LINK_WARNING ("ftruncate is unportable - " \
128 "use gnulib module ftruncate for portability"), \
134 /* Include the headers that might declare getcwd so that they will not
135 cause confusion if included after this file. */
137 # if @REPLACE_GETCWD@
138 /* Get the name of the current working directory, and put it in SIZE bytes
140 Return BUF if successful, or NULL if the directory couldn't be determined
141 or SIZE was too small.
142 See the POSIX:2001 specification
143 <http://www.opengroup.org/susv3xsh/getcwd.html>.
144 Additionally, the gnulib module 'getcwd' guarantees the following GNU
145 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
146 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
148 # define getcwd rpl_getcwd
149 extern char * getcwd (char *buf
, size_t size
);
151 #elif defined GNULIB_POSIXCHECK
153 # define getcwd(b,s) \
154 (GL_LINK_WARNING ("getcwd is unportable - " \
155 "use gnulib module getcwd for portability"), \
159 #if @GNULIB_GETHOSTNAME@
160 # if !@HAVE_DECL_GETHOSTNAME@
162 extern int gethostname (char *name
, size_t size
);
164 #elif defined GNULIB_POSIXCHECK
166 # define gethostname(n,s) \
167 (GL_LINK_WARNING ("gethostname is unportable - " \
168 "use gnulib module gethostname for portability"), \
172 #if @GNULIB_GETLOGIN_R@
173 /* Copies the user's login name to NAME.
174 The array pointed to by NAME has room for SIZE bytes.
176 Returns 0 if successful. Upon error, an error number is returned, or -1 in
177 the case that the login name cannot be found but no specific error is
178 provided (this case is hopefully rare but is left open by the POSIX spec).
180 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
182 # if !@HAVE_DECL_GETLOGIN_R@
184 extern int getlogin_r (char *name
, size_t size
);
186 #elif defined GNULIB_POSIXCHECK
188 # define getlogin_r(n,s) \
189 (GL_LINK_WARNING ("getlogin_r is unportable - " \
190 "use gnulib module getlogin_r for portability"), \
195 #if @GNULIB_GETPAGESIZE@
196 # if @REPLACE_GETPAGESIZE@
197 # define getpagesize rpl_getpagesize
198 extern int getpagesize (void);
199 # elif !@HAVE_GETPAGESIZE@
200 /* This is for POSIX systems. */
201 # if !defined getpagesize && defined _SC_PAGESIZE
202 # if ! (defined __VMS && __VMS_VER < 70000000)
203 # define getpagesize() sysconf (_SC_PAGESIZE)
206 /* This is for older VMS. */
207 # if !defined getpagesize && defined __VMS
209 # define getpagesize() 8192
211 # define getpagesize() 512
214 /* This is for BeOS. */
215 # if !defined getpagesize && @HAVE_OS_H@
217 # if defined B_PAGE_SIZE
218 # define getpagesize() B_PAGE_SIZE
221 /* This is for AmigaOS4.0. */
222 # if !defined getpagesize && defined __amigaos4__
223 # define getpagesize() 2048
225 /* This is for older Unix systems. */
226 # if !defined getpagesize && @HAVE_SYS_PARAM_H@
227 # include <sys/param.h>
228 # ifdef EXEC_PAGESIZE
229 # define getpagesize() EXEC_PAGESIZE
235 # define getpagesize() (NBPG * CLSIZE)
238 # define getpagesize() NBPC
244 #elif defined GNULIB_POSIXCHECK
246 # define getpagesize() \
247 (GL_LINK_WARNING ("getpagesize is unportable - " \
248 "use gnulib module getpagesize for portability"), \
254 # if @REPLACE_LCHOWN@
255 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
256 to GID (if GID is not -1). Do not follow symbolic links.
257 Return 0 if successful, otherwise -1 and errno set.
258 See the POSIX:2001 specification
259 <http://www.opengroup.org/susv3xsh/lchown.html>. */
260 # define lchown rpl_lchown
261 extern int lchown (char const *file
, uid_t owner
, gid_t group
);
263 #elif defined GNULIB_POSIXCHECK
265 # define lchown(f,u,g) \
266 (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
267 "systems - use gnulib module lchown for portability"), \
274 /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
275 Return the new offset if successful, otherwise -1 and errno set.
276 See the POSIX:2001 specification
277 <http://www.opengroup.org/susv3xsh/lseek.html>. */
278 # define lseek rpl_lseek
279 extern off_t
lseek (int fd
, off_t offset
, int whence
);
281 #elif defined GNULIB_POSIXCHECK
283 # define lseek(f,o,w) \
284 (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
285 "systems - use gnulib module lseek for portability"), \
290 #if @GNULIB_READLINK@
291 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
292 bytes of it into BUF. Return the number of bytes placed into BUF if
293 successful, otherwise -1 and errno set.
294 See the POSIX:2001 specification
295 <http://www.opengroup.org/susv3xsh/readlink.html>. */
296 # if !@HAVE_READLINK@
298 extern int readlink (const char *file
, char *buf
, size_t bufsize
);
300 #elif defined GNULIB_POSIXCHECK
302 # define readlink(f,b,s) \
303 (GL_LINK_WARNING ("readlink is unportable - " \
304 "use gnulib module readlink for portability"), \
310 /* Pause the execution of the current thread for N seconds.
311 Returns the number of seconds left to sleep.
312 See the POSIX:2001 specification
313 <http://www.opengroup.org/susv3xsh/sleep.html>. */
315 extern unsigned int sleep (unsigned int n
);
317 #elif defined GNULIB_POSIXCHECK
320 (GL_LINK_WARNING ("sleep is unportable - " \
321 "use gnulib module sleep for portability"), \
331 #endif /* _GL_UNISTD_H */
332 #endif /* _GL_UNISTD_H */