xref: /netbsd-src/include/unistd.h (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1 /*	$NetBSD: unistd.h,v 1.120 2009/01/11 03:04:12 christos Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998, 1999, 2008 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Klaus Klein.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Copyright (c) 1991, 1993, 1994
34  *	The Regents of the University of California.  All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  * 2. Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in the
43  *    documentation and/or other materials provided with the distribution.
44  * 3. Neither the name of the University nor the names of its contributors
45  *    may be used to endorse or promote products derived from this software
46  *    without specific prior written permission.
47  *
48  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58  * SUCH DAMAGE.
59  *
60  *	@(#)unistd.h	8.12 (Berkeley) 4/27/95
61  */
62 
63 #ifndef _UNISTD_H_
64 #define	_UNISTD_H_
65 
66 #include <machine/ansi.h>
67 #include <machine/int_types.h>
68 #include <sys/cdefs.h>
69 #include <sys/featuretest.h>
70 #include <sys/types.h>
71 #include <sys/unistd.h>
72 
73 
74 /*
75  * IEEE Std 1003.1-90
76  */
77 #define	STDIN_FILENO	0	/* standard input file descriptor */
78 #define	STDOUT_FILENO	1	/* standard output file descriptor */
79 #define	STDERR_FILENO	2	/* standard error file descriptor */
80 
81 #include <sys/null.h>
82 
83 __BEGIN_DECLS
84 __dead	 void _exit(int);
85 int	 access(const char *, int);
86 unsigned int alarm(unsigned int);
87 int	 chdir(const char *);
88 #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
89 int	chown(const char *, uid_t, gid_t) __RENAME(__posix_chown);
90 #else
91 int	chown(const char *, uid_t, gid_t);
92 #endif /* defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) */
93 int	 close(int);
94 size_t	 confstr(int, char *, size_t);
95 #ifndef __CUSERID_DECLARED
96 #define __CUSERID_DECLARED
97 /* also declared in stdio.h */
98 char	*cuserid(char *);	/* obsolete */
99 #endif /* __CUSERID_DECLARED */
100 int	 dup(int);
101 int	 dup2(int, int);
102 int	 execl(const char *, const char *, ...);
103 int	 execle(const char *, const char *, ...);
104 int	 execlp(const char *, const char *, ...);
105 int	 execv(const char *, char * const *);
106 int	 execve(const char *, char * const *, char * const *);
107 int	 execvp(const char *, char * const *);
108 pid_t	 fork(void);
109 long	 fpathconf(int, int);
110 char	*getcwd(char *, size_t);
111 gid_t	 getegid(void);
112 uid_t	 geteuid(void);
113 gid_t	 getgid(void);
114 int	 getgroups(int, gid_t []);
115 __aconst char *getlogin(void);
116 int	 getlogin_r(char *, size_t);
117 pid_t	 getpgrp(void);
118 pid_t	 getpid(void);
119 pid_t	 getppid(void);
120 uid_t	 getuid(void);
121 int	 isatty(int);
122 int	 link(const char *, const char *);
123 long	 pathconf(const char *, int);
124 int	 pause(void);
125 int	 pipe(int *);
126 ssize_t	 read(int, void *, size_t);
127 int	 rmdir(const char *);
128 int	 setgid(gid_t);
129 int	 setpgid(pid_t, pid_t);
130 pid_t	 setsid(void);
131 int	 setuid(uid_t);
132 unsigned int	 sleep(unsigned int);
133 long	 sysconf(int);
134 pid_t	 tcgetpgrp(int);
135 int	 tcsetpgrp(int, pid_t);
136 __aconst char *ttyname(int);
137 int	 unlink(const char *);
138 ssize_t	 write(int, const void *, size_t);
139 
140 
141 /*
142  * IEEE Std 1003.2-92, adopted in X/Open Portability Guide Issue 4 and later
143  */
144 #if (_POSIX_C_SOURCE - 0) >= 2 || defined(_XOPEN_SOURCE) || \
145     defined(_NETBSD_SOURCE)
146 int	 getopt(int, char * const [], const char *);
147 
148 extern	 char *optarg;			/* getopt(3) external variables */
149 extern	 int opterr;
150 extern	 int optind;
151 extern	 int optopt;
152 #endif
153 
154 /*
155  * The Open Group Base Specifications, Issue 6; IEEE Std 1003.1-2001 (POSIX)
156  */
157 #if (_POSIX_C_SOURCE - 0) >= 200112L || (_XOPEN_SOURCE - 0) >= 600 || \
158     defined(_NETBSD_SOURCE)
159 int	 setegid(gid_t);
160 int	 seteuid(uid_t);
161 #endif
162 
163 /*
164  * The following three syscalls are also defined in <sys/types.h>
165  * We protect them against double declarations.
166  */
167 #ifndef __OFF_T_SYSCALLS_DECLARED
168 #define __OFF_T_SYSCALLS_DECLARED
169 off_t	 lseek(int, off_t, int);
170 int	 truncate(const char *, off_t);
171 /*
172  * IEEE Std 1003.1b-93,
173  * also found in X/Open Portability Guide >= Issue 4 Verion 2
174  */
175 #if (_POSIX_C_SOURCE - 0) >= 199309L || \
176     (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
177     (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
178 int	 ftruncate(int, off_t);
179 #endif
180 #endif /* __OFF_T_SYSCALLS_DECLARED */
181 
182 
183 /*
184  * IEEE Std 1003.1b-93, adopted in X/Open CAE Specification Issue 5 Version 2
185  */
186 #if (_POSIX_C_SOURCE - 0) >= 199309L || (_XOPEN_SOURCE - 0) >= 500 || \
187     defined(_NETBSD_SOURCE)
188 int	 fdatasync(int);
189 int	 fsync(int);
190 #endif
191 
192 
193 /*
194  * IEEE Std 1003.1c-95, also adopted by X/Open CAE Spec Issue 5 Version 2
195  */
196 #if (_POSIX_C_SOURCE - 0) >= 199506L || (_XOPEN_SOURCE - 0) >= 500 || \
197     defined(_REENTRANT) || defined(_NETBSD_SOURCE)
198 int	 ttyname_r(int, char *, size_t);
199 int	 pthread_atfork(void (*)(void), void (*)(void), void (*)(void));
200 #endif
201 
202 /*
203  * X/Open Portability Guide, all issues
204  */
205 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
206 int	 chroot(const char *);
207 int	 nice(int);
208 #endif
209 
210 
211 /*
212  * X/Open Portability Guide >= Issue 4
213  */
214 #if defined(_XOPEN_SOURCE) || defined(_NETBSD_SOURCE)
215 __aconst char *crypt(const char *, const char *);
216 int	 encrypt(char *, int);
217 char	*getpass(const char *);
218 pid_t	 getsid(pid_t);
219 #endif
220 
221 
222 /*
223  * X/Open Portability Guide >= Issue 4 Version 2
224  */
225 #if (defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED)) || \
226     (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
227 #ifndef	intptr_t
228 typedef	__intptr_t	intptr_t;
229 #define	intptr_t	__intptr_t
230 #endif
231 
232 #define F_ULOCK		0
233 #define F_LOCK		1
234 #define F_TLOCK		2
235 #define F_TEST		3
236 
237 int	 brk(void *);
238 int	 fchdir(int);
239 #if defined(_XOPEN_SOURCE)
240 int	 fchown(int, uid_t, gid_t) __RENAME(__posix_fchown);
241 #else
242 int	 fchown(int, uid_t, gid_t);
243 #endif
244 int	 getdtablesize(void);
245 long	 gethostid(void);
246 int	 gethostname(char *, size_t);
247 __pure int
248 	 getpagesize(void);		/* legacy */
249 pid_t	 getpgid(pid_t);
250 #if defined(_XOPEN_SOURCE)
251 int	 lchown(const char *, uid_t, gid_t) __RENAME(__posix_lchown);
252 #else
253 int	 lchown(const char *, uid_t, gid_t);
254 #endif
255 int	 lockf(int, int, off_t);
256 ssize_t	 readlink(const char * __restrict, char * __restrict, size_t);
257 void	*sbrk(intptr_t);
258 /* XXX prototype wrong! */
259 int	 setpgrp(pid_t, pid_t);			/* obsoleted by setpgid() */
260 int	 setregid(gid_t, gid_t);
261 int	 setreuid(uid_t, uid_t);
262 void	 swab(const void *, void *, size_t);
263 int	 symlink(const char *, const char *);
264 void	 sync(void);
265 useconds_t ualarm(useconds_t, useconds_t);
266 int	 usleep(useconds_t);
267 #ifndef __LIBC12_SOURCE__
268 pid_t	 vfork(void) __RENAME(__vfork14);
269 #endif
270 
271 #ifndef __AUDIT__
272 char	*getwd(char *);				/* obsoleted by getcwd() */
273 #endif
274 #endif /* _XOPEN_SOURCE_EXTENDED || _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */
275 
276 
277 /*
278  * X/Open CAE Specification Issue 5 Version 2
279  */
280 #if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
281 ssize_t	 pread(int, void *, size_t, off_t);
282 ssize_t	 pwrite(int, const void *, size_t, off_t);
283 #endif
284 
285 
286 /*
287  * Implementation-defined extensions
288  */
289 #if defined(_NETBSD_SOURCE)
290 int	 acct(const char *);
291 int	 closefrom(int);
292 int	 des_cipher(const char *, char *, long, int);
293 int	 des_setkey(const char *);
294 void	 endusershell(void);
295 int	 exect(const char *, char * const *, char * const *);
296 int	 fchroot(int);
297 int	 fsync_range(int, int, off_t, off_t);
298 int	 getdomainname(char *, size_t);
299 int	 getgrouplist(const char *, gid_t, gid_t *, int *);
300 int	 getgroupmembership(const char *, gid_t, gid_t *, int, int *);
301 mode_t	 getmode(const void *, mode_t);
302 int	 getpeereid(int, uid_t *, gid_t *);
303 int	 getsubopt(char **, char * const *, char **);
304 __aconst char *getusershell(void);
305 int	 initgroups(const char *, gid_t);
306 int	 iruserok(uint32_t, int, const char *, const char *);
307 int      issetugid(void);
308 int	 nfssvc(int, void *);
309 int	 profil(char *, size_t, u_long, u_int);
310 #ifndef __PSIGNAL_DECLARED
311 #define __PSIGNAL_DECLARED
312 /* also in signal.h */
313 void	psignal(unsigned int, const char *);
314 #endif /* __PSIGNAL_DECLARED */
315 int	 rcmd(char **, int, const char *, const char *, const char *, int *);
316 int	 reboot(int, char *);
317 int	 revoke(const char *);
318 int	 rresvport(int *);
319 int	 ruserok(const char *, int, const char *, const char *);
320 int	 setdomainname(const char *, size_t);
321 int	 setgroups(int, const gid_t *);
322 int	 sethostid(long);
323 int	 sethostname(const char *, size_t);
324 int	 setlogin(const char *);
325 void	*setmode(const char *);
326 int	 setrgid(gid_t);
327 int	 setruid(uid_t);
328 void	 setusershell(void);
329 void	 strmode(mode_t, char *);
330 __aconst char *strsignal(int);
331 int	 swapctl(int, void *, int);
332 int	 swapon(const char *);			/* obsoleted by swapctl() */
333 int	 syscall(int, ...);
334 quad_t	 __syscall(quad_t, ...);
335 int	 undelete(const char *);
336 
337 #if 1 /*INET6*/
338 int	 rcmd_af(char **, int, const char *,
339 	    const char *, const char *, int *, int);
340 int	 rresvport_af(int *, int);
341 int	 iruserok_sa(const void *, int, int, const char *, const char *);
342 #endif
343 
344 #ifndef __SYS_SIGLIST_DECLARED
345 #define __SYS_SIGLIST_DECLARED
346 /* also in signal.h */
347 extern const char *const *sys_siglist __RENAME(__sys_siglist14);
348 #endif /* __SYS_SIGLIST_DECLARED */
349 extern	 int optreset;		/* getopt(3) external variable */
350 extern	 char *suboptarg;	/* getsubopt(3) external variable */
351 #endif
352 
353 __END_DECLS
354 
355 #if _FORTIFY_SOURCE > 0
356 #include <ssp/unistd.h>
357 #endif
358 #endif /* !_UNISTD_H_ */
359