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