Update.
[glibc.git] / posix / unistd.h
blob5f6067370e2c402194a4b1af7919ae7d1309b0e2
1 /* Copyright (C) 1991,92,93,94,95,96,97,98 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If not,
16 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. */
20 * POSIX Standard: 2.10 Symbolic Constants <unistd.h>
23 #ifndef _UNISTD_H
24 #define _UNISTD_H 1
26 #include <features.h>
28 __BEGIN_DECLS
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'. */
33 /* POSIX Standard approved as ISO/IEC 9945-1 as of August, 1988 and
34 extended by POSIX-1b (aka POSIX-4) and POSIX-1c (aka POSIX threads). */
35 #define _POSIX_VERSION 199506L
37 /* These are not #ifdef __USE_POSIX2 because they are
38 in the theoretically application-owned namespace. */
40 /* POSIX Standard approved as ISO/IEC 9945-2 as of December, 1993. */
41 #define _POSIX2_C_VERSION 199209L
43 /* The utilities on GNU systems also correspond to this version. */
44 #define _POSIX2_VERSION 199209L
46 /* If defined, the implementation supports the
47 C Language Bindings Option. */
48 #define _POSIX2_C_BIND 1
50 /* If defined, the implementation supports the
51 C Language Development Utilities Option. */
52 #define _POSIX2_C_DEV 1
54 /* If defined, the implementation supports the
55 Software Development Utilities Option. */
56 #define _POSIX2_SW_DEV 1
58 /* If defined, the implementation supports the
59 creation of locales with the localedef utility. */
60 #define _POSIX2_LOCALEDEF 1
62 /* X/Open version number to which the library conforms. It is selectable. */
63 #ifdef __USE_UNIX98
64 # define _XOPEN_VERSION 500
65 #else
66 # define _XOPEN_VERSION 4
67 #endif
69 /* Commands and utilities from XPG4 are available. */
70 #define _XOPEN_XCU_VERSION 4
72 /* We are compatible with the old published standards as well. */
73 #define _XOPEN_XPG2 1
74 #define _XOPEN_XPG3 1
75 #define _XOPEN_XPG4 1
77 /* The X/Open Unix extensions are available. */
78 #define _XOPEN_UNIX 1
80 /* Encryption is present. */
81 #define _XOPEN_CRYPT 1
83 /* The enhanced internationalization capabilities according to XPG4.2
84 are present. */
85 #define _XOPEN_ENH_I18N 1
87 /* The legacy interfaces are also available. */
88 #define _XOPEN_LEGACY 1
91 /* Get values of POSIX options:
93 If these symbols are defined, the corresponding features are
94 always available. If not, they may be available sometimes.
95 The current values can be obtained with `sysconf'.
97 _POSIX_JOB_CONTROL Job control is supported.
98 _POSIX_SAVED_IDS Processes have a saved set-user-ID
99 and a saved set-group-ID.
100 _POSIX_REALTIME_SIGNALS Real-time, queued signals are supported.
101 _POSIX_PRIORITY_SCHEDULING Priority scheduling is supported.
102 _POSIX_TIMERS POSIX.4 clocks and timers are supported.
103 _POSIX_ASYNCHRONOUS_IO Asynchronous I/O is supported.
104 _POSIX_PRIORITIZED_IO Prioritized asynchronous I/O is supported.
105 _POSIX_SYNCHRONIZED_IO Synchronizing file data is supported.
106 _POSIX_FSYNC The fsync function is present.
107 _POSIX_MAPPED_FILES Mapping of files to memory is supported.
108 _POSIX_MEMLOCK Locking of all memory is supported.
109 _POSIX_MEMLOCK_RANGE Locking of ranges of memory is supported.
110 _POSIX_MEMORY_PROTECTION Setting of memory protections is supported.
111 _POSIX_MESSAGE_PASSING POSIX.4 message queues are supported.
112 _POSIX_SEMAPHORES POSIX.4 counting semaphores are supported.
113 _POSIX_SHARED_MEMORY_OBJECTS POSIX.4 shared memory objects are supported.
114 _POSIX_THREADS POSIX.1c pthreads are supported.
115 _POSIX_THREAD_ATTR_STACKADDR Thread stack address attribute option supported.
116 _POSIX_THREAD_ATTR_STACKSIZE Thread stack size attribute option supported.
117 _POSIX_THREAD_SAFE_FUNCTIONS Thread-safe functions are supported.
118 _POSIX_THREAD_PRIORITY_SCHEDULING
119 POSIX.1c thread execution scheduling supported.
120 _POSIX_THREAD_PRIO_INHERIT Thread priority inheritance option supported.
121 _POSIX_THREAD_PRIO_PROTECT Thread priority protection option supported.
122 _POSIX_THREAD_PROCESS_SHARED Process-shared synchronization supported.
123 _POSIX_PII Protocol-independent interfaces are supported.
124 _POSIX_PII_XTI XTI protocol-indep. interfaces are supported.
125 _POSIX_PII_SOCKET Socket protocol-indep. interfaces are supported.
126 _POSIX_PII_INTERNET Internet family of protocols supported.
127 _POSIX_PII_INTERNET_STREAM Connection-mode Internet protocol supported.
128 _POSIX_PII_INTERNET_DGRAM Connectionless Internet protocol supported.
129 _POSIX_PII_OSI ISO/OSI family of protocols supported.
130 _POSIX_PII_OSI_COTS Connection-mode ISO/OSI service supported.
131 _POSIX_PII_OSI_CLTS Connectionless ISO/OSI service supported.
132 _POSIX_POLL Implementation supports `poll' function.
133 _POSIX_SELECT Implementation supports `select' and `pselect'.
135 _XOPEN_REALTIME X/Open realtime support is available.
136 _XOPEN_REALTIME_THREADS X/Open realtime thread support is available.
137 _XOPEN_SHM Shared memory interface according to XPG4.2.
139 _XBS5_ILP32_OFF32 Implementation provides environment with 32-bit
140 int, long, pointer, and off_t types.
141 _XBS5_ILP32_OFFBIG Implementation provides environment with 32-bit
142 int, long, and pointer and off_t with at least
143 64 bits.
144 _XBS5_LP64_OFF64 Implementation provides environment with 32-bit
145 int, and 64-bit long, pointer, and off_t types.
146 _XBS5_LPBIG_OFFBIG Implementation provides environment with at
147 least 32 bits int and long, pointer, and off_t
148 with at least 64 bits.
150 If any of these symbols is defined as -1, the corresponding option is not
151 true for any file. If any is defined as other than -1, the corresponding
152 option is true for all files. If a symbol is not defined at all, the value
153 for a specific file can be obtained from `pathconf' and `fpathconf'.
155 _POSIX_CHOWN_RESTRICTED Only the super user can use `chown' to change
156 the owner of a file. `chown' can only be used
157 to change the group ID of a file to a group of
158 which the calling process is a member.
159 _POSIX_NO_TRUNC Pathname components longer than
160 NAME_MAX generate an error.
161 _POSIX_VDISABLE If defined, if the value of an element of the
162 `c_cc' member of `struct termios' is
163 _POSIX_VDISABLE, no character will have the
164 effect associated with that element.
165 _POSIX_SYNC_IO Synchronous I/O may be performed.
166 _POSIX_ASYNC_IO Asynchronous I/O may be performed.
167 _POSIX_PRIO_IO Prioritized Asynchronous I/O may be performed.
169 Support for the Large File Support interface is not generally available.
170 If it is available the following constants are defined to one.
171 _LFS64_LARGEFILE Low-level I/O supports large files.
172 _LFS64_STDIO Standard I/O supports large files.
175 #include <bits/posix_opt.h>
177 /* Get the environment definitions from Unix98. */
178 #ifdef __USE_UNIX98
179 # include <bits/environments.h>
180 #endif
182 /* Standard file descriptors. */
183 #define STDIN_FILENO 0 /* Standard input. */
184 #define STDOUT_FILENO 1 /* Standard output. */
185 #define STDERR_FILENO 2 /* Standard error output. */
188 /* All functions that are not declared anywhere else. */
190 #include <bits/types.h>
192 #ifndef ssize_t
193 typedef __ssize_t ssize_t;
194 # define ssize_t ssize_t
195 #endif
197 #define __need_size_t
198 #define __need_NULL
199 #include <stddef.h>
201 #ifdef __USE_XOPEN
202 /* The Single Unix specification says that some more types are
203 available here. */
204 # ifndef gid_t
205 typedef __gid_t gid_t;
206 # define gid_t gid_t
207 # endif
209 # ifndef uid_t
210 typedef __uid_t uid_t;
211 # define uid_t uid_t
212 # endif
214 # ifndef off_t
215 # ifndef __USE_FILE_OFFSET64
216 typedef __off_t off_t;
217 # else
218 typedef __off64_t off_t;
219 # endif
220 # define off_t off_t
221 # endif
222 # if defined __USE_LARGEFILE64 && !defined off64_t
223 typedef __off64_t off64_t;
224 # define off64_t off64_t
225 # endif
227 # ifndef pid_t
228 typedef __pid_t pid_t;
229 # define pid_t pid_t
230 # endif
231 #endif /* X/Open */
233 #ifdef __USE_UNIX98
234 # ifndef intptr_t
235 typedef __intptr_t intptr_t;
236 # define intptr_t intptr_t
237 # endif
238 #endif /* Unix98 */
240 /* Values for the second argument to access.
241 These may be OR'd together. */
242 #define R_OK 4 /* Test for read permission. */
243 #define W_OK 2 /* Test for write permission. */
244 #define X_OK 1 /* Test for execute permission. */
245 #define F_OK 0 /* Test for existence. */
247 /* Test for access to NAME using the real UID and real GID. */
248 extern int __access __P ((__const char *__name, int __type));
249 extern int access __P ((__const char *__name, int __type));
251 #ifdef __USE_GNU
252 /* Test for access to NAME using the effective UID and GID
253 (as normal file operations use). */
254 extern int __euidaccess __P ((__const char *__name, int __type));
255 extern int euidaccess __P ((__const char *__name, int __type));
256 #endif
259 /* Values for the WHENCE argument to lseek. */
260 #ifndef _STDIO_H /* <stdio.h> has the same definitions. */
261 # define SEEK_SET 0 /* Seek from beginning of file. */
262 # define SEEK_CUR 1 /* Seek from current position. */
263 # define SEEK_END 2 /* Seek from end of file. */
264 #endif
266 #if defined __USE_BSD && !defined L_SET
267 /* Old BSD names for the same constants; just for compatibility. */
268 # define L_SET SEEK_SET
269 # define L_INCR SEEK_CUR
270 # define L_XTND SEEK_END
271 #endif
274 /* Move FD's file position to OFFSET bytes from the
275 beginning of the file (if WHENCE is SEEK_SET),
276 the current position (if WHENCE is SEEK_CUR),
277 or the end of the file (if WHENCE is SEEK_END).
278 Return the new file position. */
279 extern __off_t __lseek __P ((int __fd, __off_t __offset, int __whence));
280 extern __off64_t __lseek64 __P ((int __fd, __off64_t __offset, int __whence));
281 #ifndef __USE_FILE_OFFSET64
282 extern __off_t lseek __P ((int __fd, __off_t __offset, int __whence));
283 #else
284 # ifdef __REDIRECT
285 extern __off64_t __REDIRECT (lseek,
286 __P ((int __fd, __off64_t __offset,
287 int __whence)),
288 lseek64);
289 # else
290 # define lseek lseek64
291 # endif
292 #endif
293 #ifdef __USE_LARGEFILE64
294 extern __off64_t lseek64 __P ((int __fd, __off64_t __offset, int __whence));
295 #endif
297 /* Close the file descriptor FD. */
298 extern int __close __P ((int __fd));
299 extern int close __P ((int __fd));
301 /* Read NBYTES into BUF from FD. Return the
302 number read, -1 for errors or 0 for EOF. */
303 extern ssize_t __read __P ((int __fd, __ptr_t __buf, size_t __nbytes));
304 extern ssize_t read __P ((int __fd, __ptr_t __buf, size_t __nbytes));
306 /* Write N bytes of BUF to FD. Return the number written, or -1. */
307 extern ssize_t __write __P ((int __fd, __const __ptr_t __buf, size_t __n));
308 extern ssize_t write __P ((int __fd, __const __ptr_t __buf, size_t __n));
310 #ifdef __USE_UNIX98
311 /* Read NBYTES into BUF from FD at the given position OFFSET without
312 changing the file pointer. Return the number read, -1 for errors
313 or 0 for EOF. */
314 extern ssize_t __pread __P ((int __fd, __ptr_t __buf, size_t __nbytes,
315 __off_t __offset));
316 extern ssize_t __pread64 __P ((int __fd, __ptr_t __buf, size_t __nbytes,
317 __off64_t __offset));
318 /* Write N bytes of BUF to FD at the given position OFFSET without
319 changing the file pointer. Return the number written, or -1. */
320 extern ssize_t __pwrite __P ((int __fd, __const __ptr_t __buf, size_t __n,
321 __off_t __offset));
322 extern ssize_t __pwrite64 __P ((int __fd, __const __ptr_t __buf, size_t __n,
323 __off64_t __offset));
325 # ifndef __USE_FILE_OFFSET64
326 extern ssize_t pread __P ((int __fd, __ptr_t __buf, size_t __nbytes,
327 __off_t __offset));
328 extern ssize_t pwrite __P ((int __fd, __const __ptr_t __buf, size_t __n,
329 __off_t __offset));
330 # else
331 # ifdef __REDIRECT
332 extern ssize_t __REDIRECT (pread, __P ((int __fd, __ptr_t __buf,
333 size_t __nbytes,__off64_t __offset)),
334 pread64);
335 extern ssize_t __REDIRECT (pwrite, __P ((int __fd, __const __ptr_t __buf,
336 size_t __nbytes, __off64_t __offset)),
337 pwrite64);
338 # else
339 # define pread pread64
340 # define pwrite pwrite64
341 # endif
342 # endif
344 # ifdef __USE_LARGEFILE64
345 extern ssize_t pread64 __P ((int __fd, __ptr_t __buf, size_t __nbytes,
346 __off64_t __offset));
347 extern ssize_t pwrite64 __P ((int __fd, __const __ptr_t __buf, size_t __n,
348 __off64_t __offset));
349 # endif
350 #endif
352 /* Create a one-way communication channel (pipe).
353 If successful, two file descriptors are stored in PIPEDES;
354 bytes written on PIPEDES[1] can be read from PIPEDES[0].
355 Returns 0 if successful, -1 if not. */
356 extern int __pipe __P ((int __pipedes[2]));
357 extern int pipe __P ((int __pipedes[2]));
359 /* Schedule an alarm. In SECONDS seconds, the process will get a SIGALRM.
360 If SECONDS is zero, any currently scheduled alarm will be cancelled.
361 The function returns the number of seconds remaining until the last
362 alarm scheduled would have signaled, or zero if there wasn't one.
363 There is no return value to indicate an error, but you can set `errno'
364 to 0 and check its value after calling `alarm', and this might tell you.
365 The signal may come late due to processor scheduling. */
366 extern unsigned int alarm __P ((unsigned int __seconds));
368 /* Make the process sleep for SECONDS seconds, or until a signal arrives
369 and is not ignored. The function returns the number of seconds less
370 than SECONDS which it actually slept (thus zero if it slept the full time).
371 If a signal handler does a `longjmp' or modifies the handling of the
372 SIGALRM signal while inside `sleep' call, the handling of the SIGALRM
373 signal afterwards is undefined. There is no return value to indicate
374 error, but if `sleep' returns SECONDS, it probably didn't work. */
375 extern unsigned int __sleep __P ((unsigned int __seconds));
376 extern unsigned int sleep __P ((unsigned int __seconds));
378 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
379 /* Set an alarm to go off (generating a SIGALRM signal) in VALUE
380 microseconds. If INTERVAL is nonzero, when the alarm goes off, the
381 timer is reset to go off every INTERVAL microseconds thereafter.
382 Returns the number of microseconds remaining before the alarm. */
383 extern unsigned int ualarm __P ((unsigned int __value,
384 unsigned int __interval));
386 /* Sleep USECONDS microseconds, or until a signal arrives that is not blocked
387 or ignored. */
388 extern void usleep __P ((unsigned int __useconds));
389 #endif
392 /* Suspend the process until a signal arrives.
393 This always returns -1 and sets `errno' to EINTR. */
394 extern int pause __P ((void));
397 /* Change the owner and group of FILE. */
398 extern int __chown __P ((__const char *__file,
399 __uid_t __owner, __gid_t __group));
400 extern int chown __P ((__const char *__file,
401 __uid_t __owner, __gid_t __group));
403 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
404 /* Change the owner and group of the file that FD is open on. */
405 extern int __fchown __P ((int __fd,
406 __uid_t __owner, __gid_t __group));
407 extern int fchown __P ((int __fd,
408 __uid_t __owner, __gid_t __group));
411 /* Change owner and group of FILE, if it is a symbolic
412 link the ownership of the symbolic link is changed. */
413 extern int __lchown __P ((__const char *__file, __uid_t __owner,
414 __gid_t __group));
415 extern int lchown __P ((__const char *__file, __uid_t __owner,
416 __gid_t __group));
418 #endif /* Use BSD || X/Open Unix. */
420 /* Change the process's working directory to PATH. */
421 extern int __chdir __P ((__const char *__path));
422 extern int chdir __P ((__const char *__path));
424 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
425 /* Change the process's working directory to the one FD is open on. */
426 extern int __fchdir __P ((int __fd));
427 extern int fchdir __P ((int __fd));
428 #endif
430 /* Get the pathname of the current working directory,
431 and put it in SIZE bytes of BUF. Returns NULL if the
432 directory couldn't be determined or SIZE was too small.
433 If successful, returns BUF. In GNU, if BUF is NULL,
434 an array is allocated with `malloc'; the array is SIZE
435 bytes long, unless SIZE == 0, in which case it is as
436 big as necessary. */
437 extern char *__getcwd __P ((char *__buf, size_t __size));
438 extern char *getcwd __P ((char *__buf, size_t __size));
440 #ifdef __USE_GNU
441 /* Return a malloc'd string containing the current directory name.
442 If the environment variable `PWD' is set, and its value is correct,
443 that value is used. */
444 extern char *get_current_dir_name __P ((void));
446 /* Get the canonical absolute name of the named directory, and put it in SIZE
447 bytes of BUF. Returns NULL if the directory couldn't be determined or
448 SIZE was too small. If successful, returns BUF. In GNU, if BUF is
449 NULL, an array is allocated with `malloc'; the array is SIZE bytes long,
450 unless SIZE <= 0, in which case it is as big as necessary. */
452 char *__canonicalize_directory_name_internal __P ((__const char *__thisdir,
453 char *__buf,
454 size_t __size));
455 #endif
457 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
458 /* Put the absolute pathname of the current working directory in BUF.
459 If successful, return BUF. If not, put an error message in
460 BUF and return NULL. BUF should be at least PATH_MAX bytes long. */
461 extern char *getwd __P ((char *__buf));
462 #endif
465 /* Duplicate FD, returning a new file descriptor on the same file. */
466 extern int __dup __P ((int __fd));
467 extern int dup __P ((int __fd));
469 /* Duplicate FD to FD2, closing FD2 and making it open on the same file. */
470 extern int __dup2 __P ((int __fd, int __fd2));
471 extern int dup2 __P ((int __fd, int __fd2));
473 /* NULL-terminated array of "NAME=VALUE" environment variables. */
474 extern char **__environ;
475 #ifdef __USE_GNU
476 extern char **environ;
477 #endif
480 /* Replace the current process, executing PATH with arguments ARGV and
481 environment ENVP. ARGV and ENVP are terminated by NULL pointers. */
482 extern int __execve __P ((__const char *__path, char *__const __argv[],
483 char *__const __envp[]));
484 extern int execve __P ((__const char *__path, char *__const __argv[],
485 char *__const __envp[]));
487 #ifdef __USE_GNU
488 /* Execute the file FD refers to, overlaying the running program image.
489 ARGV and ENVP are passed to the new program, as for `execve'. */
490 extern int fexecve __P ((int __fd,
491 char *__const __argv[], char *__const __envp[]));
493 #endif
496 /* Execute PATH with arguments ARGV and environment from `environ'. */
497 extern int execv __P ((__const char *__path, char *__const __argv[]));
499 /* Execute PATH with all arguments after PATH until a NULL pointer,
500 and the argument after that for environment. */
501 extern int execle __P ((__const char *__path, __const char *__arg, ...));
503 /* Execute PATH with all arguments after PATH until
504 a NULL pointer and environment from `environ'. */
505 extern int execl __P ((__const char *__path, __const char *__arg, ...));
507 /* Execute FILE, searching in the `PATH' environment variable if it contains
508 no slashes, with arguments ARGV and environment from `environ'. */
509 extern int execvp __P ((__const char *__file, char *__const __argv[]));
511 /* Execute FILE, searching in the `PATH' environment variable if
512 it contains no slashes, with all arguments after FILE until a
513 NULL pointer and environment from `environ'. */
514 extern int execlp __P ((__const char *__file, __const char *__arg, ...));
517 #if defined __USE_MISC || defined __USE_XOPEN
518 /* Add INC to priority of the current process. */
519 extern int nice __P ((int __inc));
520 #endif
523 /* Terminate program execution with the low-order 8 bits of STATUS. */
524 extern void _exit __P ((int __status)) __attribute__ ((__noreturn__));
527 /* Get the `_PC_*' symbols for the NAME argument to `pathconf' and `fpathconf';
528 the `_SC_*' symbols for the NAME argument to `sysconf';
529 and the `_CS_*' symbols for the NAME argument to `confstr'. */
530 #include <bits/confname.h>
532 /* Get file-specific configuration information about PATH. */
533 extern long int __pathconf __P ((__const char *__path, int __name));
534 extern long int pathconf __P ((__const char *__path, int __name));
536 /* Get file-specific configuration about descriptor FD. */
537 extern long int __fpathconf __P ((int __fd, int __name));
538 extern long int fpathconf __P ((int __fd, int __name));
540 /* Get the value of the system variable NAME. */
541 extern long int __sysconf __P ((int __name));
542 extern long int sysconf __P ((int __name));
544 #ifdef __USE_POSIX2
545 /* Get the value of the string-valued system variable NAME. */
546 extern size_t confstr __P ((int __name, char *__buf, size_t __len));
547 #endif
550 /* Get the process ID of the calling process. */
551 extern __pid_t __getpid __P ((void));
552 extern __pid_t getpid __P ((void));
554 /* Get the process ID of the calling process's parent. */
555 extern __pid_t __getppid __P ((void));
556 extern __pid_t getppid __P ((void));
558 /* Get the process group ID of the calling process.
559 This function is different on old BSD. */
560 #ifndef __FAVOR_BSD
561 extern __pid_t getpgrp __P ((void));
562 #else
563 # ifdef __REDIRECT
564 extern __pid_t __REDIRECT (getpgrp, __P ((__pid_t __pid)), __getpgid);
565 # else
566 # define getpgrp __getpgid
567 # endif
568 #endif
570 /* Get the process group ID of process PID. */
571 extern __pid_t __getpgid __P ((__pid_t __pid));
572 #ifdef __USE_XOPEN_EXTENDED
573 extern __pid_t getpgid __P ((__pid_t __pid));
574 #endif
577 /* Set the process group ID of the process matching PID to PGID.
578 If PID is zero, the current process's process group ID is set.
579 If PGID is zero, the process ID of the process is used. */
580 extern int __setpgid __P ((__pid_t __pid, __pid_t __pgid));
581 extern int setpgid __P ((__pid_t __pid, __pid_t __pgid));
583 #if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
584 /* Both System V and BSD have `setpgrp' functions, but with different
585 calling conventions. The BSD function is the same as POSIX.1 `setpgid'
586 (above). The System V function takes no arguments and puts the calling
587 process in its on group like `setpgid (0, 0)'.
589 New programs should always use `setpgid' instead.
591 The default in GNU is to provide the System V function. The BSD
592 function is available under -D_BSD_SOURCE. */
594 # ifndef __FAVOR_BSD
596 /* Set the process group ID of the calling process to its own PID.
597 This is exactly the same as `setpgid (0, 0)'. */
598 extern int setpgrp __P ((void));
600 # else
602 /* Another name for `setpgid' (above). */
603 # ifdef __REDIRECT
604 extern int __REDIRECT (setpgrp, __P ((__pid_t __pid, __pid_t __pgrp)),
605 setpgid);
606 # else
607 # define setpgrp setpgid
608 # endif
610 # endif /* Favor BSD. */
611 #endif /* Use SVID or BSD. */
613 /* Create a new session with the calling process as its leader.
614 The process group IDs of the session and the calling process
615 are set to the process ID of the calling process, which is returned. */
616 extern __pid_t __setsid __P ((void));
617 extern __pid_t setsid __P ((void));
619 #ifdef __USE_XOPEN_EXTENDED
620 /* Return the session ID of the given process. */
621 extern __pid_t getsid __P ((__pid_t __pid));
622 #endif
624 /* Get the real user ID of the calling process. */
625 extern __uid_t __getuid __P ((void));
626 extern __uid_t getuid __P ((void));
628 /* Get the effective user ID of the calling process. */
629 extern __uid_t __geteuid __P ((void));
630 extern __uid_t geteuid __P ((void));
632 /* Get the real group ID of the calling process. */
633 extern __gid_t __getgid __P ((void));
634 extern __gid_t getgid __P ((void));
636 /* Get the effective group ID of the calling process. */
637 extern __gid_t __getegid __P ((void));
638 extern __gid_t getegid __P ((void));
640 /* If SIZE is zero, return the number of supplementary groups
641 the calling process is in. Otherwise, fill in the group IDs
642 of its supplementary groups in LIST and return the number written. */
643 extern int __getgroups __P ((int __size, __gid_t __list[]));
644 extern int getgroups __P ((int __size, __gid_t __list[]));
646 #ifdef __USE_GNU
647 /* Return nonzero iff the calling process is in group GID. */
648 extern int __group_member __P ((__gid_t __gid));
649 extern int group_member __P ((__gid_t __gid));
650 #endif
652 /* Set the user ID of the calling process to UID.
653 If the calling process is the super-user, set the real
654 and effective user IDs, and the saved set-user-ID to UID;
655 if not, the effective user ID is set to UID. */
656 extern int __setuid __P ((__uid_t __uid));
657 extern int setuid __P ((__uid_t __uid));
659 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
660 /* Set the real user ID of the calling process to RUID,
661 and the effective user ID of the calling process to EUID. */
662 extern int __setreuid __P ((__uid_t __ruid, __uid_t __euid));
663 extern int setreuid __P ((__uid_t __ruid, __uid_t __euid));
664 #endif
666 #ifdef __USE_BSD
667 /* Set the effective user ID of the calling process to UID. */
668 extern int seteuid __P ((__uid_t __uid));
669 #endif /* Use BSD. */
671 /* Set the group ID of the calling process to GID.
672 If the calling process is the super-user, set the real
673 and effective group IDs, and the saved set-group-ID to GID;
674 if not, the effective group ID is set to GID. */
675 extern int __setgid __P ((__gid_t __gid));
676 extern int setgid __P ((__gid_t __gid));
678 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
679 /* Set the real group ID of the calling process to RGID,
680 and the effective group ID of the calling process to EGID. */
681 extern int __setregid __P ((__gid_t __rgid, __gid_t __egid));
682 extern int setregid __P ((__gid_t __rgid, __gid_t __egid));
683 #endif
685 #ifdef __USE_BSD
686 /* Set the effective group ID of the calling process to GID. */
687 extern int setegid __P ((__gid_t __gid));
688 #endif /* Use BSD. */
691 /* Clone the calling process, creating an exact copy.
692 Return -1 for errors, 0 to the new process,
693 and the process ID of the new process to the old process. */
694 extern __pid_t __fork __P ((void));
695 extern __pid_t fork __P ((void));
697 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
698 /* Clone the calling process, but without copying the whole address space.
699 The calling process is suspended until the new process exits or is
700 replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
701 and the process ID of the new process to the old process. */
702 extern __pid_t __vfork __P ((void));
703 extern __pid_t vfork __P ((void));
704 #endif /* Use BSD. */
707 /* Return the pathname of the terminal FD is open on, or NULL on errors.
708 The returned storage is good only until the next call to this function. */
709 extern char *ttyname __P ((int __fd));
711 /* Store at most BUFLEN characters of the pathname of the terminal FD is
712 open on in BUF. Return 0 on success, otherwise an error number. */
713 extern int __ttyname_r __P ((int __fd, char *__buf, size_t __buflen));
714 extern int ttyname_r __P ((int __fd, char *__buf, size_t __buflen));
716 /* Return 1 if FD is a valid descriptor associated
717 with a terminal, zero if not. */
718 extern int __isatty __P ((int __fd));
719 extern int isatty __P ((int __fd));
721 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
722 /* Return the index into the active-logins file (utmp) for
723 the controlling terminal. */
724 extern int ttyslot __P ((void));
725 #endif
728 /* Make a link to FROM named TO. */
729 extern int __link __P ((__const char *__from, __const char *__to));
730 extern int link __P ((__const char *__from, __const char *__to));
732 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
733 /* Make a symbolic link to FROM named TO. */
734 extern int __symlink __P ((__const char *__from, __const char *__to));
735 extern int symlink __P ((__const char *__from, __const char *__to));
737 /* Read the contents of the symbolic link PATH into no more than
738 LEN bytes of BUF. The contents are not null-terminated.
739 Returns the number of characters read, or -1 for errors. */
740 extern int __readlink __P ((__const char *__path, char *__buf, size_t __len));
741 extern int readlink __P ((__const char *__path, char *__buf, size_t __len));
742 #endif /* Use BSD. */
744 /* Remove the link NAME. */
745 extern int __unlink __P ((__const char *__name));
746 extern int unlink __P ((__const char *__name));
748 /* Remove the directory PATH. */
749 extern int __rmdir __P ((__const char *__path));
750 extern int rmdir __P ((__const char *__path));
753 /* Return the foreground process group ID of FD. */
754 extern __pid_t tcgetpgrp __P ((int __fd));
756 /* Set the foreground process group ID of FD set PGRP_ID. */
757 extern int tcsetpgrp __P ((int __fd, __pid_t __pgrp_id));
760 /* Return the login name of the user. */
761 extern char *getlogin __P ((void));
762 #ifdef __USE_REENTRANT
763 /* Return at most NAME_LEN characters of the login name of the user in NAME.
764 If it cannot be determined or some other error occurred, return the error
765 code. Otherwise return 0. */
766 extern int getlogin_r __P ((char *__name, size_t __name_len));
767 #endif
769 #ifdef __USE_BSD
770 /* Set the login name returned by `getlogin'. */
771 extern int setlogin __P ((__const char *__name));
772 #endif
775 #ifdef __USE_POSIX2
776 /* Process the arguments in ARGV (ARGC of them, minus
777 the program name) for options given in OPTS.
779 If `opterr' is zero, no messages are generated
780 for invalid options; it defaults to 1.
781 `optind' is the current index into ARGV.
782 `optarg' is the argument corresponding to the current option.
783 Return the option character from OPTS just read.
784 Return -1 when there are no more options.
785 For unrecognized options, or options missing arguments,
786 `optopt' is set to the option letter, and '?' is returned.
788 The OPTS string is a list of characters which are recognized option
789 letters, optionally followed by colons, specifying that that letter
790 takes an argument, to be placed in `optarg'.
792 If a letter in OPTS is followed by two colons, its argument is optional.
793 This behavior is specific to the GNU `getopt'.
795 The argument `--' causes premature termination of argument scanning,
796 explicitly telling `getopt' that there are no more options.
798 If OPTS begins with `--', then non-option arguments
799 are treated as arguments to the option '\0'.
800 This behavior is specific to the GNU `getopt'. */
801 extern int getopt __P ((int __argc, char *__const * __argv,
802 __const char *__opts));
803 extern int opterr;
804 extern int optind;
805 extern int optopt;
806 extern char *optarg;
807 #endif
810 #if defined __USE_BSD || defined __USE_XOPEN
812 /* Put the name of the current host in no more than LEN bytes of NAME.
813 The result is null-terminated if LEN is large enough for the full
814 name and the terminator. */
815 extern int __gethostname __P ((char *__name, size_t __len));
816 extern int gethostname __P ((char *__name, size_t __len));
818 /* Set the name of the current host to NAME, which is LEN bytes long.
819 This call is restricted to the super-user. */
820 extern int sethostname __P ((__const char *__name, size_t __len));
822 /* Set the current machine's Internet number to ID.
823 This call is restricted to the super-user. */
824 extern int sethostid __P ((long int __id));
827 /* Get and set the NIS (aka YP) domain name, if any.
828 Called just like `gethostname' and `sethostname'.
829 The NIS domain name is usually the empty string when not using NIS. */
830 extern int getdomainname __P ((char *__name, size_t __len));
831 extern int setdomainname __P ((__const char *__name, size_t __len));
834 /* Make all changes done to FD actually appear on disk. */
835 extern int fsync __P ((int __fd));
838 /* Revoke access permissions to all processes currently communicating
839 with the control terminal, and then send a SIGHUP signal to the process
840 group of the control terminal. */
841 extern int vhangup __P ((void));
843 /* Revoke the access of all descriptors currently open on FILE. */
844 extern int revoke __P ((__const char *__file));
847 /* Enable statistical profiling, writing samples of the PC into at most
848 SIZE bytes of SAMPLE_BUFFER; every processor clock tick while profiling
849 is enabled, the system examines the user PC and increments
850 SAMPLE_BUFFER[((PC - OFFSET) / 2) * SCALE / 65536]. If SCALE is zero,
851 disable profiling. Returns zero on success, -1 on error. */
852 extern int __profil __P ((unsigned short int *__sample_buffer, size_t __size,
853 size_t __offset, unsigned int __scale));
854 extern int profil __P ((unsigned short int *__sample_buffer, size_t __size,
855 size_t __offset, unsigned int __scale));
858 /* Turn accounting on if NAME is an existing file. The system will then write
859 a record for each process as it terminates, to this file. If NAME is NULL,
860 turn accounting off. This call is restricted to the super-user. */
861 extern int acct __P ((__const char *__name));
863 /* Make PATH be the root directory (the starting point for absolute paths).
864 This call is restricted to the super-user. */
865 extern int chroot __P ((__const char *__path));
868 /* Successive calls return the shells listed in `/etc/shells'. */
869 extern char *getusershell __P ((void));
870 extern void endusershell __P ((void)); /* Discard cached info. */
871 extern void setusershell __P ((void)); /* Rewind and re-read the file. */
874 /* Prompt with PROMPT and read a string from the terminal without echoing.
875 Uses /dev/tty if possible; otherwise stderr and stdin. */
876 extern char *getpass __P ((__const char *__prompt));
878 /* Put the program in the background, and dissociate from the controlling
879 terminal. If NOCHDIR is zero, do `chdir ("/")'. If NOCLOSE is zero,
880 redirects stdin, stdout, and stderr to /dev/null. */
881 extern int daemon __P ((int __nochdir, int __noclose));
883 #endif /* Use BSD || X/Open. */
886 #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
888 /* Return the current machine's Internet number. */
889 extern long int gethostid __P ((void));
891 /* Make all changes done to all files actually appear on disk. */
892 extern int sync __P ((void));
895 /* Return the number of bytes in a page. This is the system's page size,
896 which is not necessarily the same as the hardware page size. */
897 extern int __getpagesize __P ((void));
898 extern int getpagesize __P ((void));
901 /* Truncate FILE to LENGTH bytes. */
902 #ifndef __USE_FILE_OFFSET64
903 extern int truncate __P ((__const char *__file, __off_t __length));
904 #else
905 # ifdef __REDIRECT
906 extern int __REDIRECT (truncate,
907 __P ((__const char *__file, __off64_t __length)),
908 truncate64);
909 # else
910 # define truncate truncate64
911 # endif
912 #endif
913 #ifdef __USE_LARGEFILE64
914 extern int truncate64 __P ((__const char *__file, __off64_t __length));
915 #endif
917 /* Truncate the file FD is open on to LENGTH bytes. */
918 extern int __ftruncate __P ((int __fd, __off_t __length));
919 #ifndef __USE_FILE_OFFSET64
920 extern int ftruncate __P ((int __fd, __off_t __length));
921 #else
922 # ifdef __REDIRECT
923 extern int __REDIRECT (ftruncate, __P ((int __fd, __off64_t __length)),
924 ftruncate64);
925 # else
926 # define ftruncate ftruncate64
927 # endif
928 #endif
929 #ifdef __USE_LARGEFILE64
930 extern int ftruncate64 __P ((int __fd, __off64_t __length));
931 #endif
934 /* Return the maximum number of file descriptors
935 the current process could possibly have. */
936 extern int __getdtablesize __P ((void));
937 extern int getdtablesize __P ((void));
939 #endif /* Use BSD || X/Open Unix. */
942 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
944 /* Set the end of accessible data space (aka "the break") to ADDR.
945 Returns zero on success and -1 for errors (with errno set). */
946 extern int __brk __P ((__ptr_t __addr));
947 extern int brk __P ((__ptr_t __addr));
949 # define __need_ptrdiff_t
950 # include <stddef.h>
952 /* Increase or decrease the end of accessible data space by DELTA bytes.
953 If successful, returns the address the previous end of data space
954 (i.e. the beginning of the new space, if DELTA > 0);
955 returns (void *) -1 for errors (with errno set). */
956 extern __ptr_t __sbrk __P ((ptrdiff_t __delta));
957 extern __ptr_t sbrk __P ((ptrdiff_t __delta));
958 #endif
961 #ifdef __USE_MISC
962 /* Invoke `system call' number SYSNO, passing it the remaining arguments.
963 This is completely system-dependent, and not often useful.
965 In Unix, `syscall' sets `errno' for all errors and most calls return -1
966 for errors; in many systems you cannot pass arguments or get return
967 values for all system calls (`pipe', `fork', and `getppid' typically
968 among them).
970 In Mach, all system calls take normal arguments and always return an
971 error code (zero for success). */
972 extern long int syscall __P ((long int __sysno, ...));
974 #endif /* Use misc. */
977 #if (defined __USE_MISC || defined __USE_XOPEN_EXTENDED) && !defined F_LOCK
978 /* NOTE: These declarations also appear in <fcntl.h>; be sure to keep both
979 files consistent. Some systems have them there and some here, and some
980 software depends on the macros being defined without including both. */
982 /* `lockf' is a simpler interface to the locking facilities of `fcntl'.
983 LEN is always relative to the current file position.
984 The CMD argument is one of the following. */
986 # define F_ULOCK 0 /* Unlock a previously locked region. */
987 # define F_LOCK 1 /* Lock a region for exclusive use. */
988 # define F_TLOCK 2 /* Test and lock a region for exclusive use. */
989 # define F_TEST 3 /* Test a region for other processes locks. */
991 # ifndef __USE_FILE_OFFSET64
992 extern int lockf __P ((int __fd, int __cmd, __off_t __len));
993 # else
994 # ifdef __REDIRECT
995 extern int __REDIRECT (lockf, __P ((int __fd, int __cmd, __off64_t __len)),
996 lockf64);
997 # else
998 # define lockf lockf64
999 # endif
1000 # endif
1001 # ifdef __USE_LARGEFILE64
1002 extern int lockf64 __P ((int __fd, int __cmd, __off64_t __len));
1003 # endif
1004 #endif /* Use misc and F_LOCK not already defined. */
1007 #ifdef __USE_GNU
1009 /* Evaluate EXPRESSION, and repeat as long as it returns -1 with `errno'
1010 set to EINTR. */
1012 # define TEMP_FAILURE_RETRY(expression) \
1013 (__extension__ \
1014 ({ long int __result; \
1015 do __result = (long int) (expression); \
1016 while (__result == -1L && errno == EINTR); \
1017 __result; })) \
1020 /* This variable is set nonzero at startup if the process's effective
1021 IDs differ from its real IDs, or it is otherwise indicated that
1022 extra security should be used. When this is set the dynamic linker
1023 and some functions contained in the C library ignore various
1024 environment variables that normally affect them. */
1025 extern int __libc_enable_secure;
1027 #endif
1029 #if defined __USE_POSIX199309 || defined __USE_UNIX98
1030 /* Synchronize at least the data part of a file with the underlying
1031 media. */
1032 extern int fdatasync __P ((int __fildes));
1033 #endif /* Use POSIX199309 */
1036 /* XPG4.2 specifies that prototypes for the encryption functions must
1037 be defined here. */
1038 #ifdef __USE_XOPEN
1039 /* Encrypt at most 8 characters from KEY using salt to perturb DES. */
1040 extern char *crypt __P ((__const char *__key, __const char *__salt));
1042 /* Setup DES tables according KEY. */
1043 extern void setkey __P ((__const char *__key));
1045 /* Encrypt data in BLOCK in place if EDFLAG is zero; otherwise decrypt
1046 block in place. */
1047 extern void encrypt __P ((char *__block, int __edflag));
1050 /* Swab pairs bytes in the first N bytes of the area pointed to by
1051 FROM and copy the result to TO. The value of TO must not be in the
1052 range [FROM - N + 1, FROM - 1]. If N is odd the first byte in FROM
1053 is without partner. */
1054 extern void swab __P ((__const __ptr_t __from, __ptr_t __to, ssize_t __n));
1055 #endif
1058 /* The Single Unix specification, version 2, demands these prototypes
1059 to be here. They are also found in <stdio.h>. */
1060 #ifdef __USE_XOPEN
1061 /* Return the name of the controlling terminal. */
1062 extern char *ctermid __P ((char *__s));
1064 /* Return the name of the current user. This function should not be
1065 used and might go away some time. */
1066 extern char *cuserid __P ((char *__s));
1068 /* Rename file OLD to NEW. */
1069 extern int rename __P ((__const char *__old, __const char *__new));
1070 #endif
1073 #ifdef __USE_POSIX199309
1074 /* This function is only available if the system has POSIX threads. */
1076 /* Install handlers to be called when a new process is created with FORK.
1077 The PREPARE handler is called in the parent process just before performing
1078 FORK. The PARENT handler is called in the parent process just after FORK.
1079 The CHILD handler is called in the child process. Each of the three
1080 handlers can be NULL, meaning that no handler needs to be called at that
1081 point.
1082 PTHREAD_ATFORK can be called several times, in which case the PREPARE
1083 handlers are called in LIFO order (last added with PTHREAD_ATFORK,
1084 first called before FORK), and the PARENT and CHILD handlers are called
1085 in FIFO (first added, first called). */
1086 extern int pthread_atfork __P ((void (*__prepare) (void),
1087 void (*__parent) (void),
1088 void (*__child) (void)));
1089 #endif
1091 __END_DECLS
1093 #endif /* unistd.h */