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 # include @ABSOLUTE_UNISTD_H@
25 /* mingw doesn't define the SEEK_* macros in <unistd.h>. */
26 #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
30 /* mingw fails to declare _exit in <unistd.h>. */
33 /* The definition of GL_LINK_WARNING is copied here. */
36 /* Declare overridden functions. */
45 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
46 to GID (if GID is not -1).
47 Return 0 if successful, otherwise -1 and errno set.
48 See the POSIX:2001 specification
49 <http://www.opengroup.org/susv3xsh/chown.html>. */
50 # define chown rpl_chown
51 extern int chown (const char *file, uid_t uid, gid_t gid);
53 #elif defined GNULIB_POSIXCHECK
55 # define chown(f,u,g) \
56 (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
57 "doesn't treat a uid or gid of -1 on some systems - " \
58 "use gnulib module chown for portability"), \
65 /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
66 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
67 Return 0 if successful, otherwise -1 and errno set.
68 See the POSIX:2001 specification
69 <http://www.opengroup.org/susv3xsh/dup2.html>. */
70 extern int dup2 (int oldfd, int newfd);
72 #elif defined GNULIB_POSIXCHECK
75 (GL_LINK_WARNING ("dup2 is unportable - " \
76 "use gnulib module dup2 for portability"), \
84 /* Change the process' current working directory to the directory on which
85 the given file descriptor is open.
86 Return 0 if successful, otherwise -1 and errno set.
87 See the POSIX:2001 specification
88 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
89 extern int fchdir (int /*fd*/);
91 # define close rpl_close
92 extern int close (int);
95 # define dup2 rpl_dup2
96 extern int dup2 (int, int);
99 #elif defined GNULIB_POSIXCHECK
102 (GL_LINK_WARNING ("fchdir is unportable - " \
103 "use gnulib module fchdir for portability"), \
108 #if @GNULIB_FTRUNCATE@
109 # if !@HAVE_FTRUNCATE@
110 /* Change the size of the file to which FD is opened to become equal to LENGTH.
111 Return 0 if successful, otherwise -1 and errno set.
112 See the POSIX:2001 specification
113 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
114 extern int ftruncate (int fd, off_t length);
116 #elif defined GNULIB_POSIXCHECK
118 # define ftruncate(f,l) \
119 (GL_LINK_WARNING ("ftruncate is unportable - " \
120 "use gnulib module ftruncate for portability"), \
126 /* Include the headers that might declare getcwd so that they will not
127 cause confusion if included after this file. */
129 # if @REPLACE_GETCWD@
130 /* Get the name of the current working directory, and put it in SIZE bytes
132 Return BUF if successful, or NULL if the directory couldn't be determined
133 or SIZE was too small.
134 See the POSIX:2001 specification
135 <http://www.opengroup.org/susv3xsh/getcwd.html>.
136 Additionally, the gnulib module 'getcwd' guarantees the following GNU
137 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
138 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
140 # define getcwd rpl_getcwd
141 extern char * getcwd (char *buf, size_t size);
143 #elif defined GNULIB_POSIXCHECK
145 # define getcwd(b,s) \
146 (GL_LINK_WARNING ("getcwd is unportable - " \
147 "use gnulib module getcwd for portability"), \
152 #if @GNULIB_GETLOGIN_R@
153 /* Copies the user's login name to NAME.
154 The array pointed to by NAME has room for SIZE bytes.
156 Returns 0 if successful. Upon error, an error number is returned, or -1 in
157 the case that the login name cannot be found but no specific error is
158 provided (this case is hopefully rare but is left open by the POSIX spec).
160 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
162 # if !@HAVE_DECL_GETLOGIN_R@
164 extern int getlogin_r (char *name, size_t size);
166 #elif defined GNULIB_POSIXCHECK
168 # define getlogin_r(n,s) \
169 (GL_LINK_WARNING ("getlogin_r is unportable - " \
170 "use gnulib module getlogin_r for portability"), \
175 #if @GNULIB_READLINK@
176 /* Read the contents of the symbolic link FILE and place the first BUFSIZE
177 bytes of it into BUF. Return the number of bytes placed into BUF if
178 successful, otherwise -1 and errno set.
179 See the POSIX:2001 specification
180 <http://www.opengroup.org/susv3xsh/readlink.html>. */
181 # if !@HAVE_READLINK@
183 extern int readlink (const char *file, char *buf, size_t bufsize);
185 #elif defined GNULIB_POSIXCHECK
187 # define readlink(f,b,s) \
188 (GL_LINK_WARNING ("readlink is unportable - " \
189 "use gnulib module readlink for portability"), \
195 /* Pause the execution of the current thread for N seconds.
196 Returns the number of seconds left to sleep.
197 See the POSIX:2001 specification
198 <http://www.opengroup.org/susv3xsh/sleep.html>. */
200 extern unsigned int sleep (unsigned int n);
202 #elif defined GNULIB_POSIXCHECK
205 (GL_LINK_WARNING ("sleep is unportable - " \
206 "use gnulib module sleep for portability"), \
216 #endif /* _GL_UNISTD_H */