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 Lesser 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 Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser 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"), \
90
# if !@HAVE_DECL_ENVIRON@
91
/* Set of environment variables and values. An array of strings of the form
92
"VARIABLE=VALUE", terminated with a NULL. */
93
# if defined __APPLE__ && defined __MACH__
94
# include <crt_externs.h>
95
# define environ (*_NSGetEnviron ())
97
extern char **environ;
100
#elif defined GNULIB_POSIXCHECK
103
(GL_LINK_WARNING ("environ is unportable - " \
104
"use gnulib module environ for portability"), \
110
# if @REPLACE_FCHDIR@
112
/* Change the process' current working directory to the directory on which
113
the given file descriptor is open.
114
Return 0 if successful, otherwise -1 and errno set.
115
See the POSIX:2001 specification
116
<http://www.opengroup.org/susv3xsh/fchdir.html>. */
117
extern int fchdir (int /*fd*/);
119
# define close rpl_close
120
extern int close (int);
122
extern int dup (int);
123
# define dup2 rpl_dup2
124
extern int dup2 (int, int);
127
#elif defined GNULIB_POSIXCHECK
130
(GL_LINK_WARNING ("fchdir is unportable - " \
131
"use gnulib module fchdir for portability"), \
136
#if @GNULIB_FTRUNCATE@
137
# if !@HAVE_FTRUNCATE@
138
/* Change the size of the file to which FD is opened to become equal to LENGTH.
139
Return 0 if successful, otherwise -1 and errno set.
140
See the POSIX:2001 specification
141
<http://www.opengroup.org/susv3xsh/ftruncate.html>. */
142
extern int ftruncate (int fd, off_t length);
144
#elif defined GNULIB_POSIXCHECK
146
# define ftruncate(f,l) \
147
(GL_LINK_WARNING ("ftruncate is unportable - " \
148
"use gnulib module ftruncate for portability"), \
154
/* Include the headers that might declare getcwd so that they will not
155
cause confusion if included after this file. */
157
# if @REPLACE_GETCWD@
158
/* Get the name of the current working directory, and put it in SIZE bytes
160
Return BUF if successful, or NULL if the directory couldn't be determined
161
or SIZE was too small.
162
See the POSIX:2001 specification
163
<http://www.opengroup.org/susv3xsh/getcwd.html>.
164
Additionally, the gnulib module 'getcwd' guarantees the following GNU
165
extension: If BUF is NULL, an array is allocated with 'malloc'; the array
166
is SIZE bytes long, unless SIZE == 0, in which case it is as big as
168
# define getcwd rpl_getcwd
169
extern char * getcwd (char *buf, size_t size);
171
#elif defined GNULIB_POSIXCHECK
173
# define getcwd(b,s) \
174
(GL_LINK_WARNING ("getcwd is unportable - " \
175
"use gnulib module getcwd for portability"), \
180
#if @GNULIB_GETLOGIN_R@
181
/* Copies the user's login name to NAME.
182
The array pointed to by NAME has room for SIZE bytes.
184
Returns 0 if successful. Upon error, an error number is returned, or -1 in
185
the case that the login name cannot be found but no specific error is
186
provided (this case is hopefully rare but is left open by the POSIX spec).
188
See <http://www.opengroup.org/susv3xsh/getlogin.html>.
190
# if !@HAVE_DECL_GETLOGIN_R@
192
extern int getlogin_r (char *name, size_t size);
194
#elif defined GNULIB_POSIXCHECK
196
# define getlogin_r(n,s) \
197
(GL_LINK_WARNING ("getlogin_r is unportable - " \
198
"use gnulib module getlogin_r for portability"), \
203
#if @GNULIB_GETPAGESIZE@
204
# if @REPLACE_GETPAGESIZE@
205
# define getpagesize rpl_getpagesize
206
extern int getpagesize (void);
207
# elif !@HAVE_GETPAGESIZE@
208
/* This is for POSIX systems. */
209
# if !defined getpagesize && defined _SC_PAGESIZE
210
# if ! (defined __VMS && __VMS_VER < 70000000)
211
# define getpagesize() sysconf (_SC_PAGESIZE)
214
/* This is for older VMS. */
215
# if !defined getpagesize && defined __VMS
217
# define getpagesize() 8192
219
# define getpagesize() 512
222
/* This is for BeOS. */
223
# if !defined getpagesize && @HAVE_OS_H@
225
# if defined B_PAGE_SIZE
226
# define getpagesize() B_PAGE_SIZE
229
/* This is for AmigaOS4.0. */
230
# if !defined getpagesize && defined __amigaos4__
231
# define getpagesize() 2048
233
/* This is for older Unix systems. */
234
# if !defined getpagesize && @HAVE_SYS_PARAM_H@
235
# include <sys/param.h>
236
# ifdef EXEC_PAGESIZE
237
# define getpagesize() EXEC_PAGESIZE
243
# define getpagesize() (NBPG * CLSIZE)
246
# define getpagesize() NBPC
252
#elif defined GNULIB_POSIXCHECK
254
# define getpagesize() \
255
(GL_LINK_WARNING ("getpagesize is unportable - " \
256
"use gnulib module getpagesize for portability"), \
262
# if @REPLACE_LCHOWN@
263
/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
264
to GID (if GID is not -1). Do not follow symbolic links.
265
Return 0 if successful, otherwise -1 and errno set.
266
See the POSIX:2001 specification
267
<http://www.opengroup.org/susv3xsh/lchown.html>. */
268
# define lchown rpl_lchown
269
extern int lchown (char const *file, uid_t owner, gid_t group);
271
#elif defined GNULIB_POSIXCHECK
273
# define lchown(f,u,g) \
274
(GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
275
"systems - use gnulib module lchown for portability"), \
282
/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
283
Return the new offset if successful, otherwise -1 and errno set.
284
See the POSIX:2001 specification
285
<http://www.opengroup.org/susv3xsh/lseek.html>. */
286
# define lseek rpl_lseek
287
extern off_t lseek (int fd, off_t offset, int whence);
289
#elif defined GNULIB_POSIXCHECK
291
# define lseek(f,o,w) \
292
(GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
293
"systems - use gnulib module lseek for portability"), \
298
#if @GNULIB_READLINK@
299
/* Read the contents of the symbolic link FILE and place the first BUFSIZE
300
bytes of it into BUF. Return the number of bytes placed into BUF if
301
successful, otherwise -1 and errno set.
302
See the POSIX:2001 specification
303
<http://www.opengroup.org/susv3xsh/readlink.html>. */
304
# if !@HAVE_READLINK@
306
extern int readlink (const char *file, char *buf, size_t bufsize);
308
#elif defined GNULIB_POSIXCHECK
310
# define readlink(f,b,s) \
311
(GL_LINK_WARNING ("readlink is unportable - " \
312
"use gnulib module readlink for portability"), \
318
/* Pause the execution of the current thread for N seconds.
319
Returns the number of seconds left to sleep.
320
See the POSIX:2001 specification
321
<http://www.opengroup.org/susv3xsh/sleep.html>. */
323
extern unsigned int sleep (unsigned int n);
325
#elif defined GNULIB_POSIXCHECK
328
(GL_LINK_WARNING ("sleep is unportable - " \
329
"use gnulib module sleep for portability"), \
339
#endif /* _GL_UNISTD_H */
340
#endif /* _GL_UNISTD_H */