1 /* Copyright (C) 1991-2006, 2007, 2008, 2009 Free Software Foundation, Inc. 2 This file is part of the GNU C Library. 3 4 The GNU C Library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 The GNU C Library 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 GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with the GNU C Library; if not, write to the Free 16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 17 02111-1307 USA. */ 18 19 /* 20 * POSIX Standard: 2.10 Symbolic Constants <unistd.h> 21 */ 22 23 #ifndef _UNISTD_H 24 #define _UNISTD_H 1 25 26 #include <features.h> 27 28 __BEGIN_DECLS 29 30 /* These may be used to determine what facilities are present at compile time. 31 Their values can be obtained at run time from `sysconf'. */ 32 33 #ifdef __USE_XOPEN2K8 34 /* POSIX Standard approved as ISO/IEC 9945-1 as of September 2008. */ 35 # define _POSIX_VERSION 200809L 36 #elif defined __USE_XOPEN2K 37 /* POSIX Standard approved as ISO/IEC 9945-1 as of December 2001. */ 38 # define _POSIX_VERSION 200112L 39 #elif defined __USE_POSIX199506 40 /* POSIX Standard approved as ISO/IEC 9945-1 as of June 1995. */ 41 # define _POSIX_VERSION 199506L 42 #elif defined __USE_POSIX199309 43 /* POSIX Standard approved as ISO/IEC 9945-1 as of September 1993. */ 44 # define _POSIX_VERSION 199309L 45 #else 46 /* POSIX Standard approved as ISO/IEC 9945-1 as of September 1990. */ 47 # define _POSIX_VERSION 199009L 48 #endif 49 50 /* These are not #ifdef __USE_POSIX2 because they are 51 in the theoretically application-owned namespace. */ 52 53 #ifdef __USE_XOPEN2K8 54 # define __POSIX2_THIS_VERSION 200809L 55 /* The utilities on GNU systems also correspond to this version. */ 56 #elif defined __USE_XOPEN2K 57 /* The utilities on GNU systems also correspond to this version. */ 58 # define __POSIX2_THIS_VERSION 200112L 59 #elif defined __USE_POSIX199506 60 /* The utilities on GNU systems also correspond to this version. */ 61 # define __POSIX2_THIS_VERSION 199506L 62 #else 63 /* The utilities on GNU systems also correspond to this version. */ 64 # define __POSIX2_THIS_VERSION 199209L 65 #endif 66 67 /* The utilities on GNU systems also correspond to this version. */ 68 #define _POSIX2_VERSION __POSIX2_THIS_VERSION 69 70 /* If defined, the implementation supports the 71 C Language Bindings Option. */ 72 #define _POSIX2_C_BIND __POSIX2_THIS_VERSION 73 74 /* If defined, the implementation supports the 75 C Language Development Utilities Option. */ 76 #define _POSIX2_C_DEV __POSIX2_THIS_VERSION 77 78 /* If defined, the implementation supports the 79 Software Development Utilities Option. */ 80 #define _POSIX2_SW_DEV __POSIX2_THIS_VERSION 81 82 /* If defined, the implementation supports the 83 creation of locales with the localedef utility. */ 84 #define _POSIX2_LOCALEDEF __POSIX2_THIS_VERSION 85 86 /* X/Open version number to which the library conforms. It is selectable. */ 87 #ifdef __USE_XOPEN2K8 88 # define _XOPEN_VERSION 700 89 #elif defined __USE_XOPEN2K 90 # define _XOPEN_VERSION 600 91 #elif defined __USE_UNIX98 92 # define _XOPEN_VERSION 500 93 #else 94 # define _XOPEN_VERSION 4 95 #endif 96 97 /* Commands and utilities from XPG4 are available. */ 98 #define _XOPEN_XCU_VERSION 4 99 100 /* We are compatible with the old published standards as well. */ 101 #define _XOPEN_XPG2 1 102 #define _XOPEN_XPG3 1 103 #define _XOPEN_XPG4 1 104 105 /* The X/Open Unix extensions are available. */ 106 #define _XOPEN_UNIX 1 107 108 /* Encryption is present. */ 109 #define _XOPEN_CRYPT 1 110 111 /* The enhanced internationalization capabilities according to XPG4.2 112 are present. */ 113 #define _XOPEN_ENH_I18N 1 114 115 /* The legacy interfaces are also available. */ 116 #define _XOPEN_LEGACY 1 117 118 119 /* Get values of POSIX options: 120 121 If these symbols are defined, the corresponding features are 122 always available. If not, they may be available sometimes. 123 The current values can be obtained with `sysconf'. 124 125 _POSIX_JOB_CONTROL Job control is supported. 126 _POSIX_SAVED_IDS Processes have a saved set-user-ID 127 and a saved set-group-ID. 128 _POSIX_REALTIME_SIGNALS Real-time, queued signals are supported. 129 _POSIX_PRIORITY_SCHEDULING Priority scheduling is supported. 130 _POSIX_TIMERS POSIX.4 clocks and timers are supported. 131 _POSIX_ASYNCHRONOUS_IO Asynchronous I/O is supported. 132 _POSIX_PRIORITIZED_IO Prioritized asynchronous I/O is supported. 133 _POSIX_SYNCHRONIZED_IO Synchronizing file data is supported. 134 _POSIX_FSYNC The fsync function is present. 135 _POSIX_MAPPED_FILES Mapping of files to memory is supported. 136 _POSIX_MEMLOCK Locking of all memory is supported. 137 _POSIX_MEMLOCK_RANGE Locking of ranges of memory is supported. 138 _POSIX_MEMORY_PROTECTION Setting of memory protections is supported. 139 _POSIX_MESSAGE_PASSING POSIX.4 message queues are supported. 140 _POSIX_SEMAPHORES POSIX.4 counting semaphores are supported. 141 _POSIX_SHARED_MEMORY_OBJECTS POSIX.4 shared memory objects are supported. 142 _POSIX_THREADS POSIX.1c pthreads are supported. 143 _POSIX_THREAD_ATTR_STACKADDR Thread stack address attribute option supported. 144 _POSIX_THREAD_ATTR_STACKSIZE Thread stack size attribute option supported. 145 _POSIX_THREAD_SAFE_FUNCTIONS Thread-safe functions are supported. 146 _POSIX_THREAD_PRIORITY_SCHEDULING 147 POSIX.1c thread execution scheduling supported. 148 _POSIX_THREAD_PRIO_INHERIT Thread priority inheritance option supported. 149 _POSIX_THREAD_PRIO_PROTECT Thread priority protection option supported. 150 _POSIX_THREAD_PROCESS_SHARED Process-shared synchronization supported. 151 _POSIX_PII Protocol-independent interfaces are supported. 152 _POSIX_PII_XTI XTI protocol-indep. interfaces are supported. 153 _POSIX_PII_SOCKET Socket protocol-indep. interfaces are supported. 154 _POSIX_PII_INTERNET Internet family of protocols supported. 155 _POSIX_PII_INTERNET_STREAM Connection-mode Internet protocol supported. 156 _POSIX_PII_INTERNET_DGRAM Connectionless Internet protocol supported. 157 _POSIX_PII_OSI ISO/OSI family of protocols supported. 158 _POSIX_PII_OSI_COTS Connection-mode ISO/OSI service supported. 159 _POSIX_PII_OSI_CLTS Connectionless ISO/OSI service supported. 160 _POSIX_POLL Implementation supports `poll' function. 161 _POSIX_SELECT Implementation supports `select' and `pselect'. 162 163 _XOPEN_REALTIME X/Open realtime support is available. 164 _XOPEN_REALTIME_THREADS X/Open realtime thread support is available. 165 _XOPEN_SHM Shared memory interface according to XPG4.2. 166 167 _XBS5_ILP32_OFF32 Implementation provides environment with 32-bit 168 int, long, pointer, and off_t types. 169 _XBS5_ILP32_OFFBIG Implementation provides environment with 32-bit 170 int, long, and pointer and off_t with at least 171 64 bits. 172 _XBS5_LP64_OFF64 Implementation provides environment with 32-bit 173 int, and 64-bit long, pointer, and off_t types. 174 _XBS5_LPBIG_OFFBIG Implementation provides environment with at 175 least 32 bits int and long, pointer, and off_t 176 with at least 64 bits. 177 178 If any of these symbols is defined as -1, the corresponding option is not 179 true for any file. If any is defined as other than -1, the corresponding 180 option is true for all files. If a symbol is not defined at all, the value 181 for a specific file can be obtained from `pathconf' and `fpathconf'. 182 183 _POSIX_CHOWN_RESTRICTED Only the super user can use `chown' to change 184 the owner of a file. `chown' can only be used 185 to change the group ID of a file to a group of 186 which the calling process is a member. 187 _POSIX_NO_TRUNC Pathname components longer than 188 NAME_MAX generate an error. 189 _POSIX_VDISABLE If defined, if the value of an element of the 190 `c_cc' member of `struct termios' is 191 _POSIX_VDISABLE, no character will have the 192 effect associated with that element. 193 _POSIX_SYNC_IO Synchronous I/O may be performed. 194 _POSIX_ASYNC_IO Asynchronous I/O may be performed. 195 _POSIX_PRIO_IO Prioritized Asynchronous I/O may be performed. 196 197 Support for the Large File Support interface is not generally available. 198 If it is available the following constants are defined to one. 199 _LFS64_LARGEFILE Low-level I/O supports large files. 200 _LFS64_STDIO Standard I/O supports large files. 201 */ 202 203 #include <bits/posix_opt.h> 204 205 /* Get the environment definitions from Unix98. */ 206 #ifdef __USE_UNIX98 207 # include <bits/environments.h> 208 #endif 209 210 /* Standard file descriptors. */ 211 #define STDIN_FILENO 0 /* Standard input. */ 212 #define STDOUT_FILENO 1 /* Standard output. */ 213 #define STDERR_FILENO 2 /* Standard error output. */ 214 215 216 /* All functions that are not declared anywhere else. */ 217 218 #include <bits/types.h> 219 220 #ifndef __ssize_t_defined 221 typedef __ssize_t ssize_t; 222 # define __ssize_t_defined 223 #endif 224 225 #define __need_size_t 226 #define __need_NULL 227 #include <stddef.h> 228 229 #if defined __USE_XOPEN || defined __USE_XOPEN2K 230 /* The Single Unix specification says that some more types are 231 available here. */ 232 # ifndef __gid_t_defined 233 typedef __gid_t gid_t; 234 # define __gid_t_defined 235 # endif 236 237 # ifndef __uid_t_defined 238 typedef __uid_t uid_t; 239 # define __uid_t_defined 240 # endif 241 242 # ifndef __off_t_defined 243 # ifndef __USE_FILE_OFFSET64 244 typedef __off_t off_t; 245 # else 246 typedef __off64_t off_t; 247 # endif 248 # define __off_t_defined 249 # endif 250 # if defined __USE_LARGEFILE64 && !defined __off64_t_defined 251 typedef __off64_t off64_t; 252 # define __off64_t_defined 253 # endif 254 255 # ifndef __useconds_t_defined 256 typedef __useconds_t useconds_t; 257 # define __useconds_t_defined 258 # endif 259 260 # ifndef __pid_t_defined 261 typedef __pid_t pid_t; 262 # define __pid_t_defined 263 # endif 264 #endif /* X/Open */ 265 266 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED 267 # ifndef __intptr_t_defined 268 typedef __intptr_t intptr_t; 269 # define __intptr_t_defined 270 # endif 271 #endif 272 273 #if defined __USE_BSD || defined __USE_XOPEN 274 # ifndef __socklen_t_defined 275 typedef __socklen_t socklen_t; 276 # define __socklen_t_defined 277 # endif 278 #endif 279 280 /* Values for the second argument to access. 281 These may be OR'd together. */ 282 #define R_OK 4 /* Test for read permission. */ 283 #define W_OK 2 /* Test for write permission. */ 284 #define X_OK 1 /* Test for execute permission. */ 285 #define F_OK 0 /* Test for existence. */ 286 287 /* Test for access to NAME using the real UID and real GID. */ 288 extern int access (__const char *__name, int __type) __THROW __nonnull ((1)); 289 290 #ifdef __USE_GNU 291 /* Test for access to NAME using the effective UID and GID 292 (as normal file operations use). */ 293 extern int euidaccess (__const char *__name, int __type) 294 __THROW __nonnull ((1)); 295 296 /* An alias for `euidaccess', used by some other systems. */ 297 extern int eaccess (__const char *__name, int __type) 298 __THROW __nonnull ((1)); 299 #endif 300 301 #ifdef __USE_ATFILE 302 /* Test for access to FILE relative to the directory FD is open on. 303 If AT_EACCESS is set in FLAG, then use effective IDs like `eaccess', 304 otherwise use real IDs like `access'. */ 305 extern int faccessat (int __fd, __const char *__file, int __type, int __flag) 306 __THROW __nonnull ((2)) __wur; 307 #endif /* Use GNU. */ 308 309 310 /* Values for the WHENCE argument to lseek. */ 311 #ifndef _STDIO_H /* <stdio.h> has the same definitions. */ 312 # define SEEK_SET 0 /* Seek from beginning of file. */ 313 # define SEEK_CUR 1 /* Seek from current position. */ 314 # define SEEK_END 2 /* Seek from end of file. */ 315 #endif 316 317 #if defined __USE_BSD && !defined L_SET 318 /* Old BSD names for the same constants; just for compatibility. */ 319 # define L_SET SEEK_SET 320 # define L_INCR SEEK_CUR 321 # define L_XTND SEEK_END 322 #endif 323 324 325 /* Move FD's file position to OFFSET bytes from the 326 beginning of the file (if WHENCE is SEEK_SET), 327 the current position (if WHENCE is SEEK_CUR), 328 or the end of the file (if WHENCE is SEEK_END). 329 Return the new file position. */ 330 #ifndef __USE_FILE_OFFSET64 331 extern __off_t lseek (int __fd, __off_t __offset, int __whence) __THROW; 332 #else 333 # ifdef __REDIRECT_NTH 334 extern __off64_t __REDIRECT_NTH (lseek, 335 (int __fd, __off64_t __offset, int __whence), 336 lseek64); 337 # else 338 # define lseek lseek64 339 # endif 340 #endif 341 #ifdef __USE_LARGEFILE64 342 extern __off64_t lseek64 (int __fd, __off64_t __offset, int __whence) 343 __THROW; 344 #endif 345 346 /* Close the file descriptor FD. 347 348 This function is a cancellation point and therefore not marked with 349 __THROW. */ 350 extern int close (int __fd); 351 352 /* Read NBYTES into BUF from FD. Return the 353 number read, -1 for errors or 0 for EOF. 354 355 This function is a cancellation point and therefore not marked with 356 __THROW. */ 357 extern ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur; 358 359 /* Write N bytes of BUF to FD. Return the number written, or -1. 360 361 This function is a cancellation point and therefore not marked with 362 __THROW. */ 363 extern ssize_t write (int __fd, __const void *__buf, size_t __n) __wur; 364 365 #ifdef __USE_UNIX98 366 # ifndef __USE_FILE_OFFSET64 367 /* Read NBYTES into BUF from FD at the given position OFFSET without 368 changing the file pointer. Return the number read, -1 for errors 369 or 0 for EOF. 370 371 This function is a cancellation point and therefore not marked with 372 __THROW. */ 373 extern ssize_t pread (int __fd, void *__buf, size_t __nbytes, 374 __off_t __offset) __wur; 375 376 /* Write N bytes of BUF to FD at the given position OFFSET without 377 changing the file pointer. Return the number written, or -1. 378 379 This function is a cancellation point and therefore not marked with 380 __THROW. */ 381 extern ssize_t pwrite (int __fd, __const void *__buf, size_t __n, 382 __off_t __offset) __wur; 383 # else 384 # ifdef __REDIRECT 385 extern ssize_t __REDIRECT (pread, (int __fd, void *__buf, size_t __nbytes, 386 __off64_t __offset), 387 pread64) __wur; 388 extern ssize_t __REDIRECT (pwrite, (int __fd, __const void *__buf, 389 size_t __nbytes, __off64_t __offset), 390 pwrite64) __wur; 391 # else 392 # define pread pread64 393 # define pwrite pwrite64 394 # endif 395 # endif 396 397 # ifdef __USE_LARGEFILE64 398 /* Read NBYTES into BUF from FD at the given position OFFSET without 399 changing the file pointer. Return the number read, -1 for errors 400 or 0 for EOF. */ 401 extern ssize_t pread64 (int __fd, void *__buf, size_t __nbytes, 402 __off64_t __offset) __wur; 403 /* Write N bytes of BUF to FD at the given position OFFSET without 404 changing the file pointer. Return the number written, or -1. */ 405 extern ssize_t pwrite64 (int __fd, __const void *__buf, size_t __n, 406 __off64_t __offset) __wur; 407 # endif 408 #endif 409 410 /* Create a one-way communication channel (pipe). 411 If successful, two file descriptors are stored in PIPEDES; 412 bytes written on PIPEDES[1] can be read from PIPEDES[0]. 413 Returns 0 if successful, -1 if not. */ 414 extern int pipe (int __pipedes[2]) __THROW __wur; 415 416 #ifdef __USE_GNU 417 /* Same as pipe but apply flags passed in FLAGS to the new file 418 descriptors. */ 419 extern int pipe2 (int __pipedes[2], int __flags) __THROW __wur; 420 #endif 421 422 /* Schedule an alarm. In SECONDS seconds, the process will get a SIGALRM. 423 If SECONDS is zero, any currently scheduled alarm will be cancelled. 424 The function returns the number of seconds remaining until the last 425 alarm scheduled would have signaled, or zero if there wasn't one. 426 There is no return value to indicate an error, but you can set `errno' 427 to 0 and check its value after calling `alarm', and this might tell you. 428 The signal may come late due to processor scheduling. */ 429 extern unsigned int alarm (unsigned int __seconds) __THROW; 430 431 /* Make the process sleep for SECONDS seconds, or until a signal arrives 432 and is not ignored. The function returns the number of seconds less 433 than SECONDS which it actually slept (thus zero if it slept the full time). 434 If a signal handler does a `longjmp' or modifies the handling of the 435 SIGALRM signal while inside `sleep' call, the handling of the SIGALRM 436 signal afterwards is undefined. There is no return value to indicate 437 error, but if `sleep' returns SECONDS, it probably didn't work. 438 439 This function is a cancellation point and therefore not marked with 440 __THROW. */ 441 extern unsigned int sleep (unsigned int __seconds); 442 443 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED 444 /* Set an alarm to go off (generating a SIGALRM signal) in VALUE 445 microseconds. If INTERVAL is nonzero, when the alarm goes off, the 446 timer is reset to go off every INTERVAL microseconds thereafter. 447 Returns the number of microseconds remaining before the alarm. */ 448 extern __useconds_t ualarm (__useconds_t __value, __useconds_t __interval) 449 __THROW; 450 451 /* Sleep USECONDS microseconds, or until a signal arrives that is not blocked 452 or ignored. 453 454 This function is a cancellation point and therefore not marked with 455 __THROW. */ 456 extern int usleep (__useconds_t __useconds); 457 #endif 458 459 460 /* Suspend the process until a signal arrives. 461 This always returns -1 and sets `errno' to EINTR. 462 463 This function is a cancellation point and therefore not marked with 464 __THROW. */ 465 extern int pause (void); 466 467 468 /* Change the owner and group of FILE. */ 469 extern int chown (__const char *__file, __uid_t __owner, __gid_t __group) 470 __THROW __nonnull ((1)) __wur; 471 472 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED 473 /* Change the owner and group of the file that FD is open on. */ 474 extern int fchown (int __fd, __uid_t __owner, __gid_t __group) __THROW __wur; 475 476 477 /* Change owner and group of FILE, if it is a symbolic 478 link the ownership of the symbolic link is changed. */ 479 extern int lchown (__const char *__file, __uid_t __owner, __gid_t __group) 480 __THROW __nonnull ((1)) __wur; 481 482 #endif /* Use BSD || X/Open Unix. */ 483 484 #ifdef __USE_ATFILE 485 /* Change the owner and group of FILE relative to the directory FD is open 486 on. */ 487 extern int fchownat (int __fd, __const char *__file, __uid_t __owner, 488 __gid_t __group, int __flag) 489 __THROW __nonnull ((2)) __wur; 490 #endif /* Use GNU. */ 491 492 /* Change the process's working directory to PATH. */ 493 extern int chdir (__const char *__path) __THROW __nonnull ((1)) __wur; 494 495 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED 496 /* Change the process's working directory to the one FD is open on. */ 497 extern int fchdir (int __fd) __THROW __wur; 498 #endif 499 500 /* Get the pathname of the current working directory, 501 and put it in SIZE bytes of BUF. Returns NULL if the 502 directory couldn't be determined or SIZE was too small. 503 If successful, returns BUF. In GNU, if BUF is NULL, 504 an array is allocated with `malloc'; the array is SIZE 505 bytes long, unless SIZE == 0, in which case it is as 506 big as necessary. */ 507 extern char *getcwd (char *__buf, size_t __size) __THROW __wur; 508 509 #ifdef __USE_GNU 510 /* Return a malloc'd string containing the current directory name. 511 If the environment variable `PWD' is set, and its value is correct, 512 that value is used. */ 513 extern char *get_current_dir_name (void) __THROW; 514 #endif 515 516 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED 517 /* Put the absolute pathname of the current working directory in BUF. 518 If successful, return BUF. If not, put an error message in 519 BUF and return NULL. BUF should be at least PATH_MAX bytes long. */ 520 extern char *getwd (char *__buf) 521 __THROW __nonnull ((1)) __attribute_deprecated__ __wur; 522 #endif 523 524 525 /* Duplicate FD, returning a new file descriptor on the same file. */ 526 extern int dup (int __fd) __THROW __wur; 527 528 /* Duplicate FD to FD2, closing FD2 and making it open on the same file. */ 529 extern int dup2 (int __fd, int __fd2) __THROW; 530 531 #ifdef __USE_GNU 532 /* Duplicate FD to FD2, closing FD2 and making it open on the same 533 file while setting flags according to FLAGS. */ 534 extern int dup3 (int __fd, int __fd2, int __flags) __THROW; 535 #endif 536 537 /* NULL-terminated array of "NAME=VALUE" environment variables. */ 538 extern char **__environ; 539 #ifdef __USE_GNU 540 extern char **environ; 541 #endif 542 543 544 /* Replace the current process, executing PATH with arguments ARGV and 545 environment ENVP. ARGV and ENVP are terminated by NULL pointers. */ 546 extern int execve (__const char *__path, char *__const __argv[], 547 char *__const __envp[]) __THROW __nonnull ((1)); 548 549 #ifdef __USE_XOPEN2K8 550 /* Execute the file FD refers to, overlaying the running program image. 551 ARGV and ENVP are passed to the new program, as for `execve'. */ 552 extern int fexecve (int __fd, char *__const __argv[], char *__const __envp[]) 553 __THROW; 554 #endif 555 556 557 /* Execute PATH with arguments ARGV and environment from `environ'. */ 558 extern int execv (__const char *__path, char *__const __argv[]) 559 __THROW __nonnull ((1)); 560 561 /* Execute PATH with all arguments after PATH until a NULL pointer, 562 and the argument after that for environment. */ 563 extern int execle (__const char *__path, __const char *__arg, ...) 564 __THROW __nonnull ((1)); 565 566 /* Execute PATH with all arguments after PATH until 567 a NULL pointer and environment from `environ'. */ 568 extern int execl (__const char *__path, __const char *__arg, ...) 569 __THROW __nonnull ((1)); 570 571 /* Execute FILE, searching in the `PATH' environment variable if it contains 572 no slashes, with arguments ARGV and environment from `environ'. */ 573 extern int execvp (__const char *__file, char *__const __argv[]) 574 __THROW __nonnull ((1)); 575 576 /* Execute FILE, searching in the `PATH' environment variable if 577 it contains no slashes, with all arguments after FILE until a 578 NULL pointer and environment from `environ'. */ 579 extern int execlp (__const char *__file, __const char *__arg, ...) 580 __THROW __nonnull ((1)); 581 582 #ifdef __USE_GNU 583 /* Execute FILE, searching in the `PATH' environment variable if it contains 584 no slashes, with arguments ARGV and environment from `environ'. */ 585 extern int execvpe (__const char *__file, char *__const __argv[], 586 char *__const __envp[]) 587 __THROW __nonnull ((1)); 588 #endif 589 590 591 #if defined __USE_MISC || defined __USE_XOPEN 592 /* Add INC to priority of the current process. */ 593 extern int nice (int __inc) __THROW __wur; 594 #endif 595 596 597 /* Terminate program execution with the low-order 8 bits of STATUS. */ 598 extern void _exit (int __status) __attribute__ ((__noreturn__)); 599 600 601 /* Get the `_PC_*' symbols for the NAME argument to `pathconf' and `fpathconf'; 602 the `_SC_*' symbols for the NAME argument to `sysconf'; 603 and the `_CS_*' symbols for the NAME argument to `confstr'. */ 604 #include <bits/confname.h> 605 606 /* Get file-specific configuration information about PATH. */ 607 extern long int pathconf (__const char *__path, int __name) 608 __THROW __nonnull ((1)); 609 610 /* Get file-specific configuration about descriptor FD. */ 611 extern long int fpathconf (int __fd, int __name) __THROW; 612 613 /* Get the value of the system variable NAME. */ 614 extern long int sysconf (int __name) __THROW; 615 616 #ifdef __USE_POSIX2 617 /* Get the value of the string-valued system variable NAME. */ 618 extern size_t confstr (int __name, char *__buf, size_t __len) __THROW; 619 #endif 620 621 622 /* Get the process ID of the calling process. */ 623 extern __pid_t getpid (void) __THROW; 624 625 /* Get the process ID of the calling process's parent. */ 626 extern __pid_t getppid (void) __THROW; 627 628 /* Get the process group ID of the calling process. 629 This function is different on old BSD. */ 630 #ifndef __FAVOR_BSD 631 extern __pid_t getpgrp (void) __THROW; 632 #else 633 # ifdef __REDIRECT_NTH 634 extern __pid_t __REDIRECT_NTH (getpgrp, (__pid_t __pid), __getpgid); 635 # else 636 # define getpgrp __getpgid 637 # endif 638 #endif 639 640 /* Get the process group ID of process PID. */ 641 extern __pid_t __getpgid (__pid_t __pid) __THROW; 642 #ifdef __USE_XOPEN_EXTENDED 643 extern __pid_t getpgid (__pid_t __pid) __THROW; 644 #endif 645 646 647 /* Set the process group ID of the process matching PID to PGID. 648 If PID is zero, the current process's process group ID is set. 649 If PGID is zero, the process ID of the process is used. */ 650 extern int setpgid (__pid_t __pid, __pid_t __pgid) __THROW; 651 652 #if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED 653 /* Both System V and BSD have `setpgrp' functions, but with different 654 calling conventions. The BSD function is the same as POSIX.1 `setpgid' 655 (above). The System V function takes no arguments and puts the calling 656 process in its on group like `setpgid (0, 0)'. 657 658 New programs should always use `setpgid' instead. 659 660 The default in GNU is to provide the System V function. The BSD 661 function is available under -D_BSD_SOURCE. */ 662 663 # ifndef __FAVOR_BSD 664 665 /* Set the process group ID of the calling process to its own PID. 666 This is exactly the same as `setpgid (0, 0)'. */ 667 extern int setpgrp (void) __THROW; 668 669 # else 670 671 /* Another name for `setpgid' (above). */ 672 # ifdef __REDIRECT_NTH 673 extern int __REDIRECT_NTH (setpgrp, (__pid_t __pid, __pid_t __pgrp), setpgid); 674 # else 675 # define setpgrp setpgid 676 # endif 677 678 # endif /* Favor BSD. */ 679 #endif /* Use SVID or BSD. */ 680 681 /* Create a new session with the calling process as its leader. 682 The process group IDs of the session and the calling process 683 are set to the process ID of the calling process, which is returned. */ 684 extern __pid_t setsid (void) __THROW; 685 686 #ifdef __USE_XOPEN_EXTENDED 687 /* Return the session ID of the given process. */ 688 extern __pid_t getsid (__pid_t __pid) __THROW; 689 #endif 690 691 /* Get the real user ID of the calling process. */ 692 extern __uid_t getuid (void) __THROW; 693 694 /* Get the effective user ID of the calling process. */ 695 extern __uid_t geteuid (void) __THROW; 696 697 /* Get the real group ID of the calling process. */ 698 extern __gid_t getgid (void) __THROW; 699 700 /* Get the effective group ID of the calling process. */ 701 extern __gid_t getegid (void) __THROW; 702 703 /* If SIZE is zero, return the number of supplementary groups 704 the calling process is in. Otherwise, fill in the group IDs 705 of its supplementary groups in LIST and return the number written. */ 706 extern int getgroups (int __size, __gid_t __list[]) __THROW __wur; 707 708 #ifdef __USE_GNU 709 /* Return nonzero iff the calling process is in group GID. */ 710 extern int group_member (__gid_t __gid) __THROW; 711 #endif 712 713 /* Set the user ID of the calling process to UID. 714 If the calling process is the super-user, set the real 715 and effective user IDs, and the saved set-user-ID to UID; 716 if not, the effective user ID is set to UID. */ 717 extern int setuid (__uid_t __uid) __THROW; 718 719 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED 720 /* Set the real user ID of the calling process to RUID, 721 and the effective user ID of the calling process to EUID. */ 722 extern int setreuid (__uid_t __ruid, __uid_t __euid) __THROW; 723 #endif 724 725 #if defined __USE_BSD || defined __USE_XOPEN2K 726 /* Set the effective user ID of the calling process to UID. */ 727 extern int seteuid (__uid_t __uid) __THROW; 728 #endif /* Use BSD. */ 729 730 /* Set the group ID of the calling process to GID. 731 If the calling process is the super-user, set the real 732 and effective group IDs, and the saved set-group-ID to GID; 733 if not, the effective group ID is set to GID. */ 734 extern int setgid (__gid_t __gid) __THROW; 735 736 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED 737 /* Set the real group ID of the calling process to RGID, 738 and the effective group ID of the calling process to EGID. */ 739 extern int setregid (__gid_t __rgid, __gid_t __egid) __THROW; 740 #endif 741 742 #if defined __USE_BSD || defined __USE_XOPEN2K 743 /* Set the effective group ID of the calling process to GID. */ 744 extern int setegid (__gid_t __gid) __THROW; 745 #endif /* Use BSD. */ 746 747 #ifdef __USE_GNU 748 /* Fetch the real user ID, effective user ID, and saved-set user ID, 749 of the calling process. */ 750 extern int getresuid (__uid_t *__ruid, __uid_t *__euid, __uid_t *__suid) 751 __THROW; 752 753 /* Fetch the real group ID, effective group ID, and saved-set group ID, 754 of the calling process. */ 755 extern int getresgid (__gid_t *__rgid, __gid_t *__egid, __gid_t *__sgid) 756 __THROW; 757 758 /* Set the real user ID, effective user ID, and saved-set user ID, 759 of the calling process to RUID, EUID, and SUID, respectively. */ 760 extern int setresuid (__uid_t __ruid, __uid_t __euid, __uid_t __suid) 761 __THROW; 762 763 /* Set the real group ID, effective group ID, and saved-set group ID, 764 of the calling process to RGID, EGID, and SGID, respectively. */ 765 extern int setresgid (__gid_t __rgid, __gid_t __egid, __gid_t __sgid) 766 __THROW; 767 #endif 768 769 770 /* Clone the calling process, creating an exact copy. 771 Return -1 for errors, 0 to the new process, 772 and the process ID of the new process to the old process. */ 773 extern __pid_t fork (void) __THROW; 774 775 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED 776 /* Clone the calling process, but without copying the whole address space. 777 The calling process is suspended until the new process exits or is 778 replaced by a call to `execve'. Return -1 for errors, 0 to the new process, 779 and the process ID of the new process to the old process. */ 780 extern __pid_t vfork (void) __THROW; 781 #endif /* Use BSD. */ 782 783 784 /* Return the pathname of the terminal FD is open on, or NULL on errors. 785 The returned storage is good only until the next call to this function. */ 786 extern char *ttyname (int __fd) __THROW; 787 788 /* Store at most BUFLEN characters of the pathname of the terminal FD is 789 open on in BUF. Return 0 on success, otherwise an error number. */ 790 extern int ttyname_r (int __fd, char *__buf, size_t __buflen) 791 __THROW __nonnull ((2)) __wur; 792 793 /* Return 1 if FD is a valid descriptor associated 794 with a terminal, zero if not. */ 795 extern int isatty (int __fd) __THROW; 796 797 #if defined __USE_BSD \ 798 || (defined __USE_XOPEN_EXTENDED && !defined __USE_UNIX98) 799 /* Return the index into the active-logins file (utmp) for 800 the controlling terminal. */ 801 extern int ttyslot (void) __THROW; 802 #endif 803 804 805 /* Make a link to FROM named TO. */ 806 extern int link (__const char *__from, __const char *__to) 807 __THROW __nonnull ((1, 2)) __wur; 808 809 #ifdef __USE_ATFILE 810 /* Like link but relative paths in TO and FROM are interpreted relative 811 to FROMFD and TOFD respectively. */ 812 extern int linkat (int __fromfd, __const char *__from, int __tofd, 813 __const char *__to, int __flags) 814 __THROW __nonnull ((2, 4)) __wur; 815 #endif 816 817 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K 818 /* Make a symbolic link to FROM named TO. */ 819 extern int symlink (__const char *__from, __const char *__to) 820 __THROW __nonnull ((1, 2)) __wur; 821 822 /* Read the contents of the symbolic link PATH into no more than 823 LEN bytes of BUF. The contents are not null-terminated. 824 Returns the number of characters read, or -1 for errors. */ 825 extern ssize_t readlink (__const char *__restrict __path, 826 char *__restrict __buf, size_t __len) 827 __THROW __nonnull ((1, 2)) __wur; 828 #endif /* Use BSD. */ 829 830 #ifdef __USE_ATFILE 831 /* Like symlink but a relative path in TO is interpreted relative to TOFD. */ 832 extern int symlinkat (__const char *__from, int __tofd, 833 __const char *__to) __THROW __nonnull ((1, 3)) __wur; 834 835 /* Like readlink but a relative PATH is interpreted relative to FD. */ 836 extern ssize_t readlinkat (int __fd, __const char *__restrict __path, 837 char *__restrict __buf, size_t __len) 838 __THROW __nonnull ((2, 3)) __wur; 839 #endif 840 841 /* Remove the link NAME. */ 842 extern int unlink (__const char *__name) __THROW __nonnull ((1)); 843 844 #ifdef __USE_ATFILE 845 /* Remove the link NAME relative to FD. */ 846 extern int unlinkat (int __fd, __const char *__name, int __flag) 847 __THROW __nonnull ((2)); 848 #endif 849 850 /* Remove the directory PATH. */ 851 extern int rmdir (__const char *__path) __THROW __nonnull ((1)); 852 853 854 /* Return the foreground process group ID of FD. */ 855 extern __pid_t tcgetpgrp (int __fd) __THROW; 856 857 /* Set the foreground process group ID of FD set PGRP_ID. */ 858 extern int tcsetpgrp (int __fd, __pid_t __pgrp_id) __THROW; 859 860 861 /* Return the login name of the user. 862 863 This function is a possible cancellation points and therefore not 864 marked with __THROW. */ 865 extern char *getlogin (void); 866 #if defined __USE_REENTRANT || defined __USE_POSIX199506 867 /* Return at most NAME_LEN characters of the login name of the user in NAME. 868 If it cannot be determined or some other error occurred, return the error 869 code. Otherwise return 0. 870 871 This function is a possible cancellation points and therefore not 872 marked with __THROW. */ 873 extern int getlogin_r (char *__name, size_t __name_len) __nonnull ((1)); 874 #endif 875 876 #ifdef __USE_BSD 877 /* Set the login name returned by `getlogin'. */ 878 extern int setlogin (__const char *__name) __THROW __nonnull ((1)); 879 #endif 880 881 882 #ifdef __USE_POSIX2 883 /* Get definitions and prototypes for functions to process the 884 arguments in ARGV (ARGC of them, minus the program name) for 885 options given in OPTS. */ 886 # define __need_getopt 887 # include <getopt.h> 888 #endif 889 890 891 #if defined __USE_BSD || defined __USE_UNIX98 892 /* Put the name of the current host in no more than LEN bytes of NAME. 893 The result is null-terminated if LEN is large enough for the full 894 name and the terminator. */ 895 extern int gethostname (char *__name, size_t __len) __THROW __nonnull ((1)); 896 #endif 897 898 899 #if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98) 900 /* Set the name of the current host to NAME, which is LEN bytes long. 901 This call is restricted to the super-user. */ 902 extern int sethostname (__const char *__name, size_t __len) 903 __THROW __nonnull ((1)) __wur; 904 905 /* Set the current machine's Internet number to ID. 906 This call is restricted to the super-user. */ 907 extern int sethostid (long int __id) __THROW __wur; 908 909 910 /* Get and set the NIS (aka YP) domain name, if any. 911 Called just like `gethostname' and `sethostname'. 912 The NIS domain name is usually the empty string when not using NIS. */ 913 extern int getdomainname (char *__name, size_t __len) 914 __THROW __nonnull ((1)) __wur; 915 extern int setdomainname (__const char *__name, size_t __len) 916 __THROW __nonnull ((1)) __wur; 917 918 919 /* Revoke access permissions to all processes currently communicating 920 with the control terminal, and then send a SIGHUP signal to the process 921 group of the control terminal. */ 922 extern int vhangup (void) __THROW; 923 924 /* Revoke the access of all descriptors currently open on FILE. */ 925 extern int revoke (__const char *__file) __THROW __nonnull ((1)) __wur; 926 927 928 /* Enable statistical profiling, writing samples of the PC into at most 929 SIZE bytes of SAMPLE_BUFFER; every processor clock tick while profiling 930 is enabled, the system examines the user PC and increments 931 SAMPLE_BUFFER[((PC - OFFSET) / 2) * SCALE / 65536]. If SCALE is zero, 932 disable profiling. Returns zero on success, -1 on error. */ 933 extern int profil (unsigned short int *__sample_buffer, size_t __size, 934 size_t __offset, unsigned int __scale) 935 __THROW __nonnull ((1)); 936 937 938 /* Turn accounting on if NAME is an existing file. The system will then write 939 a record for each process as it terminates, to this file. If NAME is NULL, 940 turn accounting off. This call is restricted to the super-user. */ 941 extern int acct (__const char *__name) __THROW; 942 943 944 /* Successive calls return the shells listed in `/etc/shells'. */ 945 extern char *getusershell (void) __THROW; 946 extern void endusershell (void) __THROW; /* Discard cached info. */ 947 extern void setusershell (void) __THROW; /* Rewind and re-read the file. */ 948 949 950 /* Put the program in the background, and dissociate from the controlling 951 terminal. If NOCHDIR is zero, do `chdir ("/")'. If NOCLOSE is zero, 952 redirects stdin, stdout, and stderr to /dev/null. */ 953 extern int daemon (int __nochdir, int __noclose) __THROW __wur; 954 #endif /* Use BSD || X/Open. */ 955 956 957 #if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_XOPEN2K) 958 /* Make PATH be the root directory (the starting point for absolute paths). 959 This call is restricted to the super-user. */ 960 extern int chroot (__const char *__path) __THROW __nonnull ((1)) __wur; 961 962 /* Prompt with PROMPT and read a string from the terminal without echoing. 963 Uses /dev/tty if possible; otherwise stderr and stdin. */ 964 extern char *getpass (__const char *__prompt) __nonnull ((1)); 965 #endif /* Use BSD || X/Open. */ 966 967 968 #if defined __USE_BSD || defined __USE_XOPEN || defined __USE_XOPEN2K 969 /* Make all changes done to FD actually appear on disk. 970 971 This function is a cancellation point and therefore not marked with 972 __THROW. */ 973 extern int fsync (int __fd); 974 #endif /* Use BSD || X/Open || Unix98. */ 975 976 977 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED 978 979 /* Return identifier for the current host. */ 980 extern long int gethostid (void); 981 982 /* Make all changes done to all files actually appear on disk. */ 983 extern void sync (void) __THROW; 984 985 986 /* Return the number of bytes in a page. This is the system's page size, 987 which is not necessarily the same as the hardware page size. */ 988 extern int getpagesize (void) __THROW __attribute__ ((__const__)); 989 990 991 /* Return the maximum number of file descriptors 992 the current process could possibly have. */ 993 extern int getdtablesize (void) __THROW; 994 995 996 /* Truncate FILE to LENGTH bytes. */ 997 # ifndef __USE_FILE_OFFSET64 998 extern int truncate (__const char *__file, __off_t __length) 999 __THROW __nonnull ((1)) __wur; 1000 # else 1001 # ifdef __REDIRECT_NTH 1002 extern int __REDIRECT_NTH (truncate, 1003 (__const char *__file, __off64_t __length), 1004 truncate64) __nonnull ((1)) __wur; 1005 # else 1006 # define truncate truncate64 1007 # endif 1008 # endif 1009 # ifdef __USE_LARGEFILE64 1010 extern int truncate64 (__const char *__file, __off64_t __length) 1011 __THROW __nonnull ((1)) __wur; 1012 # endif 1013 1014 #endif /* Use BSD || X/Open Unix. */ 1015 1016 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED || defined __USE_XOPEN2K 1017 1018 /* Truncate the file FD is open on to LENGTH bytes. */ 1019 # ifndef __USE_FILE_OFFSET64 1020 extern int ftruncate (int __fd, __off_t __length) __THROW __wur; 1021 # else 1022 # ifdef __REDIRECT_NTH 1023 extern int __REDIRECT_NTH (ftruncate, (int __fd, __off64_t __length), 1024 ftruncate64) __wur; 1025 # else 1026 # define ftruncate ftruncate64 1027 # endif 1028 # endif 1029 # ifdef __USE_LARGEFILE64 1030 extern int ftruncate64 (int __fd, __off64_t __length) __THROW __wur; 1031 # endif 1032 1033 #endif /* Use BSD || X/Open Unix || POSIX 2003. */ 1034 1035 1036 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED 1037 1038 /* Set the end of accessible data space (aka "the break") to ADDR. 1039 Returns zero on success and -1 for errors (with errno set). */ 1040 extern int brk (void *__addr) __THROW __wur; 1041 1042 /* Increase or decrease the end of accessible data space by DELTA bytes. 1043 If successful, returns the address the previous end of data space 1044 (i.e. the beginning of the new space, if DELTA > 0); 1045 returns (void *) -1 for errors (with errno set). */ 1046 extern void *sbrk (intptr_t __delta) __THROW; 1047 #endif 1048 1049 1050 #ifdef __USE_MISC 1051 /* Invoke `system call' number SYSNO, passing it the remaining arguments. 1052 This is completely system-dependent, and not often useful. 1053 1054 In Unix, `syscall' sets `errno' for all errors and most calls return -1 1055 for errors; in many systems you cannot pass arguments or get return 1056 values for all system calls (`pipe', `fork', and `getppid' typically 1057 among them). 1058 1059 In Mach, all system calls take normal arguments and always return an 1060 error code (zero for success). */ 1061 extern long int syscall (long int __sysno, ...) __THROW; 1062 1063 #endif /* Use misc. */ 1064 1065 1066 #if (defined __USE_MISC || defined __USE_XOPEN_EXTENDED) && !defined F_LOCK 1067 /* NOTE: These declarations also appear in <fcntl.h>; be sure to keep both 1068 files consistent. Some systems have them there and some here, and some 1069 software depends on the macros being defined without including both. */ 1070 1071 /* `lockf' is a simpler interface to the locking facilities of `fcntl'. 1072 LEN is always relative to the current file position. 1073 The CMD argument is one of the following. 1074 1075 This function is a cancellation point and therefore not marked with 1076 __THROW. */ 1077 1078 # define F_ULOCK 0 /* Unlock a previously locked region. */ 1079 # define F_LOCK 1 /* Lock a region for exclusive use. */ 1080 # define F_TLOCK 2 /* Test and lock a region for exclusive use. */ 1081 # define F_TEST 3 /* Test a region for other processes locks. */ 1082 1083 # ifndef __USE_FILE_OFFSET64 1084 extern int lockf (int __fd, int __cmd, __off_t __len) __wur; 1085 # else 1086 # ifdef __REDIRECT 1087 extern int __REDIRECT (lockf, (int __fd, int __cmd, __off64_t __len), 1088 lockf64) __wur; 1089 # else 1090 # define lockf lockf64 1091 # endif 1092 # endif 1093 # ifdef __USE_LARGEFILE64 1094 extern int lockf64 (int __fd, int __cmd, __off64_t __len) __wur; 1095 # endif 1096 #endif /* Use misc and F_LOCK not already defined. */ 1097 1098 1099 #ifdef __USE_GNU 1100 1101 /* Evaluate EXPRESSION, and repeat as long as it returns -1 with `errno' 1102 set to EINTR. */ 1103 1104 # define TEMP_FAILURE_RETRY(expression) \ 1105 (__extension__ \ 1106 ({ long int __result; \ 1107 do __result = (long int) (expression); \ 1108 while (__result == -1L && errno == EINTR); \ 1109 __result; })) 1110 #endif 1111 1112 #if defined __USE_POSIX199309 || defined __USE_UNIX98 1113 /* Synchronize at least the data part of a file with the underlying 1114 media. */ 1115 extern int fdatasync (int __fildes); 1116 #endif /* Use POSIX199309 */ 1117 1118 1119 /* XPG4.2 specifies that prototypes for the encryption functions must 1120 be defined here. */ 1121 #ifdef __USE_XOPEN 1122 /* Encrypt at most 8 characters from KEY using salt to perturb DES. */ 1123 extern char *crypt (__const char *__key, __const char *__salt) 1124 __THROW __nonnull ((1, 2)); 1125 1126 /* Encrypt data in BLOCK in place if EDFLAG is zero; otherwise decrypt 1127 block in place. */ 1128 extern void encrypt (char *__block, int __edflag) __THROW __nonnull ((1)); 1129 1130 1131 /* Swab pairs bytes in the first N bytes of the area pointed to by 1132 FROM and copy the result to TO. The value of TO must not be in the 1133 range [FROM - N + 1, FROM - 1]. If N is odd the first byte in FROM 1134 is without partner. */ 1135 extern void swab (__const void *__restrict __from, void *__restrict __to, 1136 ssize_t __n) __THROW __nonnull ((1, 2)); 1137 #endif 1138 1139 1140 /* The Single Unix specification demands this prototype to be here. 1141 It is also found in <stdio.h>. */ 1142 #ifdef __USE_XOPEN 1143 /* Return the name of the controlling terminal. */ 1144 extern char *ctermid (char *__s) __THROW; 1145 #endif 1146 1147 1148 /* Define some macros helping to catch buffer overflows. */ 1149 #if __USE_FORTIFY_LEVEL > 0 && defined __extern_always_inline 1150 # include <bits/unistd.h> 1151 #endif 1152 1153 __END_DECLS 1154 1155 #endif /* unistd.h */ 1156