Commit | Line | Data |
---|---|---|
9b36a80c | 1 | /* Substitute for and wrapper around <unistd.h>. |
f240aacb | 2 | Copyright (C) 2003-2009 Free Software Foundation, Inc. |
9b36a80c LC |
3 | |
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) | |
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 Lesser General Public License for more details. | |
13 | ||
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. */ | |
17 | ||
18 | #ifndef _GL_UNISTD_H | |
19 | ||
20 | #if __GNUC__ >= 3 | |
21 | @PRAGMA_SYSTEM_HEADER@ | |
22 | #endif | |
23 | ||
24 | /* The include_next requires a split double-inclusion guard. */ | |
25 | #if @HAVE_UNISTD_H@ | |
26 | # @INCLUDE_NEXT@ @NEXT_UNISTD_H@ | |
27 | #endif | |
28 | ||
29 | #ifndef _GL_UNISTD_H | |
30 | #define _GL_UNISTD_H | |
31 | ||
8912421c LC |
32 | /* NetBSD 5.0 mis-defines NULL. Also get size_t. */ |
33 | #include <stddef.h> | |
34 | ||
f240aacb | 35 | /* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */ |
9b36a80c LC |
36 | #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) |
37 | # include <stdio.h> | |
38 | #endif | |
39 | ||
40 | /* mingw fails to declare _exit in <unistd.h>. */ | |
4a462e35 | 41 | /* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */ |
9b36a80c LC |
42 | #include <stdlib.h> |
43 | ||
8912421c LC |
44 | #if ((@GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@) \ |
45 | || (@GNULIB_READLINK@ && (!@HAVE_READLINK@ || @REPLACE_READLINK@)) \ | |
46 | || (@GNULIB_READLINKAT@ && !@HAVE_READLINKAT@)) | |
9b36a80c LC |
47 | /* Get ssize_t. */ |
48 | # include <sys/types.h> | |
49 | #endif | |
50 | ||
8912421c LC |
51 | /* Get getopt(), optarg, optind, opterr, optopt. */ |
52 | #if @GNULIB_UNISTD_H_GETOPT@ && !defined _GL_SYSTEM_GETOPT | |
53 | # include <getopt.h> | |
54 | #endif | |
55 | ||
9b36a80c LC |
56 | #if @GNULIB_GETHOSTNAME@ |
57 | /* Get all possible declarations of gethostname(). */ | |
58 | # if @UNISTD_H_HAVE_WINSOCK2_H@ | |
59 | # include <winsock2.h> | |
60 | # if !defined _GL_SYS_SOCKET_H | |
61 | # undef socket | |
62 | # define socket socket_used_without_including_sys_socket_h | |
63 | # undef connect | |
64 | # define connect connect_used_without_including_sys_socket_h | |
65 | # undef accept | |
66 | # define accept accept_used_without_including_sys_socket_h | |
67 | # undef bind | |
68 | # define bind bind_used_without_including_sys_socket_h | |
69 | # undef getpeername | |
70 | # define getpeername getpeername_used_without_including_sys_socket_h | |
71 | # undef getsockname | |
72 | # define getsockname getsockname_used_without_including_sys_socket_h | |
73 | # undef getsockopt | |
74 | # define getsockopt getsockopt_used_without_including_sys_socket_h | |
75 | # undef listen | |
76 | # define listen listen_used_without_including_sys_socket_h | |
77 | # undef recv | |
78 | # define recv recv_used_without_including_sys_socket_h | |
79 | # undef send | |
80 | # define send send_used_without_including_sys_socket_h | |
81 | # undef recvfrom | |
82 | # define recvfrom recvfrom_used_without_including_sys_socket_h | |
83 | # undef sendto | |
84 | # define sendto sendto_used_without_including_sys_socket_h | |
85 | # undef setsockopt | |
86 | # define setsockopt setsockopt_used_without_including_sys_socket_h | |
87 | # undef shutdown | |
88 | # define shutdown shutdown_used_without_including_sys_socket_h | |
89 | # endif | |
90 | # if !defined _GL_SYS_SELECT_H | |
91 | # undef select | |
92 | # define select select_used_without_including_sys_select_h | |
93 | # endif | |
94 | # endif | |
95 | #endif | |
96 | ||
97 | /* The definition of GL_LINK_WARNING is copied here. */ | |
98 | ||
99 | ||
f240aacb LC |
100 | /* OS/2 EMX lacks these macros. */ |
101 | #ifndef STDIN_FILENO | |
102 | # define STDIN_FILENO 0 | |
103 | #endif | |
104 | #ifndef STDOUT_FILENO | |
105 | # define STDOUT_FILENO 1 | |
106 | #endif | |
107 | #ifndef STDERR_FILENO | |
108 | # define STDERR_FILENO 2 | |
109 | #endif | |
110 | ||
8912421c LC |
111 | /* Ensure *_OK macros exist. */ |
112 | #ifndef F_OK | |
113 | # define F_OK 0 | |
114 | # define X_OK 1 | |
115 | # define W_OK 2 | |
116 | # define R_OK 4 | |
117 | #endif | |
118 | ||
119 | ||
9b36a80c LC |
120 | /* Declare overridden functions. */ |
121 | ||
122 | #ifdef __cplusplus | |
123 | extern "C" { | |
124 | #endif | |
125 | ||
126 | ||
127 | #if @GNULIB_CHOWN@ | |
128 | # if @REPLACE_CHOWN@ | |
f29ded4b LC |
129 | # undef chown |
130 | # define chown rpl_chown | |
131 | # endif | |
132 | # if !@HAVE_CHOWN@ || @REPLACE_CHOWN@ | |
9b36a80c LC |
133 | /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE |
134 | to GID (if GID is not -1). Follow symbolic links. | |
135 | Return 0 if successful, otherwise -1 and errno set. | |
136 | See the POSIX:2001 specification | |
137 | <http://www.opengroup.org/susv3xsh/chown.html>. */ | |
9b36a80c | 138 | extern int chown (const char *file, uid_t uid, gid_t gid); |
9b36a80c LC |
139 | # endif |
140 | #elif defined GNULIB_POSIXCHECK | |
141 | # undef chown | |
142 | # define chown(f,u,g) \ | |
143 | (GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \ | |
144 | "doesn't treat a uid or gid of -1 on some systems - " \ | |
145 | "use gnulib module chown for portability"), \ | |
146 | chown (f, u, g)) | |
147 | #endif | |
148 | ||
149 | ||
150 | #if @GNULIB_CLOSE@ | |
9b36a80c LC |
151 | # if @REPLACE_CLOSE@ |
152 | /* Automatically included by modules that need a replacement for close. */ | |
153 | # undef close | |
154 | # define close rpl_close | |
155 | extern int close (int); | |
156 | # endif | |
8912421c | 157 | #elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@ |
9b36a80c LC |
158 | # undef close |
159 | # define close close_used_without_requesting_gnulib_module_close | |
160 | #elif defined GNULIB_POSIXCHECK | |
161 | # undef close | |
162 | # define close(f) \ | |
163 | (GL_LINK_WARNING ("close does not portably work on sockets - " \ | |
164 | "use gnulib module close for portability"), \ | |
165 | close (f)) | |
166 | #endif | |
167 | ||
168 | ||
8912421c LC |
169 | #if @REPLACE_DUP@ |
170 | # define dup rpl_dup | |
171 | extern int dup (int); | |
172 | #endif | |
173 | ||
174 | ||
9b36a80c | 175 | #if @GNULIB_DUP2@ |
25361e4b LC |
176 | # if @REPLACE_DUP2@ |
177 | # define dup2 rpl_dup2 | |
178 | # endif | |
179 | # if !@HAVE_DUP2@ || @REPLACE_DUP2@ | |
9b36a80c LC |
180 | /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if |
181 | NEWFD = OLDFD, otherwise close NEWFD first if it is open. | |
25361e4b | 182 | Return newfd if successful, otherwise -1 and errno set. |
9b36a80c LC |
183 | See the POSIX:2001 specification |
184 | <http://www.opengroup.org/susv3xsh/dup2.html>. */ | |
185 | extern int dup2 (int oldfd, int newfd); | |
186 | # endif | |
187 | #elif defined GNULIB_POSIXCHECK | |
188 | # undef dup2 | |
189 | # define dup2(o,n) \ | |
190 | (GL_LINK_WARNING ("dup2 is unportable - " \ | |
191 | "use gnulib module dup2 for portability"), \ | |
192 | dup2 (o, n)) | |
193 | #endif | |
194 | ||
195 | ||
8912421c LC |
196 | #if @GNULIB_DUP3@ |
197 | /* Copy the file descriptor OLDFD into file descriptor NEWFD, with the | |
198 | specified flags. | |
199 | The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>) | |
200 | and O_TEXT, O_BINARY (defined in "binary-io.h"). | |
201 | Close NEWFD first if it is open. | |
202 | Return newfd if successful, otherwise -1 and errno set. | |
203 | See the Linux man page at | |
204 | <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */ | |
205 | # if @HAVE_DUP3@ | |
206 | # define dup3 rpl_dup3 | |
207 | # endif | |
208 | extern int dup3 (int oldfd, int newfd, int flags); | |
209 | #elif defined GNULIB_POSIXCHECK | |
210 | # undef dup3 | |
211 | # define dup3(o,n,f) \ | |
212 | (GL_LINK_WARNING ("dup3 is unportable - " \ | |
213 | "use gnulib module dup3 for portability"), \ | |
214 | dup3 (o, n, f)) | |
215 | #endif | |
216 | ||
217 | ||
9b36a80c LC |
218 | #if @GNULIB_ENVIRON@ |
219 | # if !@HAVE_DECL_ENVIRON@ | |
220 | /* Set of environment variables and values. An array of strings of the form | |
221 | "VARIABLE=VALUE", terminated with a NULL. */ | |
222 | # if defined __APPLE__ && defined __MACH__ | |
223 | # include <crt_externs.h> | |
224 | # define environ (*_NSGetEnviron ()) | |
225 | # else | |
226 | extern char **environ; | |
227 | # endif | |
228 | # endif | |
229 | #elif defined GNULIB_POSIXCHECK | |
230 | # undef environ | |
231 | # define environ \ | |
232 | (GL_LINK_WARNING ("environ is unportable - " \ | |
233 | "use gnulib module environ for portability"), \ | |
234 | environ) | |
235 | #endif | |
236 | ||
237 | ||
238 | #if @GNULIB_EUIDACCESS@ | |
239 | # if !@HAVE_EUIDACCESS@ | |
8912421c | 240 | /* Like access(), except that it uses the effective user id and group id of |
9b36a80c LC |
241 | the current process. */ |
242 | extern int euidaccess (const char *filename, int mode); | |
243 | # endif | |
244 | #elif defined GNULIB_POSIXCHECK | |
245 | # undef euidaccess | |
246 | # define euidaccess(f,m) \ | |
247 | (GL_LINK_WARNING ("euidaccess is unportable - " \ | |
248 | "use gnulib module euidaccess for portability"), \ | |
249 | euidaccess (f, m)) | |
250 | #endif | |
251 | ||
252 | ||
8912421c LC |
253 | #if @GNULIB_FACCESSAT@ |
254 | # if !@HAVE_FACCESSAT@ | |
255 | int faccessat (int fd, char const *file, int mode, int flag); | |
256 | # endif | |
257 | #elif defined GNULIB_POSIXCHECK | |
258 | # undef faccessat | |
259 | # define faccessat(d,n,m,f) \ | |
260 | (GL_LINK_WARNING ("faccessat is not portable - " \ | |
261 | "use gnulib module faccessat for portability"), \ | |
262 | faccessat (d, n, m, f)) | |
263 | #endif | |
264 | ||
265 | ||
9b36a80c LC |
266 | #if @GNULIB_FCHDIR@ |
267 | # if @REPLACE_FCHDIR@ | |
9b36a80c LC |
268 | /* Change the process' current working directory to the directory on which |
269 | the given file descriptor is open. | |
270 | Return 0 if successful, otherwise -1 and errno set. | |
271 | See the POSIX:2001 specification | |
272 | <http://www.opengroup.org/susv3xsh/fchdir.html>. */ | |
273 | extern int fchdir (int /*fd*/); | |
274 | ||
8912421c LC |
275 | /* Gnulib internal hooks needed to maintain the fchdir metadata. */ |
276 | extern int _gl_register_fd (int fd, const char *filename); | |
277 | extern void _gl_unregister_fd (int fd); | |
278 | extern int _gl_register_dup (int oldfd, int newfd); | |
279 | extern const char *_gl_directory_name (int fd); | |
9b36a80c LC |
280 | |
281 | # endif | |
282 | #elif defined GNULIB_POSIXCHECK | |
283 | # undef fchdir | |
284 | # define fchdir(f) \ | |
285 | (GL_LINK_WARNING ("fchdir is unportable - " \ | |
286 | "use gnulib module fchdir for portability"), \ | |
287 | fchdir (f)) | |
288 | #endif | |
289 | ||
290 | ||
8912421c LC |
291 | #if @GNULIB_FCHOWNAT@ |
292 | # if @REPLACE_FCHOWNAT@ | |
293 | # undef fchownat | |
294 | # define fchownat rpl_fchownat | |
295 | # endif | |
296 | # if !@HAVE_FCHOWNAT@ || @REPLACE_FCHOWNAT@ | |
297 | extern int fchownat (int fd, char const *file, uid_t owner, gid_t group, int flag); | |
298 | # endif | |
299 | #elif defined GNULIB_POSIXCHECK | |
300 | # undef fchownat | |
301 | # define fchownat(d,n,o,g,f) \ | |
302 | (GL_LINK_WARNING ("fchownat is not portable - " \ | |
303 | "use gnulib module openat for portability"), \ | |
304 | fchownat (d, n, o, g, f)) | |
305 | #endif | |
306 | ||
307 | ||
9b36a80c LC |
308 | #if @GNULIB_FSYNC@ |
309 | /* Synchronize changes to a file. | |
310 | Return 0 if successful, otherwise -1 and errno set. | |
311 | See POSIX:2001 specification | |
312 | <http://www.opengroup.org/susv3xsh/fsync.html>. */ | |
313 | # if !@HAVE_FSYNC@ | |
314 | extern int fsync (int fd); | |
315 | # endif | |
316 | #elif defined GNULIB_POSIXCHECK | |
317 | # undef fsync | |
318 | # define fsync(fd) \ | |
319 | (GL_LINK_WARNING ("fsync is unportable - " \ | |
320 | "use gnulib module fsync for portability"), \ | |
321 | fsync (fd)) | |
322 | #endif | |
323 | ||
324 | ||
325 | #if @GNULIB_FTRUNCATE@ | |
326 | # if !@HAVE_FTRUNCATE@ | |
327 | /* Change the size of the file to which FD is opened to become equal to LENGTH. | |
328 | Return 0 if successful, otherwise -1 and errno set. | |
329 | See the POSIX:2001 specification | |
330 | <http://www.opengroup.org/susv3xsh/ftruncate.html>. */ | |
331 | extern int ftruncate (int fd, off_t length); | |
332 | # endif | |
333 | #elif defined GNULIB_POSIXCHECK | |
334 | # undef ftruncate | |
335 | # define ftruncate(f,l) \ | |
336 | (GL_LINK_WARNING ("ftruncate is unportable - " \ | |
337 | "use gnulib module ftruncate for portability"), \ | |
338 | ftruncate (f, l)) | |
339 | #endif | |
340 | ||
341 | ||
342 | #if @GNULIB_GETCWD@ | |
343 | /* Include the headers that might declare getcwd so that they will not | |
344 | cause confusion if included after this file. */ | |
345 | # include <stdlib.h> | |
346 | # if @REPLACE_GETCWD@ | |
347 | /* Get the name of the current working directory, and put it in SIZE bytes | |
348 | of BUF. | |
349 | Return BUF if successful, or NULL if the directory couldn't be determined | |
350 | or SIZE was too small. | |
351 | See the POSIX:2001 specification | |
352 | <http://www.opengroup.org/susv3xsh/getcwd.html>. | |
353 | Additionally, the gnulib module 'getcwd' guarantees the following GNU | |
354 | extension: If BUF is NULL, an array is allocated with 'malloc'; the array | |
355 | is SIZE bytes long, unless SIZE == 0, in which case it is as big as | |
356 | necessary. */ | |
357 | # define getcwd rpl_getcwd | |
358 | extern char * getcwd (char *buf, size_t size); | |
359 | # endif | |
360 | #elif defined GNULIB_POSIXCHECK | |
361 | # undef getcwd | |
362 | # define getcwd(b,s) \ | |
363 | (GL_LINK_WARNING ("getcwd is unportable - " \ | |
364 | "use gnulib module getcwd for portability"), \ | |
365 | getcwd (b, s)) | |
366 | #endif | |
367 | ||
368 | ||
369 | #if @GNULIB_GETDOMAINNAME@ | |
370 | /* Return the NIS domain name of the machine. | |
371 | WARNING! The NIS domain name is unrelated to the fully qualified host name | |
372 | of the machine. It is also unrelated to email addresses. | |
373 | WARNING! The NIS domain name is usually the empty string or "(none)" when | |
374 | not using NIS. | |
375 | ||
376 | Put up to LEN bytes of the NIS domain name into NAME. | |
377 | Null terminate it if the name is shorter than LEN. | |
378 | If the NIS domain name is longer than LEN, set errno = EINVAL and return -1. | |
379 | Return 0 if successful, otherwise set errno and return -1. */ | |
380 | # if !@HAVE_GETDOMAINNAME@ | |
381 | extern int getdomainname(char *name, size_t len); | |
382 | # endif | |
383 | #elif defined GNULIB_POSIXCHECK | |
384 | # undef getdomainname | |
385 | # define getdomainname(n,l) \ | |
386 | (GL_LINK_WARNING ("getdomainname is unportable - " \ | |
387 | "use gnulib module getdomainname for portability"), \ | |
388 | getdomainname (n, l)) | |
389 | #endif | |
390 | ||
391 | ||
392 | #if @GNULIB_GETDTABLESIZE@ | |
393 | # if !@HAVE_GETDTABLESIZE@ | |
8912421c LC |
394 | /* Return the maximum number of file descriptors in the current process. |
395 | In POSIX, this is same as sysconf (_SC_OPEN_MAX). */ | |
9b36a80c LC |
396 | extern int getdtablesize (void); |
397 | # endif | |
398 | #elif defined GNULIB_POSIXCHECK | |
399 | # undef getdtablesize | |
400 | # define getdtablesize() \ | |
401 | (GL_LINK_WARNING ("getdtablesize is unportable - " \ | |
402 | "use gnulib module getdtablesize for portability"), \ | |
403 | getdtablesize ()) | |
404 | #endif | |
405 | ||
406 | ||
f29ded4b LC |
407 | #if @GNULIB_GETGROUPS@ |
408 | # if @REPLACE_GETGROUPS@ | |
409 | # undef getgroups | |
410 | # define getgroups rpl_getgroups | |
411 | # endif | |
412 | # if !@HAVE_GETGROUPS@ || @REPLACE_GETGROUPS@ | |
413 | /* Return the supplemental groups that the current process belongs to. | |
414 | It is unspecified whether the effective group id is in the list. | |
415 | If N is 0, return the group count; otherwise, N describes how many | |
416 | entries are available in GROUPS. Return -1 and set errno if N is | |
417 | not 0 and not large enough. Fails with ENOSYS on some systems. */ | |
418 | int getgroups (int n, gid_t *groups); | |
419 | # endif | |
420 | #elif defined GNULIB_POSIXCHECK | |
421 | # undef getgroups | |
422 | # define getgroups(n,g) \ | |
423 | (GL_LINK_WARNING ("getgroups is unportable - " \ | |
424 | "use gnulib module getgroups for portability"), \ | |
425 | getgroups (n, g)) | |
426 | #endif | |
427 | ||
428 | ||
9b36a80c LC |
429 | #if @GNULIB_GETHOSTNAME@ |
430 | /* Return the standard host name of the machine. | |
431 | WARNING! The host name may or may not be fully qualified. | |
432 | ||
433 | Put up to LEN bytes of the host name into NAME. | |
434 | Null terminate it if the name is shorter than LEN. | |
435 | If the host name is longer than LEN, set errno = EINVAL and return -1. | |
436 | Return 0 if successful, otherwise set errno and return -1. */ | |
437 | # if @UNISTD_H_HAVE_WINSOCK2_H@ | |
438 | # undef gethostname | |
439 | # define gethostname rpl_gethostname | |
440 | # endif | |
441 | # if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@ | |
442 | extern int gethostname(char *name, size_t len); | |
443 | # endif | |
444 | #elif @UNISTD_H_HAVE_WINSOCK2_H@ | |
445 | # undef gethostname | |
446 | # define gethostname gethostname_used_without_requesting_gnulib_module_gethostname | |
447 | #elif defined GNULIB_POSIXCHECK | |
448 | # undef gethostname | |
449 | # define gethostname(n,l) \ | |
450 | (GL_LINK_WARNING ("gethostname is unportable - " \ | |
451 | "use gnulib module gethostname for portability"), \ | |
452 | gethostname (n, l)) | |
453 | #endif | |
454 | ||
455 | ||
456 | #if @GNULIB_GETLOGIN_R@ | |
457 | /* Copies the user's login name to NAME. | |
458 | The array pointed to by NAME has room for SIZE bytes. | |
459 | ||
460 | Returns 0 if successful. Upon error, an error number is returned, or -1 in | |
461 | the case that the login name cannot be found but no specific error is | |
462 | provided (this case is hopefully rare but is left open by the POSIX spec). | |
463 | ||
464 | See <http://www.opengroup.org/susv3xsh/getlogin.html>. | |
465 | */ | |
466 | # if !@HAVE_DECL_GETLOGIN_R@ | |
9b36a80c LC |
467 | extern int getlogin_r (char *name, size_t size); |
468 | # endif | |
469 | #elif defined GNULIB_POSIXCHECK | |
470 | # undef getlogin_r | |
471 | # define getlogin_r(n,s) \ | |
472 | (GL_LINK_WARNING ("getlogin_r is unportable - " \ | |
473 | "use gnulib module getlogin_r for portability"), \ | |
474 | getlogin_r (n, s)) | |
475 | #endif | |
476 | ||
477 | ||
478 | #if @GNULIB_GETPAGESIZE@ | |
479 | # if @REPLACE_GETPAGESIZE@ | |
480 | # define getpagesize rpl_getpagesize | |
481 | extern int getpagesize (void); | |
482 | # elif !@HAVE_GETPAGESIZE@ | |
483 | /* This is for POSIX systems. */ | |
484 | # if !defined getpagesize && defined _SC_PAGESIZE | |
485 | # if ! (defined __VMS && __VMS_VER < 70000000) | |
486 | # define getpagesize() sysconf (_SC_PAGESIZE) | |
487 | # endif | |
488 | # endif | |
489 | /* This is for older VMS. */ | |
490 | # if !defined getpagesize && defined __VMS | |
491 | # ifdef __ALPHA | |
492 | # define getpagesize() 8192 | |
493 | # else | |
494 | # define getpagesize() 512 | |
495 | # endif | |
496 | # endif | |
497 | /* This is for BeOS. */ | |
498 | # if !defined getpagesize && @HAVE_OS_H@ | |
499 | # include <OS.h> | |
500 | # if defined B_PAGE_SIZE | |
501 | # define getpagesize() B_PAGE_SIZE | |
502 | # endif | |
503 | # endif | |
504 | /* This is for AmigaOS4.0. */ | |
505 | # if !defined getpagesize && defined __amigaos4__ | |
506 | # define getpagesize() 2048 | |
507 | # endif | |
508 | /* This is for older Unix systems. */ | |
509 | # if !defined getpagesize && @HAVE_SYS_PARAM_H@ | |
510 | # include <sys/param.h> | |
511 | # ifdef EXEC_PAGESIZE | |
512 | # define getpagesize() EXEC_PAGESIZE | |
513 | # else | |
514 | # ifdef NBPG | |
515 | # ifndef CLSIZE | |
516 | # define CLSIZE 1 | |
517 | # endif | |
518 | # define getpagesize() (NBPG * CLSIZE) | |
519 | # else | |
520 | # ifdef NBPC | |
521 | # define getpagesize() NBPC | |
522 | # endif | |
523 | # endif | |
524 | # endif | |
525 | # endif | |
526 | # endif | |
527 | #elif defined GNULIB_POSIXCHECK | |
528 | # undef getpagesize | |
529 | # define getpagesize() \ | |
530 | (GL_LINK_WARNING ("getpagesize is unportable - " \ | |
531 | "use gnulib module getpagesize for portability"), \ | |
532 | getpagesize ()) | |
533 | #endif | |
534 | ||
535 | ||
536 | #if @GNULIB_GETUSERSHELL@ | |
537 | # if !@HAVE_GETUSERSHELL@ | |
538 | /* Return the next valid login shell on the system, or NULL when the end of | |
539 | the list has been reached. */ | |
540 | extern char *getusershell (void); | |
541 | /* Rewind to pointer that is advanced at each getusershell() call. */ | |
542 | extern void setusershell (void); | |
543 | /* Free the pointer that is advanced at each getusershell() call and | |
544 | associated resources. */ | |
545 | extern void endusershell (void); | |
546 | # endif | |
547 | #elif defined GNULIB_POSIXCHECK | |
548 | # undef getusershell | |
549 | # define getusershell() \ | |
550 | (GL_LINK_WARNING ("getusershell is unportable - " \ | |
551 | "use gnulib module getusershell for portability"), \ | |
552 | getusershell ()) | |
553 | # undef setusershell | |
554 | # define setusershell() \ | |
555 | (GL_LINK_WARNING ("setusershell is unportable - " \ | |
556 | "use gnulib module getusershell for portability"), \ | |
557 | setusershell ()) | |
558 | # undef endusershell | |
559 | # define endusershell() \ | |
560 | (GL_LINK_WARNING ("endusershell is unportable - " \ | |
561 | "use gnulib module getusershell for portability"), \ | |
562 | endusershell ()) | |
563 | #endif | |
564 | ||
565 | ||
566 | #if @GNULIB_LCHOWN@ | |
567 | # if @REPLACE_LCHOWN@ | |
f29ded4b LC |
568 | # undef lchown |
569 | # define lchown rpl_lchown | |
570 | # endif | |
571 | # if !@HAVE_LCHOWN@ || @REPLACE_LCHOWN@ | |
9b36a80c LC |
572 | /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE |
573 | to GID (if GID is not -1). Do not follow symbolic links. | |
574 | Return 0 if successful, otherwise -1 and errno set. | |
575 | See the POSIX:2001 specification | |
576 | <http://www.opengroup.org/susv3xsh/lchown.html>. */ | |
9b36a80c LC |
577 | extern int lchown (char const *file, uid_t owner, gid_t group); |
578 | # endif | |
579 | #elif defined GNULIB_POSIXCHECK | |
580 | # undef lchown | |
581 | # define lchown(f,u,g) \ | |
582 | (GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \ | |
583 | "systems - use gnulib module lchown for portability"), \ | |
584 | lchown (f, u, g)) | |
585 | #endif | |
586 | ||
587 | ||
f240aacb | 588 | #if @GNULIB_LINK@ |
8912421c LC |
589 | # if @REPLACE_LINK@ |
590 | # define link rpl_link | |
591 | # endif | |
f240aacb LC |
592 | /* Create a new hard link for an existing file. |
593 | Return 0 if successful, otherwise -1 and errno set. | |
594 | See POSIX:2001 specification | |
595 | <http://www.opengroup.org/susv3xsh/link.html>. */ | |
8912421c | 596 | # if !@HAVE_LINK@ || @REPLACE_LINK@ |
f240aacb LC |
597 | extern int link (const char *path1, const char *path2); |
598 | # endif | |
599 | #elif defined GNULIB_POSIXCHECK | |
600 | # undef link | |
601 | # define link(path1,path2) \ | |
602 | (GL_LINK_WARNING ("link is unportable - " \ | |
603 | "use gnulib module link for portability"), \ | |
604 | link (path1, path2)) | |
605 | #endif | |
606 | ||
8912421c LC |
607 | #if @GNULIB_LINKAT@ |
608 | # if @REPLACE_LINKAT@ | |
609 | # undef linkat | |
610 | # define linkat rpl_linkat | |
611 | # endif | |
612 | /* Create a new hard link for an existing file, relative to two | |
613 | directories. FLAG controls whether symlinks are followed. | |
614 | Return 0 if successful, otherwise -1 and errno set. */ | |
615 | # if !@HAVE_LINKAT@ || @REPLACE_LINKAT@ | |
616 | extern int linkat (int fd1, const char *path1, int fd2, const char *path2, | |
617 | int flag); | |
618 | # endif | |
619 | #elif defined GNULIB_POSIXCHECK | |
620 | # undef linkat | |
621 | # define link(f1,path1,f2,path2,f) \ | |
622 | (GL_LINK_WARNING ("linkat is unportable - " \ | |
623 | "use gnulib module linkat for portability"), \ | |
624 | linkat (f1, path1, f2, path2,f)) | |
625 | #endif | |
f240aacb | 626 | |
9b36a80c LC |
627 | #if @GNULIB_LSEEK@ |
628 | # if @REPLACE_LSEEK@ | |
629 | /* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END. | |
630 | Return the new offset if successful, otherwise -1 and errno set. | |
631 | See the POSIX:2001 specification | |
632 | <http://www.opengroup.org/susv3xsh/lseek.html>. */ | |
633 | # define lseek rpl_lseek | |
634 | extern off_t lseek (int fd, off_t offset, int whence); | |
635 | # endif | |
636 | #elif defined GNULIB_POSIXCHECK | |
637 | # undef lseek | |
638 | # define lseek(f,o,w) \ | |
639 | (GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \ | |
640 | "systems - use gnulib module lseek for portability"), \ | |
641 | lseek (f, o, w)) | |
642 | #endif | |
643 | ||
644 | ||
8912421c LC |
645 | #if @GNULIB_PIPE2@ |
646 | /* Create a pipe, applying the given flags when opening the read-end of the | |
647 | pipe and the write-end of the pipe. | |
648 | The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>) | |
649 | and O_TEXT, O_BINARY (defined in "binary-io.h"). | |
650 | Store the read-end as fd[0] and the write-end as fd[1]. | |
651 | Return 0 upon success, or -1 with errno set upon failure. | |
652 | See also the Linux man page at | |
653 | <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */ | |
654 | # if @HAVE_PIPE2@ | |
655 | # define pipe2 rpl_pipe2 | |
656 | # endif | |
657 | extern int pipe2 (int fd[2], int flags); | |
658 | #elif defined GNULIB_POSIXCHECK | |
659 | # undef pipe2 | |
660 | # define pipe2(f,o) \ | |
661 | (GL_LINK_WARNING ("pipe2 is unportable - " \ | |
662 | "use gnulib module pipe2 for portability"), \ | |
663 | pipe2 (f, o)) | |
664 | #endif | |
665 | ||
666 | ||
9b36a80c | 667 | #if @GNULIB_READLINK@ |
8912421c LC |
668 | # if @REPLACE_READLINK@ |
669 | # define readlink rpl_readlink | |
670 | # endif | |
9b36a80c LC |
671 | /* Read the contents of the symbolic link FILE and place the first BUFSIZE |
672 | bytes of it into BUF. Return the number of bytes placed into BUF if | |
673 | successful, otherwise -1 and errno set. | |
674 | See the POSIX:2001 specification | |
675 | <http://www.opengroup.org/susv3xsh/readlink.html>. */ | |
8912421c LC |
676 | # if !@HAVE_READLINK@ || @REPLACE_READLINK@ |
677 | extern ssize_t readlink (const char *file, char *buf, size_t bufsize); | |
9b36a80c LC |
678 | # endif |
679 | #elif defined GNULIB_POSIXCHECK | |
680 | # undef readlink | |
681 | # define readlink(f,b,s) \ | |
682 | (GL_LINK_WARNING ("readlink is unportable - " \ | |
683 | "use gnulib module readlink for portability"), \ | |
684 | readlink (f, b, s)) | |
685 | #endif | |
686 | ||
687 | ||
8912421c LC |
688 | #if @GNULIB_READLINKAT@ |
689 | # if !@HAVE_READLINKAT@ | |
690 | ssize_t readlinkat (int fd, char const *file, char *buf, size_t len); | |
691 | # endif | |
692 | #elif defined GNULIB_POSIXCHECK | |
693 | # undef readlinkat | |
694 | # define readlinkat(d,n,b,l) \ | |
695 | (GL_LINK_WARNING ("readlinkat is not portable - " \ | |
696 | "use gnulib module symlinkat for portability"), \ | |
697 | readlinkat (d, n, b, l)) | |
698 | #endif | |
699 | ||
700 | ||
701 | #if @GNULIB_RMDIR@ | |
702 | # if @REPLACE_RMDIR@ | |
703 | # define rmdir rpl_rmdir | |
704 | /* Remove the directory DIR. */ | |
705 | extern int rmdir (char const *name); | |
706 | # endif | |
707 | #elif defined GNULIB_POSIXCHECK | |
708 | # undef rmdir | |
709 | # define rmdir(n) \ | |
710 | (GL_LINK_WARNING ("rmdir is unportable - " \ | |
711 | "use gnulib module rmdir for portability"), \ | |
712 | rmdir (n)) | |
713 | #endif | |
714 | ||
715 | ||
9b36a80c LC |
716 | #if @GNULIB_SLEEP@ |
717 | /* Pause the execution of the current thread for N seconds. | |
718 | Returns the number of seconds left to sleep. | |
719 | See the POSIX:2001 specification | |
720 | <http://www.opengroup.org/susv3xsh/sleep.html>. */ | |
721 | # if !@HAVE_SLEEP@ | |
722 | extern unsigned int sleep (unsigned int n); | |
723 | # endif | |
724 | #elif defined GNULIB_POSIXCHECK | |
725 | # undef sleep | |
726 | # define sleep(n) \ | |
727 | (GL_LINK_WARNING ("sleep is unportable - " \ | |
728 | "use gnulib module sleep for portability"), \ | |
729 | sleep (n)) | |
730 | #endif | |
731 | ||
732 | ||
8912421c LC |
733 | #if @GNULIB_SYMLINK@ |
734 | # if @REPLACE_SYMLINK@ | |
735 | # undef symlink | |
736 | # define symlink rpl_symlink | |
737 | # endif | |
738 | # if !@HAVE_SYMLINK@ || @REPLACE_SYMLINK@ | |
739 | int symlink (char const *contents, char const *file); | |
740 | # endif | |
741 | #elif defined GNULIB_POSIXCHECK | |
742 | # undef symlink | |
743 | # define symlink(c,n) \ | |
744 | (GL_LINK_WARNING ("symlink is not portable - " \ | |
745 | "use gnulib module symlink for portability"), \ | |
746 | symlink (c, n)) | |
747 | #endif | |
748 | ||
749 | ||
750 | #if @GNULIB_SYMLINKAT@ | |
751 | # if !@HAVE_SYMLINKAT@ | |
752 | int symlinkat (char const *contents, int fd, char const *file); | |
753 | # endif | |
754 | #elif defined GNULIB_POSIXCHECK | |
755 | # undef symlinkat | |
756 | # define symlinkat(c,d,n) \ | |
757 | (GL_LINK_WARNING ("symlinkat is not portable - " \ | |
758 | "use gnulib module symlinkat for portability"), \ | |
759 | symlinkat (c, d, n)) | |
760 | #endif | |
761 | ||
762 | ||
763 | #if @GNULIB_UNLINK@ | |
764 | # if @REPLACE_UNLINK@ | |
765 | # undef unlink | |
766 | # define unlink rpl_unlink | |
767 | extern int unlink (char const *file); | |
768 | # endif | |
769 | #elif defined GNULIB_POSIXCHECK | |
770 | # undef unlink | |
771 | # define unlink(n) \ | |
772 | (GL_LINK_WARNING ("unlink is not portable - " \ | |
773 | "use gnulib module unlink for portability"), \ | |
774 | unlink (n)) | |
775 | #endif | |
776 | ||
777 | ||
778 | #if @GNULIB_UNLINKAT@ | |
779 | # if @REPLACE_UNLINKAT@ | |
780 | # undef unlinkat | |
781 | # define unlinkat rpl_unlinkat | |
782 | # endif | |
783 | # if !@HAVE_UNLINKAT@ || @REPLACE_UNLINKAT@ | |
784 | extern int unlinkat (int fd, char const *file, int flag); | |
785 | # endif | |
786 | #elif defined GNULIB_POSIXCHECK | |
787 | # undef unlinkat | |
788 | # define unlinkat(d,n,f) \ | |
789 | (GL_LINK_WARNING ("unlinkat is not portable - " \ | |
790 | "use gnulib module openat for portability"), \ | |
791 | unlinkat (d, n, f)) | |
792 | #endif | |
793 | ||
794 | ||
9b36a80c LC |
795 | #if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@ |
796 | /* Write up to COUNT bytes starting at BUF to file descriptor FD. | |
797 | See the POSIX:2001 specification | |
798 | <http://www.opengroup.org/susv3xsh/write.html>. */ | |
799 | # undef write | |
800 | # define write rpl_write | |
801 | extern ssize_t write (int fd, const void *buf, size_t count); | |
802 | #endif | |
803 | ||
804 | ||
9b36a80c LC |
805 | #ifdef __cplusplus |
806 | } | |
807 | #endif | |
808 | ||
809 | ||
810 | #endif /* _GL_UNISTD_H */ | |
811 | #endif /* _GL_UNISTD_H */ |