]> git.ipfire.org Git - thirdparty/glibc.git/blob - posix/unistd.h
Tue Jun 4 21:01:20 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[thirdparty/glibc.git] / posix / unistd.h
1 /* Copyright (C) 1991, 92, 93, 94, 95, 96 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
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
18
19 /*
20 * POSIX Standard: 2.10 Symbolic Constants <unistd.h>
21 */
22
23 #ifndef _UNISTD_H
24
25 #define _UNISTD_H 1
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 IEEE Std 1003.1 as of August, 1988 and
34 extended by P1003.1b (aka POSIX.4). */
35 #define _POSIX_VERSION 199309L
36
37 /* These are not #ifdef __USE_POSIX2 because they are
38 in the theoretically application-owned namespace. */
39
40 #define _POSIX2_C_VERSION 199912L /* Invalid until 1003.2 is done. */
41
42 /* If defined, the implementation supports the
43 C Language Bindings Option. */
44 #define _POSIX2_C_BIND 1
45
46 /* If defined, the implementation supports the
47 C Language Development Utilities Option. */
48 #define _POSIX2_C_DEV 1
49
50 /* If defined, the implementation supports the
51 Software Development Utilities Option. */
52 #define _POSIX2_SW_DEV 1
53
54 /* If defined, the implementation supports the
55 creation of locales with the localedef utility. */
56 #define _POSIX2_LOCALEDEF 1
57
58
59 /* Get values of POSIX options:
60
61 If these symbols are defined, the corresponding features are
62 always available. If not, they may be available sometimes.
63 The current values can be obtained with `sysconf'.
64
65 _POSIX_JOB_CONTROL Job control is supported.
66 _POSIX_SAVED_IDS Processes have a saved set-user-ID
67 and a saved set-group-ID.
68 _POSIX_REALTIME_SIGNALS Real-time, queued signals are supported.
69 _POSIX_PRIORITY_SCHEDULING Priority scheduling is supported.
70 _POSIX_TIMERS POSIX.4 clocks and timers are supported.
71 _POSIX_ASYNCHRONOUS_IO Asynchronous I/O is supported.
72 _POSIX_PRIORITIZED_IO Prioritized asynchronous I/O is supported.
73 _POSIX_SYNCHRONIZED_IO Synchronizing file data is supported.
74 _POSIX_FSYNC The fsync function is present.
75 _POSIX_MAPPED_FILES Mapping of files to memory is supported.
76 _POSIX_MEMLOCK Locking of all memory is supported.
77 _POSIX_MEMLOCK_RANGE Locking of ranges of memory is supported.
78 _POSIX_MEMORY_PROTECTION Setting of memory protections is supported.
79 _POSIX_MESSAGE_PASSING POSIX.4 message queues are supported.
80 _POSIX_SEMAPHORES POSIX.4 counting semaphores are supported.
81 _POSIX_SHARED_MEMORY_OBJECTS POSIX.4 shared memory objects are supported.
82
83 If any of these symbols is defined as -1, the corresponding option is not
84 true for any file. If any is defined as other than -1, the corresponding
85 option is true for all files. If a symbol is not defined at all, the value
86 for a specific file can be obtained from `pathconf' and `fpathconf'.
87
88 _POSIX_CHOWN_RESTRICTED Only the super user can use `chown' to change
89 the owner of a file. `chown' can only be used
90 to change the group ID of a file to a group of
91 which the calling process is a member.
92 _POSIX_NO_TRUNC Pathname components longer than
93 NAME_MAX generate an error.
94 _POSIX_VDISABLE If defined, if the value of an element of the
95 `c_cc' member of `struct termios' is
96 _POSIX_VDISABLE, no character will have the
97 effect associated with that element.
98 _POSIX_SYNC_IO Synchronous I/O may be performed.
99 _POSIX_ASYNC_IO Asynchronous I/O may be performed.
100 _POSIX_PRIO_IO Prioritized Asynchronous I/O may be performed.
101 */
102
103 #include <posix_opt.h>
104
105
106 /* Standard file descriptors. */
107 #define STDIN_FILENO 0 /* Standard input. */
108 #define STDOUT_FILENO 1 /* Standard output. */
109 #define STDERR_FILENO 2 /* Standard error output. */
110
111
112 /* All functions that are not declared anywhere else. */
113
114 #include <gnu/types.h>
115
116 #ifndef ssize_t
117 #define ssize_t __ssize_t
118 #endif
119
120 #define __need_size_t
121 #define __need_NULL
122 #include <stddef.h>
123
124
125 /* Values for the second argument to access.
126 These may be OR'd together. */
127 #define R_OK 4 /* Test for read permission. */
128 #define W_OK 2 /* Test for write permission. */
129 #define X_OK 1 /* Test for execute permission. */
130 #define F_OK 0 /* Test for existence. */
131
132 /* Test for access to NAME using the real UID and real GID. */
133 extern int __access __P ((__const char *__name, int __type));
134 extern int access __P ((__const char *__name, int __type));
135
136 #ifdef __USE_GNU
137 /* Test for access to NAME using the effective UID and GID
138 (as normal file operations use). */
139 extern int euidaccess __P ((__const char *__name, int __type));
140 #endif
141
142
143 /* Values for the WHENCE argument to lseek. */
144 #ifndef _STDIO_H /* <stdio.h> has the same definitions. */
145 #define SEEK_SET 0 /* Seek from beginning of file. */
146 #define SEEK_CUR 1 /* Seek from current position. */
147 #define SEEK_END 2 /* Seek from end of file. */
148 #endif
149
150 #if defined (__USE_BSD) && !defined (L_SET)
151 /* Old BSD names for the same constants; just for compatibility. */
152 #define L_SET SEEK_SET
153 #define L_INCR SEEK_CUR
154 #define L_XTND SEEK_END
155 #endif
156
157
158 /* Move FD's file position to OFFSET bytes from the
159 beginning of the file (if WHENCE is SEEK_SET),
160 the current position (if WHENCE is SEEK_CUR),
161 or the end of the file (if WHENCE is SEEK_END).
162 Return the new file position. */
163 extern __off_t __lseek __P ((int __fd, __off_t __offset, int __whence));
164 extern __off_t lseek __P ((int __fd, __off_t __offset, int __whence));
165
166 /* Close the file descriptor FD. */
167 extern int __close __P ((int __fd));
168 extern int close __P ((int __fd));
169
170 /* Read NBYTES into BUF from FD. Return the
171 number read, -1 for errors or 0 for EOF. */
172 extern ssize_t __read __P ((int __fd, __ptr_t __buf, size_t __nbytes));
173 extern ssize_t read __P ((int __fd, __ptr_t __buf, size_t __nbytes));
174
175 /* Write N bytes of BUF to FD. Return the number written, or -1. */
176 extern ssize_t __write __P ((int __fd, __const __ptr_t __buf, size_t __n));
177 extern ssize_t write __P ((int __fd, __const __ptr_t __buf, size_t __n));
178
179
180 /* Create a one-way communication channel (pipe).
181 If successul, two file descriptors are stored in PIPEDES;
182 bytes written on PIPEDES[1] can be read from PIPEDES[0].
183 Returns 0 if successful, -1 if not. */
184 extern int __pipe __P ((int __pipedes[2]));
185 extern int pipe __P ((int __pipedes[2]));
186
187 /* Schedule an alarm. In SECONDS seconds, the process will get a SIGALRM.
188 If SECONDS is zero, any currently scheduled alarm will be cancelled.
189 The function returns the number of seconds remaining until the last
190 alarm scheduled would have signaled, or zero if there wasn't one.
191 There is no return value to indicate an error, but you can set `errno'
192 to 0 and check its value after calling `alarm', and this might tell you.
193 The signal may come late due to processor scheduling. */
194 extern unsigned int alarm __P ((unsigned int __seconds));
195
196 /* Make the process sleep for SECONDS seconds, or until a signal arrives
197 and is not ignored. The function returns the number of seconds less
198 than SECONDS which it actually slept (thus zero if it slept the full time).
199 If a signal handler does a `longjmp' or modifies the handling of the
200 SIGALRM signal while inside `sleep' call, the handling of the SIGALRM
201 signal afterwards is undefined. There is no return value to indicate
202 error, but if `sleep' returns SECONDS, it probably didn't work. */
203 extern unsigned int sleep __P ((unsigned int __seconds));
204
205 #ifdef __USE_BSD
206 /* Sleep USECONDS microseconds, or until a signal arrives that is not blocked
207 or ignored. Return value is not necessarily useful. */
208 extern unsigned int usleep __P ((unsigned __useconds));
209 #endif
210
211
212 /* Suspend the process until a signal arrives.
213 This always returns -1 and sets `errno' to EINTR. */
214 extern int pause __P ((void));
215
216
217 /* Change the owner and group of FILE. */
218 extern int __chown __P ((__const char *__file,
219 __uid_t __owner, __gid_t __group));
220 extern int chown __P ((__const char *__file,
221 __uid_t __owner, __gid_t __group));
222
223 #ifdef __USE_BSD
224 /* Change the owner and group of the file that FD is open on. */
225 extern int __fchown __P ((int __fd,
226 __uid_t __owner, __gid_t __group));
227 extern int fchown __P ((int __fd,
228 __uid_t __owner, __gid_t __group));
229 #endif /* Use BSD. */
230
231 /* Change the process's working directory to PATH. */
232 extern int __chdir __P ((__const char *__path));
233 extern int chdir __P ((__const char *__path));
234
235 #ifdef __USE_BSD
236 /* Change the process's working directory to the one FD is open on. */
237 extern int fchdir __P ((int __fd));
238 #endif
239
240 /* Get the pathname of the current working directory,
241 and put it in SIZE bytes of BUF. Returns NULL if the
242 directory couldn't be determined or SIZE was too small.
243 If successful, returns BUF. In GNU, if BUF is NULL,
244 an array is allocated with `malloc'; the array is SIZE
245 bytes long, unless SIZE <= 0, in which case it is as
246 big as necessary. */
247 extern char *__getcwd __P ((char *__buf, size_t __size));
248 extern char *getcwd __P ((char *__buf, size_t __size));
249
250 #ifdef __USE_GNU
251 /* Return a malloc'd string containing the current directory name.
252 If the environment variable `PWD' is set, and its value is correct,
253 that value is used. */
254 extern char *get_current_dir_name __P ((void));
255
256 /* Get the canonical absolute name of the named directory, and put it in SIZE
257 bytes of BUF. Returns NULL if the directory couldn't be determined or
258 SIZE was too small. If successful, returns BUF. In GNU, if BUF is
259 NULL, an array is allocated with `malloc'; the array is SIZE bytes long,
260 unless SIZE <= 0, in which case it is as big as necessary. */
261
262 char *__canonicalize_directory_name_internal __P ((const char *__thisdir,
263 char *__buf,
264 size_t __size));
265 #endif
266
267 #ifdef __USE_BSD
268 /* Put the absolute pathname of the current working directory in BUF.
269 If successful, return BUF. If not, put an error message in
270 BUF and return NULL. BUF should be at least PATH_MAX bytes long. */
271 extern char *getwd __P ((char *__buf));
272 #endif
273
274
275 /* Duplicate FD, returning a new file descriptor on the same file. */
276 extern int __dup __P ((int __fd));
277 extern int dup __P ((int __fd));
278
279 /* Duplicate FD to FD2, closing FD2 and making it open on the same file. */
280 extern int __dup2 __P ((int __fd, int __fd2));
281 extern int dup2 __P ((int __fd, int __fd2));
282
283 /* NULL-terminated array of "NAME=VALUE" environment variables. */
284 extern char **__environ;
285 extern char **environ;
286
287
288 /* Replace the current process, executing PATH with arguments ARGV and
289 environment ENVP. ARGV and ENVP are terminated by NULL pointers. */
290 extern int __execve __P ((__const char *__path, char *__const __argv[],
291 char *__const __envp[]));
292 extern int execve __P ((__const char *__path, char *__const __argv[],
293 char *__const __envp[]));
294
295 #ifdef __USE_GNU
296 /* Execute the file FD refers to, overlaying the running program image.
297 ARGV and ENVP are passed to the new program, as for `execve'. */
298 extern int fexecve __P ((int __fd,
299 char *const __argv[], char *const __envp[]));
300
301 #endif
302
303
304 /* Execute PATH with arguments ARGV and environment from `environ'. */
305 extern int execv __P ((__const char *__path, char *__const __argv[]));
306
307 /* Execute PATH with all arguments after PATH until a NULL pointer,
308 and the argument after that for environment. */
309 extern int execle __P ((__const char *__path, __const char *__arg,...));
310
311 /* Execute PATH with all arguments after PATH until
312 a NULL pointer and environment from `environ'. */
313 extern int execl __P ((__const char *__path, __const char *__arg,...));
314
315 /* Execute FILE, searching in the `PATH' environment variable if it contains
316 no slashes, with arguments ARGV and environment from `environ'. */
317 extern int execvp __P ((__const char *__file, char *__const __argv[]));
318
319 /* Execute FILE, searching in the `PATH' environment variable if
320 it contains no slashes, with all arguments after FILE until a
321 NULL pointer and environment from `environ'. */
322 extern int execlp __P ((__const char *__file, ...));
323
324
325 /* Terminate program execution with the low-order 8 bits of STATUS. */
326 extern void _exit __P ((int __status)) __attribute__ ((__noreturn__));
327
328
329 /* Get the `_PC_*' symbols for the NAME argument to `pathconf' and `fpathconf';
330 the `_SC_*' symbols for the NAME argument to `sysconf';
331 and the `_CS_*' symbols for the NAME argument to `confstr'. */
332 #include <confname.h>
333
334 /* Get file-specific configuration information about PATH. */
335 extern long int __pathconf __P ((__const char *__path, int __name));
336 extern long int pathconf __P ((__const char *__path, int __name));
337
338 /* Get file-specific configuration about descriptor FD. */
339 extern long int __fpathconf __P ((int __fd, int __name));
340 extern long int fpathconf __P ((int __fd, int __name));
341
342 /* Get the value of the system variable NAME. */
343 extern long int __sysconf __P ((int __name));
344 extern long int sysconf __P ((int __name));
345
346 #ifdef __USE_POSIX2
347 /* Get the value of the string-valued system variable NAME. */
348 extern size_t confstr __P ((int __name, char *__buf, size_t __len));
349 #endif
350
351
352 /* Get the process ID of the calling process. */
353 extern __pid_t __getpid __P ((void));
354 extern __pid_t getpid __P ((void));
355
356 /* Get the process ID of the calling process's parent. */
357 extern __pid_t __getppid __P ((void));
358 extern __pid_t getppid __P ((void));
359
360 /* Get the process group ID of the calling process. */
361 extern __pid_t getpgrp __P ((void));
362
363 /* Set the process group ID of the process matching PID to PGID.
364 If PID is zero, the current process's process group ID is set.
365 If PGID is zero, the process ID of the process is used. */
366 extern int setpgid __P ((__pid_t __pid, __pid_t __pgid));
367
368 /* Get the process group ID of process PID. */
369 extern __pid_t __getpgid __P ((__pid_t __pid));
370 #ifdef __USE_GNU
371 extern __pid_t getpgid __P ((__pid_t __pid));
372 #endif
373
374 #if defined (__USE_SVID) || defined (__USE_BSD)
375 /* Both System V and BSD have `setpgrp' functions, but with different
376 calling conventions. The BSD function is the same as POSIX.1 `setpgid'
377 (above). The System V function takes no arguments and puts the calling
378 process in its on group like `setpgid (0, 0)'.
379
380 New programs should always use `setpgid' instead.
381
382 The default in GNU is to provide the System V function. The BSD
383 function is available under -D_BSD_SOURCE with -lbsd-compat. */
384
385 #ifndef __FAVOR_BSD
386
387 /* Set the process group ID of the calling process to its own PID.
388 This is exactly the same as `setpgid (0, 0)'. */
389 extern int setpgrp __P ((void));
390
391 #else
392
393 /* Another name for `setpgid' (above). */
394 extern int setpgrp __P ((__pid_t __pid, __pid_t __pgrp));
395
396 #endif /* Favor BSD. */
397 #endif /* Use SVID or BSD. */
398
399 /* Create a new session with the calling process as its leader.
400 The process group IDs of the session and the calling process
401 are set to the process ID of the calling process, which is returned. */
402 extern __pid_t __setsid __P ((void));
403 extern __pid_t setsid __P ((void));
404
405 #ifdef __USE_GNU
406 /* Return the session ID of the given process. */
407 extern __pid_t getsid __P ((__pid_t));
408 #endif
409
410 /* Get the real user ID of the calling process. */
411 extern __uid_t __getuid __P ((void));
412 extern __uid_t getuid __P ((void));
413
414 /* Get the effective user ID of the calling process. */
415 extern __uid_t __geteuid __P ((void));
416 extern __uid_t geteuid __P ((void));
417
418 /* Get the real group ID of the calling process. */
419 extern __gid_t __getgid __P ((void));
420 extern __gid_t getgid __P ((void));
421
422 /* Get the effective group ID of the calling process. */
423 extern __gid_t __getegid __P ((void));
424 extern __gid_t getegid __P ((void));
425
426 /* If SIZE is zero, return the number of supplementary groups
427 the calling process is in. Otherwise, fill in the group IDs
428 of its supplementary groups in LIST and return the number written. */
429 extern int __getgroups __P ((int __size, __gid_t __list[]));
430 extern int getgroups __P ((int __size, __gid_t __list[]));
431
432 #ifdef __USE_GNU
433 /* Return nonzero iff the calling process is in group GID. */
434 extern int __group_member __P ((__gid_t __gid));
435 extern int group_member __P ((__gid_t __gid));
436 #endif
437
438 /* Set the user ID of the calling process to UID.
439 If the calling process is the super-user, set the real
440 and effective user IDs, and the saved set-user-ID to UID;
441 if not, the effective user ID is set to UID. */
442 extern int __setuid __P ((__uid_t __uid));
443 extern int setuid __P ((__uid_t __uid));
444
445 #ifdef __USE_BSD
446 /* Set the real user ID of the calling process to RUID,
447 and the effective user ID of the calling process to EUID. */
448 extern int __setreuid __P ((__uid_t __ruid, __uid_t __euid));
449 extern int setreuid __P ((__uid_t __ruid, __uid_t __euid));
450
451 /* Set the effective user ID of the calling process to UID. */
452 extern int seteuid __P ((__uid_t __uid));
453 #endif /* Use BSD. */
454
455 /* Set the group ID of the calling process to GID.
456 If the calling process is the super-user, set the real
457 and effective group IDs, and the saved set-group-ID to GID;
458 if not, the effective group ID is set to GID. */
459 extern int __setgid __P ((__gid_t __gid));
460 extern int setgid __P ((__gid_t __gid));
461
462 #ifdef __USE_BSD
463 /* Set the real group ID of the calling process to RGID,
464 and the effective group ID of the calling process to EGID. */
465 extern int __setregid __P ((__gid_t __rgid, __gid_t __egid));
466 extern int setregid __P ((__gid_t __rgid, __gid_t __egid));
467
468 /* Set the effective group ID of the calling process to GID. */
469 extern int setegid __P ((__gid_t __gid));
470 #endif /* Use BSD. */
471
472
473 /* Clone the calling process, creating an exact copy.
474 Return -1 for errors, 0 to the new process,
475 and the process ID of the new process to the old process. */
476 extern __pid_t __fork __P ((void));
477 extern __pid_t fork __P ((void));
478
479 #ifdef __USE_BSD
480 /* Clone the calling process, but without copying the whole address space.
481 The the calling process is suspended until the the new process exits or is
482 replaced by a call to `execve'. Return -1 for errors, 0 to the new process,
483 and the process ID of the new process to the old process. */
484 extern __pid_t __vfork __P ((void));
485 extern __pid_t vfork __P ((void));
486 #endif /* Use BSD. */
487
488
489 /* Return the pathname of the terminal FD is open on, or NULL on errors.
490 The returned storage is good only until the next call to this function. */
491 extern char *ttyname __P ((int __fd));
492 #ifdef __USE_REENTRANT
493 /* Store at most BUFLEN characters of the pathname of the terminal FD is
494 open on in BUF. Return 0 on success, -1 otherwise. */
495 extern int ttyname_r __P ((int __fd, char *__buf, int __buflen));
496 #endif
497
498 /* Return 1 if FD is a valid descriptor associated
499 with a terminal, zero if not. */
500 extern int __isatty __P ((int __fd));
501 extern int isatty __P ((int __fd));
502
503 #ifdef __USE_BSD
504 /* Return the index into the active-logins file (utmp) for
505 the controlling terminal. */
506 extern int ttyslot __P ((void));
507 #endif
508
509
510 /* Make a link to FROM named TO. */
511 extern int __link __P ((__const char *__from, __const char *__to));
512 extern int link __P ((__const char *__from, __const char *__to));
513
514 #ifdef __USE_BSD
515 /* Make a symbolic link to FROM named TO. */
516 extern int __symlink __P ((__const char *__from, __const char *__to));
517 extern int symlink __P ((__const char *__from, __const char *__to));
518
519 /* Read the contents of the symbolic link PATH into no more than
520 LEN bytes of BUF. The contents are not null-terminated.
521 Returns the number of characters read, or -1 for errors. */
522 extern int __readlink __P ((__const char *__path, char *__buf, size_t __len));
523 extern int readlink __P ((__const char *__path, char *__buf, size_t __len));
524 #endif /* Use BSD. */
525
526 /* Remove the link NAME. */
527 extern int __unlink __P ((__const char *__name));
528 extern int unlink __P ((__const char *__name));
529
530 /* Remove the directory PATH. */
531 extern int __rmdir __P ((__const char *__path));
532 extern int rmdir __P ((__const char *__path));
533
534
535 /* Return the foreground process group ID of FD. */
536 extern __pid_t tcgetpgrp __P ((int __fd));
537
538 /* Set the foreground process group ID of FD set PGRP_ID. */
539 extern int tcsetpgrp __P ((int __fd, __pid_t __pgrp_id));
540
541
542 /* Return the login name of the user. */
543 extern char *getlogin __P ((void));
544 #ifdef __USE_REENTRANT
545 /* Return at most NAME_LEN characters of the login name of the user in NAME.
546 If it cannot be determined or some other error occured, return the error
547 code. Otherwise return 0. */
548 extern int getlogin_r __P ((char *__name, size_t __name_len));
549 #endif
550
551 #ifdef __USE_BSD
552 /* Set the login name returned by `getlogin'. */
553 extern int setlogin __P ((__const char *__name));
554 #endif
555
556
557 #ifdef __USE_POSIX2
558 /* Process the arguments in ARGV (ARGC of them, minus
559 the program name) for options given in OPTS.
560
561 If `opterr' is zero, no messages are generated
562 for invalid options; it defaults to 1.
563 `optind' is the current index into ARGV.
564 `optarg' is the argument corresponding to the current option.
565 Return the option character from OPTS just read.
566 Return -1 when there are no more options.
567 For unrecognized options, or options missing arguments,
568 `optopt' is set to the option letter, and '?' is returned.
569
570 The OPTS string is a list of characters which are recognized option
571 letters, optionally followed by colons, specifying that that letter
572 takes an argument, to be placed in `optarg'.
573
574 If a letter in OPTS is followed by two colons, its argument is optional.
575 This behavior is specific to the GNU `getopt'.
576
577 The argument `--' causes premature termination of argument scanning,
578 explicitly telling `getopt' that there are no more options.
579
580 If OPTS begins with `--', then non-option arguments
581 are treated as arguments to the option '\0'.
582 This behavior is specific to the GNU `getopt'. */
583 extern int getopt __P ((int __argc, char *__const * __argv,
584 __const char *__opts));
585 extern int opterr;
586 extern int optind;
587 extern int optopt;
588 extern char *optarg;
589 #endif
590
591
592 #ifdef __USE_BSD
593
594 /* Put the name of the current host in no more than LEN bytes of NAME.
595 The result is null-terminated if LEN is large enough for the full
596 name and the terminator. */
597 extern int __gethostname __P ((char *__name, size_t __len));
598 extern int gethostname __P ((char *__name, size_t __len));
599
600 /* Set the name of the current host to NAME, which is LEN bytes long.
601 This call is restricted to the super-user. */
602 extern int sethostname __P ((__const char *__name, size_t __len));
603
604 /* Return the current machine's Internet number. */
605 extern long int gethostid __P ((void));
606
607 /* Set the current machine's Internet number to ID.
608 This call is restricted to the super-user. */
609 extern int sethostid __P ((long int __id));
610
611
612 /* Return the number of bytes in a page. This is the system's page size,
613 which is not necessarily the same as the hardware page size. */
614 extern size_t __getpagesize __P ((void));
615 extern size_t getpagesize __P ((void));
616
617
618 /* Return the maximum number of file descriptors
619 the current process could possibly have. */
620 extern int __getdtablesize __P ((void));
621 extern int getdtablesize __P ((void));
622
623
624 /* Truncate FILE to LENGTH bytes. */
625 extern int truncate __P ((__const char *__file, __off_t __length));
626
627 /* Truncate the file FD is open on to LENGTH bytes. */
628 extern int ftruncate __P ((int __fd, __off_t __length));
629
630
631 /* Make all changes done to FD actually appear on disk. */
632 extern int fsync __P ((int __fd));
633
634 /* Make all changes done to all files actually appear on disk. */
635 extern int sync __P ((void));
636
637
638 /* Revoke access permissions to all processes currently communicating
639 with the control terminal, and then send a SIGHUP signal to the process
640 group of the control terminal. */
641 extern int vhangup __P ((void));
642
643 /* Revoke the access of all descriptors currently open on FILE. */
644 extern int revoke __P ((const char *__file));
645
646
647 /* Enable statistical profiling, writing samples of the PC into at most
648 SIZE bytes of SAMPLE_BUFFER; every processor clock tick while profiling
649 is enabled, the system examines the user PC and increments
650 SAMPLE_BUFFER[((PC - OFFSET) / 2) * SCALE / 65536]. If SCALE is zero,
651 disable profiling. Returns zero on success, -1 on error. */
652 extern int profil __P ((unsigned short int *__sample_buffer, size_t __size,
653 size_t __offset, unsigned int __scale));
654
655
656 /* Turn accounting on if NAME is an existing file. The system will then write
657 a record for each process as it terminates, to this file. If NAME is NULL,
658 turn accounting off. This call is restricted to the super-user. */
659 extern int acct __P ((__const char *__name));
660
661 /* Make PATH be the root directory (the starting point for absolute paths).
662 This call is restricted to the super-user. */
663 extern int chroot __P ((__const char *__path));
664
665 /* Make the block special device PATH available to the system for swapping.
666 This call is restricted to the super-user. */
667 extern int swapon __P ((__const char *__path));
668
669 /* Stop using block special device PATH for swapping. */
670 extern int swapoff __P ((__const char *__path));
671
672
673 /* Successive calls return the shells listed in `/etc/shells'. */
674 extern char *getusershell __P ((void));
675 extern void endusershell __P ((void)); /* Discard cached info. */
676 extern void setusershell __P ((void)); /* Rewind and re-read the file. */
677
678
679 /* Prompt with PROMPT and read a string from the terminal without echoing.
680 Uses /dev/tty if possible; otherwise stderr and stdin. */
681 extern char *getpass __P ((const char *__prompt));
682
683 /* Put the program in the background, and dissociate from the controlling
684 terminal. If NOCHDIR is zero, do `chdir ("/")'. If NOCLOSE is zero,
685 redirects stdin, stdout, and stderr to /dev/null. */
686 extern int daemon __P ((int __nochdir, int __noclose));
687
688 #endif /* Use BSD. */
689
690
691 #ifdef __USE_MISC
692
693 /* Generate a unique temporary file name from TEMPLATE.
694 The last six characters of TEMPLATE must be "XXXXXX";
695 they are replaced with a string that makes the file name unique.
696 Returns TEMPLATE, or a null pointer if it cannot get a unique file name. */
697 extern char *mktemp __P ((char *__template));
698
699 /* Generate a unique temporary file name from TEMPLATE.
700 The last six characters of TEMPLATE must be "XXXXXX";
701 they are replaced with a string that makes the filename unique.
702 Returns a file descriptor open on the file for reading and writing,
703 or -1 if it cannot create a uniquely-named file. */
704 extern int mkstemp __P ((char *__template));
705
706
707 /* Set the end of accessible data space (aka "the break") to ADDR.
708 Returns zero on success and -1 for errors (with errno set). */
709 extern int __brk __P ((__ptr_t __addr));
710 extern int brk __P ((__ptr_t __addr));
711
712 #define __need_ptrdiff_t
713 #include <stddef.h>
714
715 /* Increase or decrease the end of accessible data space by DELTA bytes.
716 If successful, returns the address the previous end of data space
717 (i.e. the beginning of the new space, if DELTA > 0);
718 returns (void *) -1 for errors (with errno set). */
719 extern __ptr_t __sbrk __P ((ptrdiff_t __delta));
720 extern __ptr_t sbrk __P ((ptrdiff_t __delta));
721
722
723 /* Invoke `system call' number SYSNO, passing it the remaining arguments.
724 This is completely system-dependent, and not often useful.
725
726 In Unix, `syscall' sets `errno' for all errors and most calls return -1
727 for errors; in many systems you cannot pass arguments or get return
728 values for all system calls (`pipe', `fork', and `getppid' typically
729 among them).
730
731 In Mach, all system calls take normal arguments and always return an
732 error code (zero for success). */
733 extern int syscall __P ((int __sysno, ...));
734
735 #endif /* Use misc. */
736
737
738 #if defined (__USE_MISC) && !defined (F_LOCK)
739 /* NOTE: These declarations also appear in <fcntl.h>; be sure to keep both
740 files consistent. Some systems have them there and some here, and some
741 software depends on the macros being defined without including both. */
742
743 /* `lockf' is a simpler interface to the locking facilities of `fcntl'.
744 LEN is always relative to the current file position.
745 The CMD argument is one of the following. */
746
747 #define F_ULOCK 0 /* Unlock a previously locked region. */
748 #define F_LOCK 1 /* Lock a region for exclusive use. */
749 #define F_TLOCK 2 /* Test and lock a region for exclusive use. */
750 #define F_TEST 3 /* Test a region for other processes locks. */
751
752 extern int lockf __P ((int __fd, int __cmd, __off_t __len));
753 #endif /* Use misc and F_LOCK not already defined. */
754
755
756 #ifdef __USE_GNU
757
758 /* Evaluate EXPRESSION, and repeat as long as it returns -1 with `errno'
759 set to EINTR. */
760
761 #define TEMP_FAILURE_RETRY(expression) \
762 ({ long int __result; \
763 do __result = (long int) (expression); \
764 while (__result == -1L && errno == EINTR); \
765 __result; })
766
767 #endif
768
769 #ifdef __USE_POSIX
770 /* Synchronize at least the data part of a file with the underlying
771 media. */
772 extern int fdatasync __P ((int __fildes));
773 #endif /* Use POSIX */
774
775 __END_DECLS
776
777 #endif /* unistd.h */