1 /* $NetBSD: compat_defs.h,v 1.77 2010/01/14 21:38:19 christos Exp $ */ 2 3 #ifndef __NETBSD_COMPAT_DEFS_H__ 4 #define __NETBSD_COMPAT_DEFS_H__ 5 6 7 /* Work around some complete brain damage. */ 8 /* 9 * Linux: <features.h> turns on _POSIX_SOURCE by default, even though the 10 * program (not the OS) should do that. Preload <features.h> to keep any 11 * of this crap from being pulled in, and undefine _POSIX_SOURCE. 12 */ 13 14 #if defined(__linux__) && HAVE_FEATURES_H 15 #include <features.h> 16 #define __USE_ISOC99 1 17 #endif 18 19 /* So _NETBSD_SOURCE doesn't end up defined. Define enough to pull in standard 20 defs. Other platforms may need similiar defines. */ 21 #ifdef __NetBSD__ 22 #define _ISOC99_SOURCE 23 #define _POSIX_SOURCE 1 24 #define _POSIX_C_SOURCE 200112L 25 #define _XOPEN_SOURCE 600 26 #else 27 #undef _POSIX_SOURCE 28 #undef _POSIX_C_SOURCE 29 #endif 30 31 /* System headers needed for (re)definitions below. */ 32 33 #include <sys/types.h> 34 #include <sys/mman.h> 35 #include <sys/param.h> 36 /* time.h needs to be pulled in first at least on netbsd w/o _NETBSD_SOURCE */ 37 #include <sys/time.h> 38 #include <sys/stat.h> 39 #include <errno.h> 40 #include <fcntl.h> 41 #include <limits.h> 42 #include <paths.h> 43 #include <stdarg.h> 44 #include <stdio.h> 45 #include <stdlib.h> 46 #include <string.h> 47 48 #if HAVE_SYS_CDEFS_H 49 #include <sys/cdefs.h> 50 #endif 51 #if HAVE_SYS_SYSLIMITS_H 52 #include <sys/syslimits.h> 53 #endif 54 #if HAVE_SYS_SYSMACROS_H 55 /* major(), minor() on SVR4 */ 56 #include <sys/sysmacros.h> 57 #endif 58 #if HAVE_INTTYPES_H 59 #include <inttypes.h> 60 #endif 61 #if HAVE_STDDEF_H 62 #include <stddef.h> 63 #endif 64 65 #ifdef _NETBSD_SOURCE 66 #error _NETBSD_SOURCE is *not* to be defined. 67 #endif 68 69 /* Need this since we can't depend on NetBSD's version to be around */ 70 #ifdef __UNCONST 71 #undef __UNCONST 72 #endif 73 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 74 75 /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */ 76 struct passwd; 77 78 /* We don't include <grp.h> either */ 79 struct group; 80 81 /* Assume an ANSI compiler for the host. */ 82 83 #undef __P 84 #define __P(x) x 85 86 #ifndef __BEGIN_DECLS 87 #define __BEGIN_DECLS 88 #endif 89 #ifndef __END_DECLS 90 #define __END_DECLS 91 #endif 92 93 /* Some things usually in BSD <sys/cdefs.h>. */ 94 95 #ifndef __CONCAT 96 #define __CONCAT(x,y) x ## y 97 #endif 98 #if !defined(__attribute__) && !defined(__GNUC__) 99 #define __attribute__(x) 100 #endif 101 #if !defined(__packed) 102 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) 103 #define __packed __attribute__((__packed__)) 104 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) 105 #define __packed __attribute__((__packed__)) 106 #else 107 #define __packed error: no __packed for this compiler 108 #endif 109 #endif /* !__packed */ 110 #ifndef __RENAME 111 #define __RENAME(x) 112 #endif 113 #undef __aconst 114 #define __aconst 115 #undef __dead 116 #define __dead 117 #undef __restrict 118 #define __restrict 119 #undef __unused 120 #define __unused 121 #undef __arraycount 122 #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) 123 124 /* Dirent support. */ 125 126 #if HAVE_DIRENT_H 127 # if defined(__linux__) && defined(__USE_BSD) 128 # undef __USE_BSD 129 # include <dirent.h> 130 # define __USE_BSD 1 131 # undef d_fileno 132 # else 133 # include <dirent.h> 134 # if defined(__DARWIN_UNIX03) 135 # undef d_fileno 136 # endif 137 # endif 138 # define NAMLEN(dirent) (strlen((dirent)->d_name)) 139 #else 140 # define dirent direct 141 # define NAMLEN(dirent) ((dirent)->d_namlen) 142 # if HAVE_SYS_NDIR_H 143 # include <sys/ndir.h> 144 # endif 145 # if HAVE_SYS_DIR_H 146 # include <sys/dir.h> 147 # endif 148 # if HAVE_NDIR_H 149 # include <ndir.h> 150 # endif 151 #endif 152 153 /* Type substitutes. */ 154 155 #if !HAVE_ID_T 156 typedef unsigned int id_t; 157 #endif 158 159 #if !HAVE_SOCKLEN_T 160 typedef int socklen_t; 161 #endif 162 163 #if !HAVE_U_LONG 164 typedef unsigned long u_long; 165 #endif 166 167 #if !HAVE_U_CHAR 168 typedef unsigned char u_char; 169 #endif 170 171 #if !HAVE_U_INT 172 typedef unsigned int u_int; 173 #endif 174 175 #if !HAVE_U_SHORT 176 typedef unsigned short u_short; 177 #endif 178 179 /* Prototypes for replacement functions. */ 180 181 #if !HAVE_ATOLL 182 long long int atoll(const char *); 183 #endif 184 185 #if !HAVE_ASPRINTF 186 int asprintf(char **, const char *, ...); 187 #endif 188 189 #if !HAVE_ASNPRINTF 190 int asnprintf(char **, size_t, const char *, ...); 191 #endif 192 193 #if !HAVE_BASENAME 194 char *basename(char *); 195 #endif 196 197 #if !HAVE_DECL_OPTIND 198 int getopt(int, char *const *, const char *); 199 extern char *optarg; 200 extern int optind, opterr, optopt; 201 #endif 202 203 #if !HAVE_DIRNAME 204 char *dirname(char *); 205 #endif 206 207 #if !HAVE_DIRFD 208 #if HAVE_DIR_DD_FD 209 #define dirfd(dirp) ((dirp)->dd_fd) 210 #elif HAVE_DIR___DD_FD 211 #define dirfd(dirp) ((dirp)->__dd_fd) 212 #else 213 /*XXX: Very hacky but no other way to bring this into scope w/o defining 214 _NETBSD_SOURCE which we're avoiding. */ 215 #ifdef __NetBSD__ 216 struct _dirdesc { 217 int dd_fd; /* file descriptor associated with directory */ 218 long dd_loc; /* offset in current buffer */ 219 long dd_size; /* amount of data returned by getdents */ 220 char *dd_buf; /* data buffer */ 221 int dd_len; /* size of data buffer */ 222 off_t dd_seek; /* magic cookie returned by getdents */ 223 long dd_rewind; /* magic cookie for rewinding */ 224 int dd_flags; /* flags for readdir */ 225 void *dd_lock; /* lock for concurrent access */ 226 }; 227 #define dirfd(dirp) (((struct _dirdesc *)dirp)->dd_fd) 228 #else 229 #error cannot figure out how to turn a DIR * into a fd 230 #endif 231 #endif 232 #endif 233 234 #if !HAVE_ERR_H 235 void err(int, const char *, ...); 236 void errx(int, const char *, ...); 237 void warn(const char *, ...); 238 void warnx(const char *, ...); 239 void vwarnx(const char *, va_list); 240 #endif 241 242 #if !HAVE_ESETFUNC 243 void (*esetfunc(void (*)(int, const char *, ...)))(int, const char *, ...); 244 size_t estrlcpy(char *, const char *, size_t); 245 size_t estrlcat(char *, const char *, size_t); 246 char *estrdup(const char *); 247 char *estrndup(const char *, size_t); 248 void *ecalloc(size_t, size_t); 249 void *emalloc(size_t); 250 void *erealloc(void *, size_t); 251 FILE *efopen(const char *, const char *); 252 int easprintf(char **, const char *, ...); 253 int evasprintf(char **, const char *, va_list); 254 #endif 255 256 #if !HAVE_FGETLN || defined(__NetBSD__) 257 char *fgetln(FILE *, size_t *); 258 #endif 259 260 #if !HAVE_FLOCK 261 # define LOCK_SH 0x01 262 # define LOCK_EX 0x02 263 # define LOCK_NB 0x04 264 # define LOCK_UN 0x08 265 int flock(int, int); 266 #endif 267 268 #if !HAVE_FPARSELN || BROKEN_FPARSELN || defined(__NetBSD__) 269 # define FPARSELN_UNESCESC 0x01 270 # define FPARSELN_UNESCCONT 0x02 271 # define FPARSELN_UNESCCOMM 0x04 272 # define FPARSELN_UNESCREST 0x08 273 # define FPARSELN_UNESCALL 0x0f 274 char *fparseln(FILE *, size_t *, size_t *, const char [3], int); 275 #endif 276 277 #if !HAVE_ISSETUGID 278 int issetugid(void); 279 #endif 280 281 #if !HAVE_ISBLANK && !defined(isblank) 282 #define isblank(x) ((x) == ' ' || (x) == '\t') 283 #endif 284 285 #define __nbcompat_bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff)) 286 287 #define __nbcompat_bswap32(x) ((((x) << 24) & 0xff000000) | \ 288 (((x) << 8) & 0x00ff0000) | \ 289 (((x) >> 8) & 0x0000ff00) | \ 290 (((x) >> 24) & 0x000000ff)) 291 292 #define __nbcompat_bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \ 293 ((u_int64_t)bswap32((x) >> 32))) 294 295 #if ! HAVE_DECL_BSWAP16 296 #ifdef bswap16 297 #undef bswap16 298 #endif 299 #define bswap16(x) __nbcompat_bswap16(x) 300 #endif 301 #if ! HAVE_DECL_BSWAP32 302 #ifdef bswap32 303 #undef bswap32 304 #endif 305 #define bswap32(x) __nbcompat_bswap32(x) 306 #endif 307 #if ! HAVE_DECL_BSWAP64 308 #ifdef bswap64 309 #undef bswap64 310 #endif 311 #define bswap64(x) __nbcompat_bswap64(x) 312 #endif 313 314 #if !HAVE_MKSTEMP 315 int mkstemp(char *); 316 #endif 317 318 #if !HAVE_MKDTEMP 319 char *mkdtemp(char *); 320 #endif 321 322 #if !HAVE_MKSTEMP || !HAVE_MKDTEMP 323 /* This is a prototype for the internal function defined in 324 * src/lib/lib/stdio/gettemp.c */ 325 int __nbcompat_gettemp(char *, int *, int); 326 #endif 327 328 #if !HAVE_PREAD 329 ssize_t pread(int, void *, size_t, off_t); 330 #endif 331 332 #if !HAVE_HEAPSORT 333 int heapsort (void *, size_t, size_t, int (*)(const void *, const void *)); 334 #endif 335 /* Make them use our version */ 336 # define heapsort __nbcompat_heapsort 337 338 char *flags_to_string(unsigned long, const char *); 339 int string_to_flags(char **, unsigned long *, unsigned long *); 340 341 /* 342 * HAVE_X_FROM_Y and HAVE_PWCACHE_FOODB go together, because we cannot 343 * supply an implementation of one without the others -- some parts are 344 * libc internal and this varies from system to system. 345 * 346 * XXX this is dubious anyway: we assume (see HAVE_DECLs below) that if the 347 * XXX host system has all of these functions, all of their interfaces 348 * XXX and interactions are exactly the same as in our libc/libutil -- ugh. 349 */ 350 #if !HAVE_USER_FROM_UID || !HAVE_UID_FROM_USER || !HAVE_GROUP_FROM_GID || \ 351 !HAVE_GID_FROM_GROUP || !HAVE_PWCACHE_USERDB || !HAVE_PWCACHE_GROUDB 352 /* Make them use our version */ 353 # define user_from_uid __nbcompat_user_from_uid 354 # define uid_from_user __nbcompat_uid_from_user 355 # define pwcache_userdb __nbcompat_pwcache_userdb 356 # define group_from_gid __nbcompat_group_from_gid 357 # define gid_from_group __nbcompat_gid_from_group 358 # define pwcache_groupdb __nbcompat_pwcache_groupdb 359 #endif 360 361 #if !HAVE_DECL_UID_FROM_USER 362 int uid_from_user(const char *, uid_t *); 363 #endif 364 365 #if !HAVE_DECL_USER_FROM_UID 366 const char *user_from_uid(uid_t, int); 367 #endif 368 369 #if !HAVE_DECL_PWCACHE_USERDB 370 int pwcache_userdb(int (*)(int), void (*)(void), 371 struct passwd * (*)(const char *), struct passwd * (*)(uid_t)); 372 #endif 373 374 #if !HAVE_DECL_GID_FROM_GROUP 375 int gid_from_group(const char *, gid_t *); 376 #endif 377 378 #if !HAVE_DECL_GROUP_FROM_GID 379 const char *group_from_gid(gid_t, int); 380 #endif 381 382 #if !HAVE_DECL_PWCACHE_GROUPDB 383 int pwcache_groupdb(int (*)(int), void (*)(void), 384 struct group * (*)(const char *), struct group * (*)(gid_t)); 385 #endif 386 387 #if !HAVE_DECL_STRNDUP 388 char *strndup(const char *, size_t); 389 #endif 390 #if !HAVE_DECL_LCHFLAGS 391 int lchflags(const char *, unsigned long); 392 #endif 393 #if !HAVE_DECL_LCHMOD 394 int lchmod(const char *, mode_t); 395 #endif 396 #if !HAVE_DECL_LCHOWN 397 int lchown(const char *, uid_t, gid_t); 398 #endif 399 400 #if !HAVE_PWRITE 401 ssize_t pwrite(int, const void *, size_t, off_t); 402 #endif 403 404 #if !HAVE_RAISE_DEFAULT_SIGNAL 405 int raise_default_signal(int); 406 #endif 407 408 #if !HAVE_SETENV 409 int setenv(const char *, const char *, int); 410 #endif 411 412 #if !HAVE_DECL_SETGROUPENT 413 int setgroupent(int); 414 #endif 415 416 #if !HAVE_DECL_SETPASSENT 417 int setpassent(int); 418 #endif 419 420 #if !HAVE_SETPROGNAME || defined(__NetBSD__) 421 const char *getprogname(void); 422 void setprogname(const char *); 423 #endif 424 425 #if !HAVE_SNPRINTF 426 int snprintf(char *, size_t, const char *, ...); 427 #endif 428 429 #if !HAVE_STRLCAT 430 size_t strlcat(char *, const char *, size_t); 431 #endif 432 433 #if !HAVE_STRLCPY 434 size_t strlcpy(char *, const char *, size_t); 435 #endif 436 437 #if !HAVE_STRMODE 438 void strmode(mode_t, char *); 439 #endif 440 441 #if !HAVE_STRNDUP 442 char *strndup(const char *, size_t); 443 #endif 444 445 #if !HAVE_STRSEP || defined(__NetBSD__) 446 char *strsep(char **, const char *); 447 #endif 448 449 #if !HAVE_DECL_STRSUFTOLL 450 long long strsuftoll(const char *, const char *, long long, long long); 451 long long strsuftollx(const char *, const char *, 452 long long, long long, char *, size_t); 453 #endif 454 455 #if !HAVE_STRTOLL 456 long long strtoll(const char *, char **, int); 457 #endif 458 459 #if !HAVE_USER_FROM_UID 460 const char *user_from_uid(uid_t, int); 461 #endif 462 463 #if !HAVE_GROUP_FROM_GID 464 const char *group_from_gid(gid_t, int); 465 #endif 466 467 #if !HAVE_VASPRINTF 468 int vasprintf(char **, const char *, va_list); 469 #endif 470 471 #if !HAVE_VASNPRINTF 472 int vasnprintf(char **, size_t, const char *, va_list); 473 #endif 474 475 #if !HAVE_VSNPRINTF 476 int vsnprintf(char *, size_t, const char *, va_list); 477 #endif 478 479 /* 480 * getmode() and setmode() are always defined, as these function names 481 * exist but with very different meanings on other OS's. The compat 482 * versions here simply accept an octal mode number; the "u+x,g-w" type 483 * of syntax is not accepted. 484 */ 485 486 #define getmode __nbcompat_getmode 487 #define setmode __nbcompat_setmode 488 489 mode_t getmode(const void *, mode_t); 490 void *setmode(const char *); 491 492 /* Eliminate assertions embedded in binaries. */ 493 494 #undef _DIAGASSERT 495 #define _DIAGASSERT(x) 496 497 /* Various sources use this */ 498 #undef __RCSID 499 #define __RCSID(x) struct XXXNETBSD_RCSID 500 #undef __SCCSID 501 #define __SCCSID(x) 502 #undef __COPYRIGHT 503 #define __COPYRIGHT(x) struct XXXNETBSD_COPYRIGHT 504 #undef __KERNEL_RCSID 505 #define __KERNEL_RCSID(x,y) 506 507 /* Heimdal expects this one. */ 508 509 #undef RCSID 510 #define RCSID(x) 511 512 /* Some definitions not available on all systems. */ 513 514 #ifndef __inline 515 #define __inline inline 516 #endif 517 518 /* <errno.h> */ 519 520 #ifndef EFTYPE 521 #define EFTYPE EIO 522 #endif 523 524 /* <fcntl.h> */ 525 526 #ifndef O_EXLOCK 527 #define O_EXLOCK 0 528 #endif 529 #ifndef O_SHLOCK 530 #define O_SHLOCK 0 531 #endif 532 533 /* <inttypes.h> */ 534 535 #if USHRT_MAX == 0xffffU /* short is a 16-bit type */ 536 #ifndef PRId16 537 #define PRId16 "hd" 538 #endif 539 #ifndef PRIi16 540 #define PRIi16 "hi" 541 #endif 542 #ifndef PRIo16 543 #define PRIo16 "ho" 544 #endif 545 #ifndef PRIu16 546 #define PRIu16 "hu" 547 #endif 548 #ifndef PRIx16 549 #define PRIx16 "hx" 550 #endif 551 #ifndef PRIX16 552 #define PRIX16 "hX" 553 #endif 554 #endif /* short is a 16-bit type */ 555 #if ! (defined(PRId16) && defined(PRIi16) && defined(PRIo16) && \ 556 defined(PRIu16) && defined(PRIx16) && defined(PRIX16)) 557 #error "Don't know how to define PRI[diouxX]16" 558 #endif 559 560 #if UINT_MAX == 0xffffffffU /* int is a 32-bit type */ 561 #ifndef PRId32 562 #define PRId32 "d" 563 #endif 564 #ifndef PRIi32 565 #define PRIi32 "i" 566 #endif 567 #ifndef PRIo32 568 #define PRIo32 "o" 569 #endif 570 #ifndef PRIu32 571 #define PRIu32 "u" 572 #endif 573 #ifndef PRIx32 574 #define PRIx32 "x" 575 #endif 576 #ifndef PRIX32 577 #define PRIX32 "X" 578 #endif 579 #endif /* int is a 32-bit type */ 580 #if ULONG_MAX == 0xffffffffU /* long is a 32-bit type */ 581 #ifndef PRId32 582 #define PRId32 "ld" 583 #endif 584 #ifndef PRIi32 585 #define PRIi32 "li" 586 #endif 587 #ifndef PRIo32 588 #define PRIo32 "lo" 589 #endif 590 #ifndef PRIu32 591 #define PRIu32 "lu" 592 #endif 593 #ifndef PRIx32 594 #define PRIx32 "lx" 595 #endif 596 #ifndef PRIX32 597 #define PRIX32 "lX" 598 #endif 599 #endif /* long is a 32-bit type */ 600 #if ! (defined(PRId32) && defined(PRIi32) && defined(PRIo32) && \ 601 defined(PRIu32) && defined(PRIx32) && defined(PRIX32)) 602 #error "Don't know how to define PRI[diouxX]32" 603 #endif 604 605 #if ULONG_MAX == 0xffffffffffffffffU /* long is a 64-bit type */ 606 #ifndef PRId64 607 #define PRId64 "ld" 608 #endif 609 #ifndef PRIi64 610 #define PRIi64 "li" 611 #endif 612 #ifndef PRIo64 613 #define PRIo64 "lo" 614 #endif 615 #ifndef PRIu64 616 #define PRIu64 "lu" 617 #endif 618 #ifndef PRIx64 619 #define PRIx64 "lx" 620 #endif 621 #ifndef PRIX64 622 #define PRIX64 "lX" 623 #endif 624 #endif /* long is a 64-bit type */ 625 #if ULLONG_MAX == 0xffffffffffffffffU /* long long is a 64-bit type */ 626 #ifndef PRId64 627 #define PRId64 "lld" 628 #endif 629 #ifndef PRIi64 630 #define PRIi64 "lli" 631 #endif 632 #ifndef PRIo64 633 #define PRIo64 "llo" 634 #endif 635 #ifndef PRIu64 636 #define PRIu64 "llu" 637 #endif 638 #ifndef PRIx64 639 #define PRIx64 "llx" 640 #endif 641 #ifndef PRIX64 642 #define PRIX64 "llX" 643 #endif 644 #endif /* long long is a 64-bit type */ 645 #if ! (defined(PRId64) && defined(PRIi64) && defined(PRIo64) && \ 646 defined(PRIu64) && defined(PRIx64) && defined(PRIX64)) 647 #error "Don't know how to define PRI[diouxX]64" 648 #endif 649 650 /* <limits.h> */ 651 652 #ifndef UID_MAX 653 #define UID_MAX 32767 654 #endif 655 #ifndef GID_MAX 656 #define GID_MAX UID_MAX 657 #endif 658 659 #ifndef UQUAD_MAX 660 #define UQUAD_MAX ((u_quad_t)-1) 661 #endif 662 #ifndef QUAD_MAX 663 #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1)) 664 #endif 665 #ifndef QUAD_MIN 666 #define QUAD_MIN ((quad_t)(~QUAD_MAX)) 667 #endif 668 #ifndef ULLONG_MAX 669 #define ULLONG_MAX ((unsigned long long)-1) 670 #endif 671 #ifndef LLONG_MAX 672 #define LLONG_MAX ((long long)(ULLONG_MAX >> 1)) 673 #endif 674 #ifndef LLONG_MIN 675 #define LLONG_MIN ((long long)(~LLONG_MAX)) 676 #endif 677 678 /* <paths.h> */ 679 680 /* The host's _PATH_BSHELL might be broken, so override it. */ 681 #undef _PATH_BSHELL 682 #define _PATH_BSHELL PATH_BSHELL 683 #ifndef _PATH_DEFPATH 684 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin" 685 #endif 686 #ifndef _PATH_DEV 687 #define _PATH_DEV "/dev/" 688 #endif 689 #ifndef _PATH_DEVNULL 690 #define _PATH_DEVNULL _PATH_DEV "null" 691 #endif 692 #ifndef _PATH_TMP 693 #define _PATH_TMP "/tmp/" 694 #endif 695 #ifndef _PATH_DEFTAPE 696 #define _PATH_DEFTAPE "/dev/nrst0" 697 #endif 698 #ifndef _PATH_VI 699 #define _PATH_VI "/usr/bin/vi" 700 #endif 701 702 /* <stdarg.h> */ 703 704 #ifndef _BSD_VA_LIST_ 705 #define _BSD_VA_LIST_ va_list 706 #endif 707 708 /* <stdint.h> */ 709 710 #if !defined(SIZE_MAX) && defined(SIZE_T_MAX) 711 #define SIZE_MAX SIZE_T_MAX 712 #endif 713 714 #ifndef UINT8_MAX 715 #define UINT8_MAX 0xffU 716 #endif 717 718 #ifndef UINT16_MAX 719 #define UINT16_MAX 0xffffU 720 #endif 721 722 #ifndef UINT32_MAX 723 #define UINT32_MAX 0xffffffffU 724 #endif 725 726 /* <stdlib.h> */ 727 728 #ifndef __GNUC__ 729 # if HAVE_ALLOCA_H 730 # include <alloca.h> 731 # else 732 # ifndef alloca /* predefined by HP cc +Olibcalls */ 733 char *alloca (); 734 # endif 735 # endif 736 #endif 737 738 /* avoid prototype conflicts with host */ 739 #define cgetcap __nbcompat_cgetcap 740 #define cgetclose __nbcompat_cgetclose 741 #define cgetent __nbcompat_cgetent 742 #define cgetfirst __nbcompat_cgetfirst 743 #define cgetmatch __nbcompat_cgetmatch 744 #define cgetnext __nbcompat_cgetnext 745 #define cgetnum __nbcompat_cgetnum 746 #define cgetset __nbcompat_cgetset 747 #define cgetstr __nbcompat_cgetstr 748 #define cgetustr __nbcompat_cgetustr 749 750 char *cgetcap(char *, const char *, int); 751 int cgetclose(void); 752 int cgetent(char **, const char * const *, const char *); 753 int cgetfirst(char **, const char * const *); 754 int cgetmatch(const char *, const char *); 755 int cgetnext(char **, const char * const *); 756 int cgetnum(char *, const char *, long *); 757 int cgetset(const char *); 758 int cgetstr(char *, const char *, char **); 759 int cgetustr(char *, const char *, char **); 760 761 /* <sys/endian.h> */ 762 763 #if WORDS_BIGENDIAN 764 #if !HAVE_DECL_HTOBE16 765 #define htobe16(x) (x) 766 #endif 767 #if !HAVE_DECL_HTOBE32 768 #define htobe32(x) (x) 769 #endif 770 #if !HAVE_DECL_HTOBE64 771 #define htobe64(x) (x) 772 #endif 773 #if !HAVE_DECL_HTOLE16 774 #define htole16(x) bswap16((u_int16_t)(x)) 775 #endif 776 #if !HAVE_DECL_HTOLE32 777 #define htole32(x) bswap32((u_int32_t)(x)) 778 #endif 779 #if !HAVE_DECL_HTOLE64 780 #define htole64(x) bswap64((u_int64_t)(x)) 781 #endif 782 #else 783 #if !HAVE_DECL_HTOBE16 784 #define htobe16(x) bswap16((u_int16_t)(x)) 785 #endif 786 #if !HAVE_DECL_HTOBE32 787 #define htobe32(x) bswap32((u_int32_t)(x)) 788 #endif 789 #if !HAVE_DECL_HTOBE64 790 #define htobe64(x) bswap64((u_int64_t)(x)) 791 #endif 792 #if !HAVE_DECL_HTOLE16 793 #define htole16(x) (x) 794 #endif 795 #if !HAVE_DECL_HTOLE32 796 #define htole32(x) (x) 797 #endif 798 #if !HAVE_DECL_HTOLE64 799 #define htole64(x) (x) 800 #endif 801 #endif 802 #if !HAVE_DECL_BE16TOH 803 #define be16toh(x) htobe16(x) 804 #endif 805 #if !HAVE_DECL_BE32TOH 806 #define be32toh(x) htobe32(x) 807 #endif 808 #if !HAVE_DECL_BE64TOH 809 #define be64toh(x) htobe64(x) 810 #endif 811 #if !HAVE_DECL_LE16TOH 812 #define le16toh(x) htole16(x) 813 #endif 814 #if !HAVE_DECL_LE32TOH 815 #define le32toh(x) htole32(x) 816 #endif 817 #if !HAVE_DECL_LE64TOH 818 #define le64toh(x) htole64(x) 819 #endif 820 821 #define __GEN_ENDIAN_ENC(bits, endian) \ 822 static void \ 823 endian ## bits ## enc(void *dst, uint ## bits ## _t u) \ 824 { \ 825 u = hto ## endian ## bits (u); \ 826 memcpy(dst, &u, sizeof(u)); \ 827 } 828 #if !HAVE_DECL_BE16ENC 829 __GEN_ENDIAN_ENC(16, be) 830 #endif 831 #if !HAVE_DECL_BE32ENC 832 __GEN_ENDIAN_ENC(32, be) 833 #endif 834 #if !HAVE_DECL_BE64ENC 835 __GEN_ENDIAN_ENC(64, be) 836 #endif 837 #if !HAVE_DECL_LE16ENC 838 __GEN_ENDIAN_ENC(16, le) 839 #endif 840 #if !HAVE_DECL_LE32ENC 841 __GEN_ENDIAN_ENC(32, le) 842 #endif 843 #if !HAVE_DECL_LE64ENC 844 __GEN_ENDIAN_ENC(64, le) 845 #endif 846 #undef __GEN_ENDIAN_ENC 847 848 #define __GEN_ENDIAN_DEC(bits, endian) \ 849 static uint ## bits ## _t \ 850 endian ## bits ## dec(const void *buf) \ 851 { \ 852 uint ## bits ## _t u; \ 853 memcpy(&u, buf, sizeof(u)); \ 854 return endian ## bits ## toh (u); \ 855 } 856 #if !HAVE_DECL_BE16DEC 857 __GEN_ENDIAN_DEC(16, be) 858 #endif 859 #if !HAVE_DECL_BE32DEC 860 __GEN_ENDIAN_DEC(32, be) 861 #endif 862 #if !HAVE_DECL_BE64DEC 863 __GEN_ENDIAN_DEC(64, be) 864 #endif 865 #if !HAVE_DECL_LE16DEC 866 __GEN_ENDIAN_DEC(16, le) 867 #endif 868 #if !HAVE_DECL_LE32DEC 869 __GEN_ENDIAN_DEC(32, le) 870 #endif 871 #if !HAVE_DECL_LE64DEC 872 __GEN_ENDIAN_DEC(64, le) 873 #endif 874 #undef __GEN_ENDIAN_DEC 875 876 /* <sys/mman.h> */ 877 878 #ifndef MAP_FILE 879 #define MAP_FILE 0 880 #endif 881 882 /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */ 883 #ifndef MAP_ANON 884 #ifdef MAP_ANONYMOUS 885 #define MAP_ANON MAP_ANONYMOUS 886 #endif 887 #endif 888 889 /* <sys/param.h> */ 890 891 #undef BIG_ENDIAN 892 #undef LITTLE_ENDIAN 893 #define BIG_ENDIAN 4321 894 #define LITTLE_ENDIAN 1234 895 896 #undef BYTE_ORDER 897 #if WORDS_BIGENDIAN 898 #define BYTE_ORDER BIG_ENDIAN 899 #else 900 #define BYTE_ORDER LITTLE_ENDIAN 901 #endif 902 903 #ifndef DEV_BSIZE 904 #define DEV_BSIZE (1 << 9) 905 #endif 906 907 #undef MIN 908 #undef MAX 909 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 910 #define MAX(a,b) ((a) > (b) ? (a) : (b)) 911 912 #ifndef MAXBSIZE 913 #define MAXBSIZE (64 * 1024) 914 #endif 915 #ifndef MAXFRAG 916 #define MAXFRAG 8 917 #endif 918 #ifndef MAXPHYS 919 #define MAXPHYS (64 * 1024) 920 #endif 921 922 /* XXX needed by makefs; this should be done in a better way */ 923 #undef btodb 924 #define btodb(x) ((x) << 9) 925 926 #undef setbit 927 #undef clrbit 928 #undef isset 929 #undef isclr 930 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY)) 931 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) 932 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY))) 933 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) 934 935 #ifndef powerof2 936 #define powerof2(x) ((((x)-1)&(x))==0) 937 #endif 938 939 #undef roundup 940 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) 941 942 /* <sys/stat.h> */ 943 944 #ifndef ALLPERMS 945 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) 946 #endif 947 #ifndef DEFFILEMODE 948 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 949 #endif 950 #ifndef S_ISTXT 951 #ifdef S_ISVTX 952 #define S_ISTXT S_ISVTX 953 #else 954 #define S_ISTXT 0 955 #endif 956 #endif 957 958 /* Protected by _NETBSD_SOURCE otherwise. */ 959 #if HAVE_STRUCT_STAT_ST_FLAGS && defined(__NetBSD__) 960 #define UF_SETTABLE 0x0000ffff 961 #define UF_NODUMP 0x00000001 962 #define UF_IMMUTABLE 0x00000002 963 #define UF_APPEND 0x00000004 964 #define UF_OPAQUE 0x00000008 965 #define SF_SETTABLE 0xffff0000 966 #define SF_ARCHIVED 0x00010000 967 #define SF_IMMUTABLE 0x00020000 968 #define SF_APPEND 0x00040000 969 #endif 970 971 /* <sys/syslimits.h> */ 972 973 #ifndef LINE_MAX 974 #define LINE_MAX 2048 975 #endif 976 977 /* <sys/time.h> */ 978 979 #ifndef timercmp 980 #define timercmp(tvp, uvp, cmp) \ 981 (((tvp)->tv_sec == (uvp)->tv_sec) ? \ 982 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ 983 ((tvp)->tv_sec cmp (uvp)->tv_sec)) 984 #endif 985 #ifndef timeradd 986 #define timeradd(tvp, uvp, vvp) \ 987 do { \ 988 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ 989 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ 990 if ((vvp)->tv_usec >= 1000000) { \ 991 (vvp)->tv_sec++; \ 992 (vvp)->tv_usec -= 1000000; \ 993 } \ 994 } while (/* CONSTCOND */ 0) 995 #endif 996 #ifndef timersub 997 #define timersub(tvp, uvp, vvp) \ 998 do { \ 999 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ 1000 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ 1001 if ((vvp)->tv_usec < 0) { \ 1002 (vvp)->tv_sec--; \ 1003 (vvp)->tv_usec += 1000000; \ 1004 } \ 1005 } while (/* CONSTCOND */ 0) 1006 #endif 1007 1008 /* <sys/types.h> */ 1009 1010 #ifdef major 1011 #undef major 1012 #endif 1013 #define major(x) ((int32_t)((((x) & 0x000fff00) >> 8))) 1014 1015 #ifdef minor 1016 #undef minor 1017 #endif 1018 #define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \ 1019 (((x) & 0x000000ff) >> 0))) 1020 #ifdef makedev 1021 #undef makedev 1022 #endif 1023 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \ 1024 (((y) << 12) & 0xfff00000) | \ 1025 (((y) << 0) & 0x000000ff))) 1026 #ifndef NBBY 1027 #define NBBY 8 1028 #endif 1029 1030 #if !HAVE_U_QUAD_T 1031 /* #define, not typedef, as quad_t exists as a struct on some systems */ 1032 #define quad_t long long 1033 #define u_quad_t unsigned long long 1034 #define strtoq strtoll 1035 #define strtouq strtoull 1036 #endif 1037 1038 /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */ 1039 #ifdef __NetBSD__ 1040 quad_t strtoq __P((const char *, char **, int)); 1041 u_quad_t strtouq __P((const char *, char **, int)); 1042 #endif 1043 1044 #endif /* !__NETBSD_COMPAT_DEFS_H__ */ 1045