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