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