]> sjero.net Git - wget/blob - lib/unistd.in.h
Automated merge.
[wget] / lib / unistd.in.h
1 /* Substitute for and wrapper around <unistd.h>.
2    Copyright (C) 2004-2008 Free Software Foundation, Inc.
3
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)
7    any later version.
8
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.
13
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.  */
17
18 #ifndef _GL_UNISTD_H
19
20 /* The include_next requires a split double-inclusion guard.  */
21 #if @HAVE_UNISTD_H@
22 # @INCLUDE_NEXT@ @NEXT_UNISTD_H@
23 #endif
24
25 #ifndef _GL_UNISTD_H
26 #define _GL_UNISTD_H
27
28 /* mingw doesn't define the SEEK_* macros in <unistd.h>.  */
29 #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
30 # include <stdio.h>
31 #endif
32
33 /* mingw fails to declare _exit in <unistd.h>.  */
34 #include <stdlib.h>
35
36 /* The definition of GL_LINK_WARNING is copied here.  */
37
38
39 /* Declare overridden functions.  */
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45
46 #if @GNULIB_CHOWN@
47 # if @REPLACE_CHOWN@
48 #  ifndef REPLACE_CHOWN
49 #   define REPLACE_CHOWN 1
50 #  endif
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).  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);
59 #  endif
60 # endif
61 #elif defined GNULIB_POSIXCHECK
62 # undef chown
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"), \
67      chown (f, u, g))
68 #endif
69
70
71 #if @GNULIB_DUP2@
72 # if !@HAVE_DUP2@
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);
79 # endif
80 #elif defined GNULIB_POSIXCHECK
81 # undef dup2
82 # define dup2(o,n) \
83     (GL_LINK_WARNING ("dup2 is unportable - " \
84                       "use gnulib module dup2 for portability"), \
85      dup2 (o, n))
86 #endif
87
88
89 #if @GNULIB_ENVIRON@
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 ())
96 #  else
97 extern char **environ;
98 #  endif
99 # endif
100 #elif defined GNULIB_POSIXCHECK
101 # undef environ
102 # define environ \
103     (GL_LINK_WARNING ("environ is unportable - " \
104                       "use gnulib module environ for portability"), \
105      environ)
106 #endif
107
108
109 #if @GNULIB_FCHDIR@
110 # if @REPLACE_FCHDIR@
111
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*/);
118
119 #  define close rpl_close
120 extern int close (int);
121 #  define dup rpl_dup
122 extern int dup (int);
123 #  define dup2 rpl_dup2
124 extern int dup2 (int, int);
125
126 # endif
127 #elif defined GNULIB_POSIXCHECK
128 # undef fchdir
129 # define fchdir(f) \
130     (GL_LINK_WARNING ("fchdir is unportable - " \
131                       "use gnulib module fchdir for portability"), \
132      fchdir (f))
133 #endif
134
135
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);
143 # endif
144 #elif defined GNULIB_POSIXCHECK
145 # undef ftruncate
146 # define ftruncate(f,l) \
147     (GL_LINK_WARNING ("ftruncate is unportable - " \
148                       "use gnulib module ftruncate for portability"), \
149      ftruncate (f, l))
150 #endif
151
152
153 #if @GNULIB_GETCWD@
154 /* Include the headers that might declare getcwd so that they will not
155    cause confusion if included after this file.  */
156 # include <stdlib.h>
157 # if @REPLACE_GETCWD@
158 /* Get the name of the current working directory, and put it in SIZE bytes
159    of BUF.
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
167    necessary.  */
168 #  define getcwd rpl_getcwd
169 extern char * getcwd (char *buf, size_t size);
170 # endif
171 #elif defined GNULIB_POSIXCHECK
172 # undef getcwd
173 # define getcwd(b,s) \
174     (GL_LINK_WARNING ("getcwd is unportable - " \
175                       "use gnulib module getcwd for portability"), \
176      getcwd (b, s))
177 #endif
178
179
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.
183
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).
187
188    See <http://www.opengroup.org/susv3xsh/getlogin.html>.
189  */
190 # if !@HAVE_DECL_GETLOGIN_R@
191 #  include <stddef.h>
192 extern int getlogin_r (char *name, size_t size);
193 # endif
194 #elif defined GNULIB_POSIXCHECK
195 # undef getlogin_r
196 # define getlogin_r(n,s) \
197     (GL_LINK_WARNING ("getlogin_r is unportable - " \
198                       "use gnulib module getlogin_r for portability"), \
199      getlogin_r (n, s))
200 #endif
201
202
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)
212 #   endif
213 #  endif
214 /* This is for older VMS.  */
215 #  if !defined getpagesize && defined __VMS
216 #   ifdef __ALPHA
217 #    define getpagesize() 8192
218 #   else
219 #    define getpagesize() 512
220 #   endif
221 #  endif
222 /* This is for BeOS.  */
223 #  if !defined getpagesize && @HAVE_OS_H@
224 #   include <OS.h>
225 #   if defined B_PAGE_SIZE
226 #    define getpagesize() B_PAGE_SIZE
227 #   endif
228 #  endif
229 /* This is for AmigaOS4.0.  */
230 #  if !defined getpagesize && defined __amigaos4__
231 #   define getpagesize() 2048
232 #  endif
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
238 #   else
239 #    ifdef NBPG
240 #     ifndef CLSIZE
241 #      define CLSIZE 1
242 #     endif
243 #     define getpagesize() (NBPG * CLSIZE)
244 #    else
245 #     ifdef NBPC
246 #      define getpagesize() NBPC
247 #     endif
248 #    endif
249 #   endif
250 #  endif
251 # endif
252 #elif defined GNULIB_POSIXCHECK
253 # undef getpagesize
254 # define getpagesize() \
255     (GL_LINK_WARNING ("getpagesize is unportable - " \
256                       "use gnulib module getpagesize for portability"), \
257      getpagesize ())
258 #endif
259
260
261 #if @GNULIB_LCHOWN@
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);
270 # endif
271 #elif defined GNULIB_POSIXCHECK
272 # undef lchown
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"), \
276      lchown (f, u, g))
277 #endif
278
279
280 #if @GNULIB_LSEEK@
281 # if @REPLACE_LSEEK@
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);
288 # endif
289 #elif defined GNULIB_POSIXCHECK
290 # undef lseek
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"), \
294      lseek (f, o, w))
295 #endif
296
297
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@
305 #  include <stddef.h>
306 extern int readlink (const char *file, char *buf, size_t bufsize);
307 # endif
308 #elif defined GNULIB_POSIXCHECK
309 # undef readlink
310 # define readlink(f,b,s) \
311     (GL_LINK_WARNING ("readlink is unportable - " \
312                       "use gnulib module readlink for portability"), \
313      readlink (f, b, s))
314 #endif
315
316
317 #if @GNULIB_SLEEP@
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>.  */
322 # if !@HAVE_SLEEP@
323 extern unsigned int sleep (unsigned int n);
324 # endif
325 #elif defined GNULIB_POSIXCHECK
326 # undef sleep
327 # define sleep(n) \
328     (GL_LINK_WARNING ("sleep is unportable - " \
329                       "use gnulib module sleep for portability"), \
330      sleep (n))
331 #endif
332
333
334 #ifdef __cplusplus
335 }
336 #endif
337
338
339 #endif /* _GL_UNISTD_H */
340 #endif /* _GL_UNISTD_H */