1 /*
   2  * CDDL HEADER START
   3  *
   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.
   7  *
   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.
  12  *
  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]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
  24  * Copyright (c) 2013 Gary Mills
  25  *
  26  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  27  */
  28 
  29 /*      Copyright (c) 1988 AT&T     */
  30 /*        All Rights Reserved   */
  31 
  32 /* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
  33 
  34 /*
  35  * Copyright 2014 PALO, Richard.
  36  */
  37 
  38 #ifndef _UNISTD_H
  39 #define _UNISTD_H
  40 
  41 #include <sys/feature_tests.h>
  42 
  43 #include <sys/null.h>
  44 #include <sys/types.h>
  45 #include <sys/unistd.h>
  46 
  47 #ifdef  __cplusplus
  48 extern "C" {
  49 #endif
  50 
  51 /* Symbolic constants for the "access" routine: */
  52 #define R_OK    4       /* Test for Read permission */
  53 #define W_OK    2       /* Test for Write permission */
  54 #define X_OK    1       /* Test for eXecute permission */
  55 #define F_OK    0       /* Test for existence of File */
  56 
  57 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
  58 #define F_ULOCK 0       /* Unlock a previously locked region */
  59 #define F_LOCK  1       /* Lock a region for exclusive use */
  60 #define F_TLOCK 2       /* Test and lock a region for exclusive use */
  61 #define F_TEST  3       /* Test a region for other processes locks */
  62 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
  63 
  64 /* Symbolic constants for the "lseek" routine: */
  65 
  66 #ifndef SEEK_SET
  67 #define SEEK_SET        0       /* Set file pointer to "offset" */
  68 #endif
  69 
  70 #ifndef SEEK_CUR
  71 #define SEEK_CUR        1       /* Set file pointer to current plus "offset" */
  72 #endif
  73 
  74 #ifndef SEEK_END
  75 #define SEEK_END        2       /* Set file pointer to EOF plus "offset" */
  76 #endif
  77 
  78 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
  79 #ifndef SEEK_DATA
  80 #define SEEK_DATA       3       /* Set file pointer to next data past offset */
  81 #endif
  82 
  83 #ifndef SEEK_HOLE
  84 #define SEEK_HOLE       4       /* Set file pointer to next hole past offset */
  85 #endif
  86 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
  87 
  88 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
  89 /* Path names: */
  90 #define GF_PATH "/etc/group"    /* Path name of the "group" file */
  91 #define PF_PATH "/etc/passwd"   /* Path name of the "passwd" file */
  92 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
  93 
  94 /*
  95  * compile-time symbolic constants,
  96  * Support does not mean the feature is enabled.
  97  * Use pathconf/sysconf to obtain actual configuration value.
  98  */
  99 
 100 /* Values unchanged in UNIX 03 */
 101 #define _POSIX_ASYNC_IO                 1
 102 #define _POSIX_JOB_CONTROL              1
 103 #define _POSIX_SAVED_IDS                1
 104 #define _POSIX_SYNC_IO                  1
 105 
 106 /*
 107  * POSIX.1b compile-time symbolic constants.
 108  */
 109 #if defined(_XPG6)
 110 #define _POSIX_ASYNCHRONOUS_IO          200112L
 111 #define _POSIX_FSYNC                    200112L
 112 #define _POSIX_MAPPED_FILES             200112L
 113 #define _POSIX_MEMLOCK                  200112L
 114 #define _POSIX_MEMLOCK_RANGE            200112L
 115 #define _POSIX_MEMORY_PROTECTION        200112L
 116 #define _POSIX_MESSAGE_PASSING          200112L
 117 #define _POSIX_PRIORITY_SCHEDULING      200112L
 118 #define _POSIX_REALTIME_SIGNALS         200112L
 119 #define _POSIX_SEMAPHORES               200112L
 120 #define _POSIX_SHARED_MEMORY_OBJECTS    200112L
 121 #define _POSIX_SYNCHRONIZED_IO          200112L
 122 #else
 123 #define _POSIX_ASYNCHRONOUS_IO          1
 124 #define _POSIX_FSYNC                    1
 125 #define _POSIX_MAPPED_FILES             1
 126 #define _POSIX_MEMLOCK                  1
 127 #define _POSIX_MEMLOCK_RANGE            1
 128 #define _POSIX_MEMORY_PROTECTION        1
 129 #define _POSIX_MESSAGE_PASSING          1
 130 #define _POSIX_PRIORITY_SCHEDULING      1
 131 #define _POSIX_REALTIME_SIGNALS         1
 132 #define _POSIX_SEMAPHORES               1
 133 #define _POSIX_SHARED_MEMORY_OBJECTS    1
 134 #define _POSIX_SYNCHRONIZED_IO          1
 135 #endif
 136 
 137 /*
 138  * POSIX.1c compile-time symbolic constants.
 139  */
 140 #if defined(_XPG6)
 141 #define _POSIX_THREAD_SAFE_FUNCTIONS            200112L
 142 #define _POSIX_THREADS                          200112L
 143 #define _POSIX_THREAD_ATTR_STACKADDR            200112L
 144 #define _POSIX_THREAD_ATTR_STACKSIZE            200112L
 145 #define _POSIX_THREAD_PROCESS_SHARED            200112L
 146 #define _POSIX_THREAD_PRIORITY_SCHEDULING       200112L
 147 #define _POSIX_TIMERS                           200112L
 148 #else
 149 #define _POSIX_THREAD_SAFE_FUNCTIONS            1
 150 #define _POSIX_THREADS                          1
 151 #define _POSIX_THREAD_ATTR_STACKADDR            1
 152 #define _POSIX_THREAD_ATTR_STACKSIZE            1
 153 #define _POSIX_THREAD_PROCESS_SHARED            1
 154 #define _POSIX_THREAD_PRIORITY_SCHEDULING       1
 155 #define _POSIX_TIMERS                           1
 156 #endif
 157 
 158 /* New in UNIX 03 */
 159 #define _POSIX_ADVISORY_INFO                    200112L
 160 #define _POSIX_BARRIERS                         200112L
 161 #define _POSIX_CLOCK_SELECTION                  200112L
 162 #define _POSIX_IPV6                             200112L
 163 #define _POSIX_MONOTONIC_CLOCK                  200112L
 164 #define _POSIX_RAW_SOCKETS                      200112L
 165 #define _POSIX_READER_WRITER_LOCKS              200112L
 166 #define _POSIX_SPAWN                            200112L
 167 #define _POSIX_SPIN_LOCKS                       200112L
 168 #define _POSIX_TIMEOUTS                         200112L
 169 
 170 /*
 171  * Support for the POSIX.1 mutex protocol attribute. For realtime applications
 172  * which need mutexes to support priority inheritance/ceiling.
 173  */
 174 #if defined(_XPG6)
 175 #define _POSIX_THREAD_PRIO_INHERIT              200112L
 176 #define _POSIX_THREAD_PRIO_PROTECT              200112L
 177 #else
 178 #define _POSIX_THREAD_PRIO_INHERIT              1
 179 #define _POSIX_THREAD_PRIO_PROTECT              1
 180 #endif
 181 
 182 #ifndef _POSIX_VDISABLE
 183 #define _POSIX_VDISABLE         0
 184 #endif
 185 
 186 #define STDIN_FILENO    0
 187 #define STDOUT_FILENO   1
 188 #define STDERR_FILENO   2
 189 
 190 /*
 191  * Large File Summit-related announcement macros.  The system supports both
 192  * the additional and transitional Large File Summit interfaces.  (The final
 193  * two macros provide a finer granularity breakdown of _LFS64_LARGEFILE.)
 194  */
 195 #define _LFS_LARGEFILE          1
 196 #define _LFS64_LARGEFILE        1
 197 #define _LFS64_STDIO            1
 198 #define _LFS64_ASYNCHRONOUS_IO  1
 199 
 200 /* large file compilation environment setup */
 201 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
 202 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 203 #pragma redefine_extname        ftruncate       ftruncate64
 204 #pragma redefine_extname        lseek           lseek64
 205 #pragma redefine_extname        pread           pread64
 206 #pragma redefine_extname        pwrite          pwrite64
 207 #pragma redefine_extname        truncate        truncate64
 208 #pragma redefine_extname        lockf           lockf64
 209 #pragma redefine_extname        tell            tell64
 210 #else   /* __PRAGMA_REDEFINE_EXTNAME */
 211 #define ftruncate                       ftruncate64
 212 #define lseek                           lseek64
 213 #define pread                           pread64
 214 #define pwrite                          pwrite64
 215 #define truncate                        truncate64
 216 #define lockf                           lockf64
 217 #define tell                            tell64
 218 #endif  /* __PRAGMA_REDEFINE_EXTNAME */
 219 #endif  /* !_LP64 && _FILE_OFFSET_BITS == 64 */
 220 
 221 /* In the LP64 compilation environment, the APIs are already large file */
 222 #if defined(_LP64) && defined(_LARGEFILE64_SOURCE)
 223 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 224 #pragma redefine_extname        ftruncate64     ftruncate
 225 #pragma redefine_extname        lseek64         lseek
 226 #pragma redefine_extname        pread64         pread
 227 #pragma redefine_extname        pwrite64        pwrite
 228 #pragma redefine_extname        truncate64      truncate
 229 #pragma redefine_extname        lockf64         lockf
 230 #pragma redefine_extname        tell64          tell
 231 #else   /* __PRAGMA_REDEFINE_EXTNAME */
 232 #define ftruncate64                     ftruncate
 233 #define lseek64                         lseek
 234 #define pread64                         pread
 235 #define pwrite64                        pwrite
 236 #define truncate64                      truncate
 237 #define lockf64                         lockf
 238 #define tell64                          tell
 239 #endif  /* __PRAGMA_REDEFINE_EXTNAME */
 240 #endif  /* _LP64 && _LARGEFILE64_SOURCE */
 241 
 242 extern int access(const char *, int);
 243 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 244 extern int acct(const char *);
 245 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
 246 extern unsigned alarm(unsigned);
 247 /* Marked as LEGACY in SUSv2 and removed in SUSv3 */
 248 #if !defined(__XOPEN_OR_POSIX) || (defined(_XPG4_2) && !defined(_XPG6)) || \
 249         defined(__EXTENSIONS__)
 250 extern int brk(void *);
 251 #endif /* !defined(__XOPEN_OR_POSIX) || (defined(_XPG4_2)... */
 252 extern int chdir(const char *);
 253 extern int chown(const char *, uid_t, gid_t);
 254 /* Marked as LEGACY in SUSv2 and removed in SUSv3 */
 255 #if !defined(_POSIX_C_SOURCE) || (defined(_XOPEN_SOURCE) && \
 256         !defined(_XPG6)) || defined(__EXTENSIONS__)
 257 extern int chroot(const char *);
 258 #endif /* !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE))... */
 259 extern int close(int);
 260 #if defined(_XPG4) || defined(__EXTENSIONS__)
 261 extern size_t confstr(int, char *, size_t);
 262 extern char *crypt(const char *, const char *);
 263 #endif /* defined(_XPG4) || defined(__EXTENSIONS__) */
 264 #if !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
 265         defined(__EXTENSIONS__)
 266 extern char *ctermid(char *);
 267 #endif /* (!defined(_POSIX_C_SOURCE) ... */
 268 #if !defined(__XOPEN_OR_POSIX) || defined(_REENTRANT) || defined(__EXTENSIONS__)
 269 extern char *ctermid_r(char *);
 270 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_REENTRANT) ... */
 271 /* Marked as LEGACY in SUSv2 and removed in SUSv3 */
 272 #if !defined(_XPG6) || defined(__EXTENSIONS__)
 273 extern char *cuserid(char *);
 274 #endif
 275 extern int dup(int);
 276 extern int dup2(int, int);
 277 extern int dup3(int, int, int);
 278 #if defined(_XPG4) || defined(__EXTENSIONS__)
 279 extern void encrypt(char *, int);
 280 #endif /* defined(XPG4) || defined(__EXTENSIONS__) */
 281 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 282 extern void endusershell(void);
 283 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
 284 extern int execl(const char *, const char *, ...);
 285 extern int execle(const char *, const char *, ...);
 286 extern int execlp(const char *, const char *, ...);
 287 extern int execv(const char *, char *const *);
 288 extern int execve(const char *, char *const *, char *const *);
 289 extern int execvp(const char *, char *const *);
 290 extern void _exit(int)
 291         __NORETURN;
 292 /*
 293  * The following fattach prototype is duplicated in <stropts.h>. The
 294  * duplication is necessitated by XPG4.2 which requires the prototype
 295  * be defined in <stropts.h>.
 296  */
 297 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 298 extern int fattach(int, const char *);
 299 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
 300 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
 301 extern int fchdir(int);
 302 extern int fchown(int, uid_t, gid_t);
 303 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
 304 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 305 extern int fchroot(int);
 306 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
 307 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2) || \
 308         defined(__EXTENSIONS__)
 309 extern int fdatasync(int);
 310 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2)... */
 311 /*
 312  * The following fdetach prototype is duplicated in <stropts.h>. The
 313  * duplication is necessitated by XPG4.2 which requires the prototype
 314  * be defined in <stropts.h>.
 315  */
 316 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 317 extern int fdetach(const char *);
 318 #endif /* !defined(__XOPEN_OR_POSIX)... */
 319 extern pid_t fork(void);
 320 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 321 extern pid_t fork1(void);
 322 extern pid_t forkall(void);
 323 #endif /* !defined(__XOPEN_OR_POSIX)... */
 324 extern long fpathconf(int, int);
 325 #if !defined(_POSIX_C_SOURCE) || (_POSIX_C_SOURCE > 2) || \
 326         defined(__EXTENSIONS__)
 327 extern int fsync(int);
 328 #endif /* !defined(_POSIX_C_SOURCE) || (_POSIX_C_SOURCE > 2)... */
 329 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2) || defined(_XPG4_2) || \
 330         (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64) || \
 331         defined(__EXTENSIONS__)
 332 extern int ftruncate(int, off_t);
 333 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE > 2)... */
 334 extern char *getcwd(char *, size_t);
 335 #if !defined(__XOPEN_OR_POSIX) || (defined(_XPG4_2) && !defined(_XPG6)) || \
 336         defined(__EXTENSIONS__)
 337 extern int getdtablesize(void);
 338 #endif
 339 extern gid_t getegid(void);
 340 extern uid_t geteuid(void);
 341 extern gid_t getgid(void);
 342 extern int getgroups(int, gid_t *);
 343 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
 344 extern long gethostid(void);
 345 #endif
 346 #if defined(_XPG4_2)
 347 extern int gethostname(char *, size_t);
 348 #elif  !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 349 extern int gethostname(char *, int);
 350 #endif
 351 
 352 #ifndef __GETLOGIN_DEFINED      /* Avoid duplicate in stdlib.h */
 353 #define __GETLOGIN_DEFINED
 354 #ifndef __USE_LEGACY_LOGNAME__
 355 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 356 #pragma redefine_extname getlogin getloginx
 357 #else   /* __PRAGMA_REDEFINE_EXTNAME */
 358 extern char *getloginx(void);
 359 #define getlogin        getloginx
 360 #endif  /* __PRAGMA_REDEFINE_EXTNAME */
 361 #endif  /* __USE_LEGACY_LOGNAME__ */
 362 extern char *getlogin(void);
 363 #endif  /* __GETLOGIN_DEFINED */
 364 
 365 #if defined(_XPG4) || defined(__EXTENSIONS__)
 366 extern int  getopt(int, char *const *, const char *);
 367 extern char *optarg;
 368 extern int  opterr, optind, optopt;
 369 /* Marked as LEGACY in SUSv2 and removed in SUSv3 */
 370 #if !defined(_XPG6) || defined(__EXTENSIONS__)
 371 extern char *getpass(const char *);
 372 #endif
 373 #endif /* defined(_XPG4) || defined(__EXTENSIONS__) */
 374 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
 375 /* Marked as LEGACY in SUSv2 and removed in SUSv3 */
 376 #if !defined(_XPG6) || defined(__EXTENSIONS__)
 377 extern int getpagesize(void);
 378 #endif
 379 extern pid_t getpgid(pid_t);
 380 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
 381 extern pid_t getpid(void);
 382 extern pid_t getppid(void);
 383 extern pid_t getpgrp(void);
 384 
 385 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 386 char *gettxt(const char *, const char *);
 387 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
 388 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
 389 extern pid_t getsid(pid_t);
 390 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
 391 extern uid_t getuid(void);
 392 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 393 extern char *getusershell(void);
 394 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
 395 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
 396 extern char *getwd(char *);
 397 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
 398 /*
 399  * The following ioctl prototype is duplicated in <stropts.h>. The
 400  * duplication is necessitated by XPG4.2 which requires the prototype
 401  * be defined in <stropts.h>.
 402  */
 403 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 404 extern int ioctl(int, int, ...);
 405 extern int isaexec(const char *, char *const *, char *const *);
 406 extern int issetugid(void);
 407 #endif
 408 extern int isatty(int);
 409 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
 410 extern int lchown(const char *, uid_t, gid_t);
 411 #endif
 412 extern int link(const char *, const char *);
 413 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 414 extern offset_t llseek(int, offset_t, int);
 415 #endif
 416 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
 417         (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64) || \
 418         defined(__EXTENSIONS__)
 419 extern int lockf(int, int, off_t);
 420 #endif
 421 extern off_t lseek(int, off_t, int);
 422 #if !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
 423         defined(__EXTENSIONS__)
 424 extern int nice(int);
 425 #endif /* !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)... */
 426 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 427 extern int mincore(caddr_t, size_t, char *);
 428 #endif
 429 extern long pathconf(const char *, int);
 430 extern int pause(void);
 431 extern int pipe(int *);
 432 extern int pipe2(int *, int);
 433 #if !defined(_POSIX_C_SOURCE) || defined(_XPG5) || \
 434         (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64) || \
 435         defined(__EXTENSIONS__)
 436 extern ssize_t pread(int, void *, size_t, off_t);
 437 #endif
 438 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 439 extern void profil(unsigned short *, size_t, unsigned long, unsigned int);
 440 #endif
 441 /*
 442  * pthread_atfork() is also declared in <pthread.h> as per SUSv3. The
 443  * declarations are identical. A change to either one may also require
 444  * appropriate namespace updates in order to avoid redeclaration
 445  * warnings in the case where both prototypes are exposed via inclusion
 446  * of both <pthread.h> and <unistd.h>.
 447  */
 448 #if !defined(__XOPEN_OR_POSIX) || \
 449         ((_POSIX_C_SOURCE > 2) && !defined(_XPG6)) || \
 450         defined(__EXTENSIONS__)
 451 extern int pthread_atfork(void (*) (void), void (*) (void), void (*) (void));
 452 #endif /* !defined(__XOPEN_OR_POSIX) || ((_POSIX_C_SOURCE > 2) ... */
 453 #if !defined(_LP64) && \
 454         (!defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__))
 455 extern int ptrace(int, pid_t, int, int);
 456 #endif
 457 #if !defined(_POSIX_C_SOURCE) || defined(_XPG5) || \
 458         (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64) || \
 459         defined(__EXTENSIONS__)
 460 extern ssize_t pwrite(int, const void *, size_t, off_t);
 461 #endif
 462 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 463 /* per RFC 3542; This is also defined in netdb.h */
 464 extern int rcmd_af(char **, unsigned short, const char *, const char *,
 465         const char *, int *, int);
 466 #endif
 467 extern ssize_t read(int, void *, size_t);
 468 #if !defined(__XOPEN_OR_POSIX) || \
 469         defined(_XPG4_2) || defined(__EXTENSIONS__)
 470 extern ssize_t readlink(const char *_RESTRICT_KYWD, char *_RESTRICT_KYWD,
 471         size_t);
 472 #endif
 473 #if (!defined(__XOPEN_OR_POSIX) || (defined(_XPG3) && !defined(_XPG4))) || \
 474         defined(__EXTENSIONS__)
 475 #if __cplusplus >= 199711L
 476 namespace std {
 477 #endif
 478 extern int rename(const char *, const char *);
 479 #if __cplusplus >= 199711L
 480 } /* end of namespace std */
 481 
 482 using std::rename;
 483 #endif /* __cplusplus >= 199711L */
 484 #endif /* (!defined(__XOPEN_OR_POSIX) || (defined(_XPG3)... */
 485 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 486 extern int resolvepath(const char *, char *, size_t);
 487 /* per RFC 3542; This is also defined in netdb.h */
 488 extern int rexec_af(char **, unsigned short, const char *, const char *,
 489         const char *, int *, int);
 490 #endif /* !defined(__XOPEN_OR_POSIX)|| defined(__EXTENSIONS__) */
 491 extern int rmdir(const char *);
 492 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 493 /* per RFC 3542; This is also defined in netdb.h */
 494 extern int rresvport_af(int *, int);
 495 #endif
 496 
 497 #if !defined(__XOPEN_OR_POSIX) || (defined(_XPG4_2) && !defined(_XPG6)) || \
 498         defined(__EXTENSIONS__)
 499 extern void *sbrk(intptr_t);
 500 #endif /* !defined(__XOPEN_OR_POSIX) || (defined(_XPG4_2)... */
 501 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG6) || defined(__EXTENSIONS__)
 502 extern int setegid(gid_t);
 503 extern int seteuid(uid_t);
 504 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG6) ... */
 505 extern int setgid(gid_t);
 506 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 507 extern int setgroups(int, const gid_t *);
 508 extern int sethostname(char *, int);
 509 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
 510 extern int setpgid(pid_t, pid_t);
 511 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
 512 extern pid_t setpgrp(void);
 513 extern int setregid(gid_t, gid_t);
 514 extern int setreuid(uid_t, uid_t);
 515 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
 516 extern pid_t setsid(void);
 517 extern int setuid(uid_t);
 518 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 519 extern void setusershell(void);
 520 #endif /* !defined(__XOPEN_OR_POSIX)|| defined(__EXTENSIONS__) */
 521 extern unsigned sleep(unsigned);
 522 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 523 extern int stime(const time_t *);
 524 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
 525 #if defined(_XPG4)
 526 /* __EXTENSIONS__ makes the SVID Third Edition prototype in stdlib.h visible */
 527 extern void swab(const void *_RESTRICT_KYWD, void *_RESTRICT_KYWD, ssize_t);
 528 #endif /* defined(_XPG4) */
 529 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
 530 extern int symlink(const char *, const char *);
 531 extern void sync(void);
 532 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) */
 533 #if defined(_XPG5) && !defined(_XPG6)
 534 #ifdef __PRAGMA_REDEFINE_EXTNAME
 535 #pragma redefine_extname sysconf __sysconf_xpg5
 536 #else /* __PRAGMA_REDEFINE_EXTNAME */
 537 #define sysconf __sysconf_xpg5
 538 #endif  /* __PRAGMA_REDEFINE_EXTNAME */
 539 #endif /* defined(_XPG5) && !defined(_XPG6) */
 540 extern long sysconf(int);
 541 extern pid_t tcgetpgrp(int);
 542 extern int tcsetpgrp(int, pid_t);
 543 #if !defined(__XOPEN_OR_POSIX) || \
 544         (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64) || \
 545         defined(__EXTENSIONS__)
 546 extern off_t tell(int);
 547 #endif /* !defined(__XOPEN_OR_POSIX)... */
 548 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
 549         (defined(_LARGEFILE_SOURCE) && _FILE_OFFSET_BITS == 64) || \
 550         defined(__EXTENSIONS__)
 551 extern int truncate(const char *, off_t);
 552 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
 553 extern char *ttyname(int);
 554 #if (defined(_XPG4_2) && !defined(_XPG7)) || !defined(_STRICT_SYMBOLS)
 555 extern useconds_t ualarm(useconds_t, useconds_t);
 556 #endif
 557 extern int unlink(const char *);
 558 #if (defined(_XPG4_2) && !defined(_XPG7)) || !defined(_STRICT_SYMBOLS)
 559 extern int usleep(useconds_t);
 560 #endif
 561 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
 562 extern pid_t vfork(void) __RETURNS_TWICE;
 563 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
 564 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 565 extern void vhangup(void);
 566 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
 567 extern ssize_t write(int, const void *, size_t);
 568 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 569 extern void yield(void);
 570 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
 571 
 572 #if !defined(__XOPEN_OR_POSIX) || defined(_ATFILE_SOURCE) || \
 573         defined(__EXTENSIONS__)
 574         /* || defined(_XPG7) */
 575 extern int faccessat(int, const char *, int, int);
 576 extern int fchownat(int, const char *, uid_t, gid_t, int);
 577 extern int linkat(int, const char *, int, const char *, int);
 578 extern ssize_t readlinkat(int, const char *_RESTRICT_KYWD,
 579         char *_RESTRICT_KYWD, size_t);
 580 extern int renameat(int, const char *, int, const char *);
 581 extern int symlinkat(const char *, int, const char *);
 582 extern int unlinkat(int, const char *, int);
 583 #endif  /* !defined(__XOPEN_OR_POSIX) || defined(_ATFILE_SOURCE)... */
 584 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
 585 extern int get_nprocs(void);
 586 extern int get_nprocs_conf(void);
 587 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
 588 
 589 /* transitional large file interface versions */
 590 #if     defined(_LARGEFILE64_SOURCE) && !((_FILE_OFFSET_BITS == 64) && \
 591             !defined(__PRAGMA_REDEFINE_EXTNAME))
 592 extern int ftruncate64(int, off64_t);
 593 extern off64_t lseek64(int, off64_t, int);
 594 extern ssize_t  pread64(int, void *, size_t, off64_t);
 595 extern ssize_t  pwrite64(int, const void *, size_t, off64_t);
 596 extern off64_t  tell64(int);
 597 extern int      truncate64(const char *, off64_t);
 598 extern int      lockf64(int, int, off64_t);
 599 #endif  /* _LARGEFILE64_SOURCE */
 600 
 601 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
 602 #pragma unknown_control_flow(vfork)
 603 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)... */
 604 
 605 /*
 606  * getlogin_r() & ttyname_r() prototypes are defined here.
 607  */
 608 
 609 /*
 610  * Previous releases of Solaris, starting at 2.3, provided definitions of
 611  * various functions as specified in POSIX.1c, Draft 6.  For some of these
 612  * functions, the final POSIX 1003.1c standard had a different number of
 613  * arguments and return values.
 614  *
 615  * The following segment of this header provides support for the standard
 616  * interfaces while supporting applications written under earlier
 617  * releases.  The application defines appropriate values of the feature
 618  * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate
 619  * whether it was written to expect the Draft 6 or standard versions of
 620  * these interfaces, before including this header.  This header then
 621  * provides a mapping from the source version of the interface to an
 622  * appropriate binary interface.  Such mappings permit an application
 623  * to be built from libraries and objects which have mixed expectations
 624  * of the definitions of these functions.
 625  *
 626  * For applications using the Draft 6 definitions, the binary symbol is the
 627  * same as the source symbol, and no explicit mapping is needed.  For the
 628  * standard interface, the function func() is mapped to the binary symbol
 629  * _posix_func().  The preferred mechanism for the remapping is a compiler
 630  * #pragma.  If the compiler does not provide such a #pragma, the header file
 631  * defines a static function func() which calls the _posix_func() version;
 632  * this has to be done instead of #define since POSIX specifies that an
 633  * application can #undef the symbol and still be bound to the correct
 634  * implementation.  Unfortunately, the statics confuse lint so we fallback to
 635  * #define in that case.
 636  *
 637  * NOTE: Support for the Draft 6 definitions is provided for compatibility
 638  * only.  New applications/libraries should use the standard definitions.
 639  */
 640 
 641 #if     defined(__EXTENSIONS__) || defined(_REENTRANT) || \
 642         !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L) || \
 643         defined(_POSIX_PTHREAD_SEMANTICS)
 644 
 645 #if     (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
 646 
 647 #ifndef __USE_LEGACY_LOGNAME__
 648 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 649 #pragma redefine_extname getlogin_r __posix_getloginx_r
 650 extern int getlogin_r(char *, int);
 651 #else   /* __PRAGMA_REDEFINE_EXTNAME */
 652 extern int __posix_getloginx_r(char *, int);
 653 #define getlogin_r      __posix_getloginx_r
 654 #endif  /* __PRAGMA_REDEFINE_EXTNAME */
 655 #else   /* __USE_LEGACY_LOGNAME__ */
 656 #ifdef __PRAGMA_REDEFINE_EXTNAME
 657 #pragma redefine_extname getlogin_r __posix_getlogin_r
 658 extern int getlogin_r(char *, int);
 659 #else  /* __PRAGMA_REDEFINE_EXTNAME */
 660 extern int __posix_getlogin_r(char *, int);
 661 
 662 #ifdef __lint
 663 
 664 #define getlogin_r      __posix_getlogin_r
 665 
 666 #else /* !__lint */
 667 
 668 static int
 669 getlogin_r(char *__name, int __len)
 670 {
 671         return (__posix_getlogin_r(__name, __len));
 672 }
 673 
 674 #endif /* !__lint */
 675 #endif /* __PRAGMA_REDEFINE_EXTNAME */
 676 #endif  /* __USE_LEGACY_LOGNAME__ */
 677 
 678 #ifdef __PRAGMA_REDEFINE_EXTNAME
 679 #pragma redefine_extname ttyname_r __posix_ttyname_r
 680 extern int ttyname_r(int, char *, size_t);
 681 #else  /* __PRAGMA_REDEFINE_EXTNAME */
 682 extern int __posix_ttyname_r(int, char *, size_t);
 683 
 684 #ifdef __lint
 685 
 686 #define ttyname_r       __posix_ttyname_r
 687 
 688 #else /* !__lint */
 689 
 690 static int
 691 ttyname_r(int __fildes, char *__buf, size_t __size)
 692 {
 693         return (__posix_ttyname_r(__fildes, __buf, __size));
 694 }
 695 
 696 #endif /* !__lint */
 697 #endif /* __PRAGMA_REDEFINE_EXTNAME */
 698 
 699 #else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
 700 
 701 #ifndef __USE_LEGACY_LOGNAME__
 702 #ifdef  __PRAGMA_REDEFINE_EXTNAME
 703 #pragma redefine_extname getlogin_r getloginx_r
 704 #else   /* __PRAGMA_REDEFINE_EXTNAME */
 705 extern char *getloginx_r(char *, int);
 706 #define getlogin_r      getloginx_r
 707 #endif  /* __PRAGMA_REDEFINE_EXTNAME */
 708 #endif  /* __USE_LEGACY_LOGNAME__ */
 709 extern char *getlogin_r(char *, int);
 710 
 711 extern char *ttyname_r(int, char *, int);
 712 
 713 #endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
 714 
 715 #endif /* defined(__EXTENSIONS__) || defined(_REENTRANT)... */
 716 
 717 #ifdef  __cplusplus
 718 }
 719 #endif
 720 
 721 #endif /* _UNISTD_H */