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