Update PGP key.
[shishi.git] / gl / unistd_.h
blobf34bc66c1763bba7f0fa3ef91ce106c51b1b6f43
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)
7 any later version.
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. */
18 #ifndef _GL_UNISTD_H
20 /* The include_next requires a split double-inclusion guard. */
21 #if @HAVE_UNISTD_H@
22 # if @HAVE_INCLUDE_NEXT@
23 # include_next <unistd.h>
24 # else
25 # include @ABSOLUTE_UNISTD_H@
26 # endif
27 #endif
29 #ifndef _GL_UNISTD_H
30 #define _GL_UNISTD_H
32 /* mingw doesn't define the SEEK_* macros in <unistd.h>. */
33 #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
34 # include <stdio.h>
35 #endif
37 /* mingw fails to declare _exit in <unistd.h>. */
38 #include <stdlib.h>
40 /* The definition of GL_LINK_WARNING is copied here. */
43 /* Declare overridden functions. */
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
50 #if @GNULIB_CHOWN@
51 # if @REPLACE_CHOWN@
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);
59 # endif
60 #elif defined GNULIB_POSIXCHECK
61 # undef chown
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"), \
66 chown (f, u, g))
67 #endif
70 #if @GNULIB_DUP2@
71 # if !@HAVE_DUP2@
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);
78 # endif
79 #elif defined GNULIB_POSIXCHECK
80 # undef dup2
81 # define dup2(o,n) \
82 (GL_LINK_WARNING ("dup2 is unportable - " \
83 "use gnulib module dup2 for portability"), \
84 dup2 (o, n))
85 #endif
88 #if @GNULIB_FCHDIR@
89 # if @REPLACE_FCHDIR@
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);
100 # define dup rpl_dup
101 extern int dup (int);
102 # define dup2 rpl_dup2
103 extern int dup2 (int, int);
105 # endif
106 #elif defined GNULIB_POSIXCHECK
107 # undef fchdir
108 # define fchdir(f) \
109 (GL_LINK_WARNING ("fchdir is unportable - " \
110 "use gnulib module fchdir for portability"), \
111 fchdir (f))
112 #endif
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);
122 # endif
123 #elif defined GNULIB_POSIXCHECK
124 # undef ftruncate
125 # define ftruncate(f,l) \
126 (GL_LINK_WARNING ("ftruncate is unportable - " \
127 "use gnulib module ftruncate for portability"), \
128 ftruncate (f, l))
129 #endif
132 #if @GNULIB_GETCWD@
133 /* Include the headers that might declare getcwd so that they will not
134 cause confusion if included after this file. */
135 # include <stdlib.h>
136 # if @REPLACE_GETCWD@
137 /* Get the name of the current working directory, and put it in SIZE bytes
138 of BUF.
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
146 necessary. */
147 # define getcwd rpl_getcwd
148 extern char * getcwd (char *buf, size_t size);
149 # endif
150 #elif defined GNULIB_POSIXCHECK
151 # undef getcwd
152 # define getcwd(b,s) \
153 (GL_LINK_WARNING ("getcwd is unportable - " \
154 "use gnulib module getcwd for portability"), \
155 getcwd (b, s))
156 #endif
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@
170 # include <stddef.h>
171 extern int getlogin_r (char *name, size_t size);
172 # endif
173 #elif defined GNULIB_POSIXCHECK
174 # undef getlogin_r
175 # define getlogin_r(n,s) \
176 (GL_LINK_WARNING ("getlogin_r is unportable - " \
177 "use gnulib module getlogin_r for portability"), \
178 getlogin_r (n, s))
179 #endif
182 #if @GNULIB_LSEEK@
183 # if @REPLACE_LSEEK@
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);
190 # endif
191 #elif defined GNULIB_POSIXCHECK
192 # undef lseek
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"), \
196 lseek (f, o, w))
197 #endif
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@
207 # include <stddef.h>
208 extern int readlink (const char *file, char *buf, size_t bufsize);
209 # endif
210 #elif defined GNULIB_POSIXCHECK
211 # undef readlink
212 # define readlink(f,b,s) \
213 (GL_LINK_WARNING ("readlink is unportable - " \
214 "use gnulib module readlink for portability"), \
215 readlink (f, b, s))
216 #endif
219 #if @GNULIB_SLEEP@
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>. */
224 # if !@HAVE_SLEEP@
225 extern unsigned int sleep (unsigned int n);
226 # endif
227 #elif defined GNULIB_POSIXCHECK
228 # undef sleep
229 # define sleep(n) \
230 (GL_LINK_WARNING ("sleep is unportable - " \
231 "use gnulib module sleep for portability"), \
232 sleep (n))
233 #endif
236 #ifdef __cplusplus
238 #endif
241 #endif /* _GL_UNISTD_H */
242 #endif /* _GL_UNISTD_H */