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