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. */
22 # if @HAVE_INCLUDE_NEXT@
23 # include_next <unistd.h>
25 # include @ABSOLUTE_UNISTD_H@
29 /* mingw doesn't define the SEEK_* macros in <unistd.h>. */
30 #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
34 /* mingw fails to declare _exit in <unistd.h>. */
37 /* The definition of GL_LINK_WARNING is copied here. */
40 /* Declare overridden functions. */
49 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
50 to GID (if GID is not -1).
51 Return 0 if successful, otherwise -1 and errno set.
52 See the POSIX:2001 specification
53 <http://www.opengroup.org/susv3xsh/chown.html>. */
54 # define chown rpl_chown
55 extern int chown (const char *file
, uid_t uid
, gid_t gid
);
57 #elif defined GNULIB_POSIXCHECK
59 # define chown(f,u,g) \
60 (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
61 "doesn't treat a uid or gid of -1 on some systems - " \
62 "use gnulib module chown for portability"), \
69 /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
70 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
71 Return 0 if successful, otherwise -1 and errno set.
72 See the POSIX:2001 specification
73 <http://www.opengroup.org/susv3xsh/dup2.html>. */
74 extern int dup2 (int oldfd
, int newfd
);
76 #elif defined GNULIB_POSIXCHECK
79 (GL_LINK_WARNING ("dup2 is unportable - " \
80 "use gnulib module dup2 for portability"), \
88 /* Change the process' current working directory to the directory on which
89 the given file descriptor is open.
90 Return 0 if successful, otherwise -1 and errno set.
91 See the POSIX:2001 specification
92 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
93 extern int fchdir (int /*fd*/);
95 # define close rpl_close
96 extern int close (int);
99 # define dup2 rpl_dup2
100 extern int dup2 (int, int);
103 #elif defined GNULIB_POSIXCHECK
106 (GL_LINK_WARNING ("fchdir is unportable - " \
107 "use gnulib module fchdir for portability"), \
112 #if @GNULIB_FTRUNCATE@
113 # if !@HAVE_FTRUNCATE@
114 /* Change the size of the file to which FD is opened to become equal to LENGTH.
115 Return 0 if successful, otherwise -1 and errno set.
116 See the POSIX:2001 specification
117 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
118 extern int ftruncate (int fd
, off_t length
);
120 #elif defined GNULIB_POSIXCHECK
122 # define ftruncate(f,l) \
123 (GL_LINK_WARNING ("ftruncate is unportable - " \
124 "use gnulib module ftruncate for portability"), \
130 /* Include the headers that might declare getcwd so that they will not
131 cause confusion if included after this file. */
133 # if @REPLACE_GETCWD@
134 /* Get the name of the current working directory, and put it in SIZE bytes
136 Return BUF if successful, or NULL if the directory couldn't be determined
137 or SIZE was too small.
138 See the POSIX:2001 specification
139 <http://www.opengroup.org/susv3xsh/getcwd.html>.
140 Additionally, the gnulib module 'getcwd' guarantees the following GNU
141 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
142 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
144 # define getcwd rpl_getcwd
145 extern char * getcwd (char *buf
, size_t size
);
147 #elif defined GNULIB_POSIXCHECK
149 # define getcwd(b,s) \
150 (GL_LINK_WARNING ("getcwd is unportable - " \
151 "use gnulib module getcwd for portability"), \
156 #if @GNULIB_GETLOGIN_R@
157 /* Copies the user's login name to NAME.
158 The array pointed to by NAME has room for SIZE bytes.
160 Returns 0 if successful. Upon error, an error number is returned, or -1 in
161 the case that the login name cannot be found but no specific error is
162 provided (this case is hopefully rare but is left open by the POSIX spec).
164 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
166 # if !@HAVE_DECL_GETLOGIN_R@
168 extern int getlogin_r (char *name
, size_t size
);
170 #elif defined GNULIB_POSIXCHECK
172 # define getlogin_r(n,s) \
173 (GL_LINK_WARNING ("getlogin_r is unportable - " \
174 "use gnulib module getlogin_r for portability"), \
179 #if @GNULIB_READLINK@
180 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
181 bytes of it into BUF. Return the number of bytes placed into BUF if
182 successful, otherwise -1 and errno set.
183 See the POSIX:2001 specification
184 <http://www.opengroup.org/susv3xsh/readlink.html>. */
185 # if !@HAVE_READLINK@
187 extern int readlink (const char *file
, char *buf
, size_t bufsize
);
189 #elif defined GNULIB_POSIXCHECK
191 # define readlink(f,b,s) \
192 (GL_LINK_WARNING ("readlink is unportable - " \
193 "use gnulib module readlink for portability"), \
199 /* Pause the execution of the current thread for N seconds.
200 Returns the number of seconds left to sleep.
201 See the POSIX:2001 specification
202 <http://www.opengroup.org/susv3xsh/sleep.html>. */
204 extern unsigned int sleep (unsigned int n
);
206 #elif defined GNULIB_POSIXCHECK
209 (GL_LINK_WARNING ("sleep is unportable - " \
210 "use gnulib module sleep for portability"), \
220 #endif /* _GL_UNISTD_H */