4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2014 PALO, Richard.
24 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
25 * Copyright (c) 2013 Gary Mills
27 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
30 /* Copyright (c) 1988 AT&T */
31 /* All Rights Reserved */
33 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
38 #include <sys/feature_tests.h>
41 #include <sys/types.h>
42 #include <sys/unistd.h>
48 /* Symbolic constants for the "access" routine: */
49 #define R_OK 4 /* Test for Read permission */
50 #define W_OK 2 /* Test for Write permission */
51 #define X_OK 1 /* Test for eXecute permission */
52 #define F_OK 0 /* Test for existence of File */
54 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
55 #define F_ULOCK 0 /* Unlock a previously locked region */
56 #define F_LOCK 1 /* Lock a region for exclusive use */
57 #define F_TLOCK 2 /* Test and lock a region for exclusive use */
58 #define F_TEST 3 /* Test a region for other processes locks */
59 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
61 /* Symbolic constants for the "lseek" routine: */
64 #define SEEK_SET 0 /* Set file pointer to "offset" */
68 #define SEEK_CUR 1 /* Set file pointer to current plus "offset" */
72 #define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
75 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
77 #define SEEK_DATA 3 /* Set file pointer to next data past offset */
81 #define SEEK_HOLE 4 /* Set file pointer to next hole past offset */
83 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
85 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
87 #define GF_PATH "/etc/group" /* Path name of the "group" file */
88 #define PF_PATH "/etc/passwd" /* Path name of the "passwd" file */
89 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
92 * compile-time symbolic constants,
93 * Support does not mean the feature is enabled.
94 * Use pathconf/sysconf to obtain actual configuration value.
97 /* Values unchanged in UNIX 03 */
98 #define _POSIX_ASYNC_IO 1
99 #define _POSIX_JOB_CONTROL 1
100 #define _POSIX_SAVED_IDS 1
101 #define _POSIX_SYNC_IO 1
104 * POSIX.1b compile-time symbolic constants.
107 #define _POSIX_ASYNCHRONOUS_IO 200112L
108 #define _POSIX_FSYNC 200112L
109 #define _POSIX_MAPPED_FILES 200112L
110 #define _POSIX_MEMLOCK 200112L
111 #define _POSIX_MEMLOCK_RANGE 200112L
112 #define _POSIX_MEMORY_PROTECTION 200112L
113 #define _POSIX_MESSAGE_PASSING 200112L
114 #define _POSIX_PRIORITY_SCHEDULING 200112L
115 #define _POSIX_REALTIME_SIGNALS 200112L
116 #define _POSIX_SEMAPHORES 200112L
117 #define _POSIX_SHARED_MEMORY_OBJECTS 200112L
118 #define _POSIX_SYNCHRONIZED_IO 200112L
120 #define _POSIX_ASYNCHRONOUS_IO 1
121 #define _POSIX_FSYNC 1
122 #define _POSIX_MAPPED_FILES 1
123 #define _POSIX_MEMLOCK 1
124 #define _POSIX_MEMLOCK_RANGE 1
125 #define _POSIX_MEMORY_PROTECTION 1
126 #define _POSIX_MESSAGE_PASSING 1
127 #define _POSIX_PRIORITY_SCHEDULING 1
128 #define _POSIX_REALTIME_SIGNALS 1
129 #define _POSIX_SEMAPHORES 1
130 #define _POSIX_SHARED_MEMORY_OBJECTS 1
131 #define _POSIX_SYNCHRONIZED_IO 1
135 * POSIX.1c compile-time symbolic constants.
138 #define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
139 #define _POSIX_THREADS 200112L
140 #define _POSIX_THREAD_ATTR_STACKADDR 200112L
141 #define _POSIX_THREAD_ATTR_STACKSIZE 200112L
142 #define _POSIX_THREAD_PROCESS_SHARED 200112L
143 #define _POSIX_THREAD_PRIORITY_SCHEDULING 200112L
144 #define _POSIX_TIMERS 200112L
146 #define _POSIX_THREAD_SAFE_FUNCTIONS 1
147 #define _POSIX_THREADS 1
148 #define _POSIX_THREAD_ATTR_STACKADDR 1
149 #define _POSIX_THREAD_ATTR_STACKSIZE 1
150 #define _POSIX_THREAD_PROCESS_SHARED 1
151 #define _POSIX_THREAD_PRIORITY_SCHEDULING 1
152 #define _POSIX_TIMERS 1
156 #define _POSIX_ADVISORY_INFO 200112L
157 #define _POSIX_BARRIERS 200112L
158 #define _POSIX_CLOCK_SELECTION 200112L
159 #define _POSIX_IPV6 200112L
160 #define _POSIX_MONOTONIC_CLOCK 200112L
161 #define _POSIX_RAW_SOCKETS 200112L
162 #define _POSIX_READER_WRITER_LOCKS 200112L
163 #define _POSIX_SPAWN 200112L
164 #define _POSIX_SPIN_LOCKS 200112L
165 #define _POSIX_TIMEOUTS 200112L
168 * Support for the POSIX.1 mutex protocol attribute. For realtime applications
169 * which need mutexes to support priority inheritance/ceiling.
172 #define _POSIX_THREAD_PRIO_INHERIT 200112L
173 #define _POSIX_THREAD_PRIO_PROTECT 200112L
175 #define _POSIX_THREAD_PRIO_INHERIT 1
176 #define _POSIX_THREAD_PRIO_PROTECT 1
179 #ifndef _POSIX_VDISABLE
180 #define _POSIX_VDISABLE 0
183 #define STDIN_FILENO 0
184 #define STDOUT_FILENO 1
185 #define STDERR_FILENO 2
187 extern int access(const char *, int);
188 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
189 extern int acct(const char *);
190 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
191 extern unsigned alarm(unsigned);
192 /* Marked as LEGACY in SUSv2 and removed in SUSv3 */
193 #if !defined(__XOPEN_OR_POSIX) || (defined(_XPG4_2) && !defined(_XPG6)) || \
194 defined(__EXTENSIONS__)
195 extern int brk(void *);
196 #endif /* !defined(__XOPEN_OR_POSIX) || (defined(_XPG4_2)... */
197 extern int chdir(const char *);
198 extern int chown(const char *, uid_t
, gid_t
);
199 /* Marked as LEGACY in SUSv2 and removed in SUSv3 */
200 #if !defined(_POSIX_C_SOURCE) || (defined(_XOPEN_SOURCE) && \
201 !defined(_XPG6)) || defined(__EXTENSIONS__)
202 extern int chroot(const char *);
203 #endif /* !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE))... */
204 extern int close(int);
205 #if defined(_XPG4) || defined(__EXTENSIONS__)
206 extern size_t confstr(int, char *, size_t);
207 extern char *crypt(const char *, const char *);
208 #endif /* defined(_XPG4) || defined(__EXTENSIONS__) */
209 #if !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
210 defined(__EXTENSIONS__)
211 extern char *ctermid(char *);
212 #endif /* (!defined(_POSIX_C_SOURCE) ... */
213 extern char *ctermid_r(char *);
214 /* Marked as LEGACY in SUSv2 and removed in SUSv3 */
215 #if !defined(_XPG6) || defined(__EXTENSIONS__)
216 extern char *cuserid(char *);
219 extern int dup2(int, int);
220 extern int dup3(int, int, int);
221 #if defined(_XPG4) || defined(__EXTENSIONS__)
222 extern void encrypt(char *, int);
223 #endif /* defined(XPG4) || defined(__EXTENSIONS__) */
224 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
225 extern void endusershell(void);
226 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
227 extern int execl(const char *, const char *, ...);
228 extern int execle(const char *, const char *, ...);
229 extern int execlp(const char *, const char *, ...);
230 extern int execv(const char *, char *const *);
231 extern int execve(const char *, char *const *, char *const *);
232 extern int execvp(const char *, char *const *);
233 #if defined(_GNU_SOURCE) || defined(__EXTENSIONS__)
234 extern int execvpe(const char *, char *const *, char *const *);
236 extern void _exit(int)
239 * The following fattach prototype is duplicated in <stropts.h>. The
240 * duplication is necessitated by XPG4.2 which requires the prototype
241 * be defined in <stropts.h>.
243 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
244 extern int fattach(int, const char *);
245 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
246 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
247 extern int fchdir(int);
248 extern int fchown(int, uid_t
, gid_t
);
249 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
250 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
251 extern int fchroot(int);
252 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
253 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2) || \
254 defined(__EXTENSIONS__)
255 extern int fdatasync(int);
256 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2)... */
258 * The following fdetach prototype is duplicated in <stropts.h>. The
259 * duplication is necessitated by XPG4.2 which requires the prototype
260 * be defined in <stropts.h>.
262 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
263 extern int fdetach(const char *);
264 #endif /* !defined(__XOPEN_OR_POSIX)... */
265 extern pid_t
fork(void);
266 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
267 extern pid_t
fork1(void);
268 extern pid_t
forkall(void);
269 #endif /* !defined(__XOPEN_OR_POSIX)... */
270 extern long fpathconf(int, int);
271 #if !defined(_POSIX_C_SOURCE) || (_POSIX_C_SOURCE > 2) || \
272 defined(__EXTENSIONS__)
273 extern int fsync(int);
274 #endif /* !defined(_POSIX_C_SOURCE) || (_POSIX_C_SOURCE > 2)... */
275 extern int ftruncate(int, off_t
);
276 extern char *getcwd(char *, size_t);
277 #if !defined(__XOPEN_OR_POSIX) || (defined(_XPG4_2) && !defined(_XPG6)) || \
278 defined(__EXTENSIONS__)
279 extern int getdtablesize(void);
281 extern gid_t
getegid(void);
282 extern uid_t
geteuid(void);
283 extern gid_t
getgid(void);
284 extern int getgroups(int, gid_t
*);
285 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
286 extern long gethostid(void);
288 extern int gethostname(char *, size_t);
290 #ifndef __GETLOGIN_DEFINED /* Avoid duplicate in stdlib.h */
291 extern char *getlogin(void);
292 #endif /* __GETLOGIN_DEFINED */
294 #if defined(_XPG4) || defined(__EXTENSIONS__)
295 extern int getopt(int, char *const *, const char *);
297 extern int opterr
, optind
, optopt
;
298 /* Marked as LEGACY in SUSv2 and removed in SUSv3 */
299 #if !defined(_XPG6) || defined(__EXTENSIONS__)
300 extern char *getpass(const char *);
302 #endif /* defined(_XPG4) || defined(__EXTENSIONS__) */
303 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
304 /* Marked as LEGACY in SUSv2 and removed in SUSv3 */
305 #if !defined(_XPG6) || defined(__EXTENSIONS__)
306 extern int getpagesize(void);
308 extern pid_t
getpgid(pid_t
);
309 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
310 extern pid_t
getpid(void);
311 extern pid_t
getppid(void);
312 extern pid_t
getpgrp(void);
314 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
315 char *gettxt(const char *, const char *);
316 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
317 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
318 extern pid_t
getsid(pid_t
);
319 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
320 extern uid_t
getuid(void);
321 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
322 extern char *getusershell(void);
323 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
325 * The following ioctl prototype is duplicated in <stropts.h>. The
326 * duplication is necessitated by XPG4.2 which requires the prototype
327 * be defined in <stropts.h>.
329 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
330 extern int ioctl(int, int, ...);
331 extern int isaexec(const char *, char *const *, char *const *);
332 extern int issetugid(void);
334 extern int isatty(int);
335 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
336 extern int lchown(const char *, uid_t
, gid_t
);
338 extern int link(const char *, const char *);
339 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
340 extern offset_t
llseek(int, offset_t
, int);
342 extern int lockf(int, int, off_t
);
343 extern off_t
lseek(int, off_t
, int);
344 #if !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
345 defined(__EXTENSIONS__)
346 extern int nice(int);
347 #endif /* !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)... */
348 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
349 extern int mincore(caddr_t
, size_t, char *);
351 extern long pathconf(const char *, int);
352 extern int pause(void);
353 extern int pipe(int *);
354 extern int pipe2(int *, int);
355 extern ssize_t
pread(int, void *, size_t, off_t
);
356 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
357 extern void profil(unsigned short *, size_t, unsigned long, unsigned int);
360 * pthread_atfork() is also declared in <pthread.h> as per SUSv3. The
361 * declarations are identical. A change to either one may also require
362 * appropriate namespace updates in order to avoid redeclaration
363 * warnings in the case where both prototypes are exposed via inclusion
364 * of both <pthread.h> and <unistd.h>.
366 #if !defined(__XOPEN_OR_POSIX) || \
367 ((_POSIX_C_SOURCE > 2) && !defined(_XPG6)) || \
368 defined(__EXTENSIONS__)
369 extern int pthread_atfork(void (*) (void), void (*) (void), void (*) (void));
370 #endif /* !defined(__XOPEN_OR_POSIX) || ((_POSIX_C_SOURCE > 2) ... */
371 #if !defined(_LP64) && \
372 (!defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__))
373 extern int ptrace(int, pid_t
, int, int);
375 extern ssize_t
pwrite(int, const void *, size_t, off_t
);
376 extern ssize_t
read(int, void *, size_t);
377 #if !defined(__XOPEN_OR_POSIX) || \
378 defined(_XPG4_2) || defined(__EXTENSIONS__)
379 extern ssize_t
readlink(const char *_RESTRICT_KYWD
, char *_RESTRICT_KYWD
,
382 #if (!defined(__XOPEN_OR_POSIX) || (defined(_XPG3) && !defined(_XPG4))) || \
383 defined(__EXTENSIONS__)
384 #if __cplusplus >= 199711L
387 extern int rename(const char *, const char *);
388 #if __cplusplus >= 199711L
389 } /* end of namespace std */
392 #endif /* __cplusplus >= 199711L */
393 #endif /* (!defined(__XOPEN_OR_POSIX) || (defined(_XPG3)... */
394 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
395 extern int resolvepath(const char *, char *, size_t);
396 #endif /* !defined(__XOPEN_OR_POSIX)|| defined(__EXTENSIONS__) */
397 extern int rmdir(const char *);
399 #if !defined(__XOPEN_OR_POSIX) || (defined(_XPG4_2) && !defined(_XPG6)) || \
400 defined(__EXTENSIONS__)
401 extern void *sbrk(intptr_t);
402 #endif /* !defined(__XOPEN_OR_POSIX) || (defined(_XPG4_2)... */
403 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
404 extern int setegid(gid_t
);
405 extern int seteuid(uid_t
);
406 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG6) ... */
407 extern int setgid(gid_t
);
408 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
409 extern int setgroups(int, const gid_t
*);
410 extern int sethostname(char *, int);
411 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
412 extern int setpgid(pid_t
, pid_t
);
413 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
414 extern pid_t
setpgrp(void);
415 extern int setregid(gid_t
, gid_t
);
416 extern int setreuid(uid_t
, uid_t
);
417 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
418 extern pid_t
setsid(void);
419 extern int setuid(uid_t
);
420 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
421 extern void setusershell(void);
422 #endif /* !defined(__XOPEN_OR_POSIX)|| defined(__EXTENSIONS__) */
423 extern unsigned sleep(unsigned);
424 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
425 extern int stime(const time_t *);
426 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
428 /* __EXTENSIONS__ makes the SVID Third Edition prototype in stdlib.h visible */
429 extern void swab(const void *_RESTRICT_KYWD
, void *_RESTRICT_KYWD
, ssize_t
);
430 #endif /* defined(_XPG4) */
431 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
432 extern int symlink(const char *, const char *);
433 extern void sync(void);
434 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) */
435 #if defined(_XPG5) && !defined(_XPG6)
436 #ifdef __PRAGMA_REDEFINE_EXTNAME
437 #pragma redefine_extname sysconf __sysconf_xpg5
438 #else /* __PRAGMA_REDEFINE_EXTNAME */
439 #define sysconf __sysconf_xpg5
440 #endif /* __PRAGMA_REDEFINE_EXTNAME */
441 #endif /* defined(_XPG5) && !defined(_XPG6) */
442 extern long sysconf(int);
443 extern pid_t
tcgetpgrp(int);
444 extern int tcsetpgrp(int, pid_t
);
445 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
446 extern off_t
tell(int);
447 #endif /* !defined(__XOPEN_OR_POSIX)... */
448 #if __XPG_VISIBLE >= 420
449 extern int truncate(const char *, off_t
);
451 extern char *ttyname(int);
452 #if (defined(_XPG4_2) && !defined(_XPG7)) || !defined(_STRICT_SYMBOLS)
453 extern useconds_t
ualarm(useconds_t
, useconds_t
);
455 extern int unlink(const char *);
456 #if (defined(_XPG4_2) && !defined(_XPG7)) || !defined(_STRICT_SYMBOLS)
457 extern char *getwd(char *);
458 extern int usleep(useconds_t
);
459 extern pid_t
vfork(void) __RETURNS_TWICE
;
460 #pragma unknown_control_flow(vfork)
462 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
463 extern void vhangup(void);
464 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
465 extern ssize_t
write(int, const void *, size_t);
466 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
467 extern void yield(void);
468 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
470 #if !defined(__XOPEN_OR_POSIX) || defined(_ATFILE_SOURCE) || \
471 defined(__EXTENSIONS__)
472 /* || defined(_XPG7) */
473 extern int faccessat(int, const char *, int, int);
474 extern int fchownat(int, const char *, uid_t
, gid_t
, int);
475 extern int linkat(int, const char *, int, const char *, int);
476 extern ssize_t
readlinkat(int, const char *_RESTRICT_KYWD
,
477 char *_RESTRICT_KYWD
, size_t);
478 extern int renameat(int, const char *, int, const char *);
479 extern int symlinkat(const char *, int, const char *);
480 extern int unlinkat(int, const char *, int);
481 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_ATFILE_SOURCE)... */
482 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
483 extern int get_nprocs(void);
484 extern int get_nprocs_conf(void);
485 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
487 extern int getlogin_r(char *, size_t);
488 extern int ttyname_r(int, char *, size_t);
490 #if !defined(_STRICT_SYMBOLS)
491 extern int getentropy(void *, size_t);
492 #endif /* !_STRICT_SYMBOLS */
494 #if __UNLEASHED_VISIBLE
495 extern mode_t
getmode(const void *, mode_t
);
496 extern void *setmode(const char *);
503 #endif /* _UNISTD_H */