1 /* $NetBSD: compat_defs.h,v 1.133 2026/01/11 22:08:48 nia Exp $ */ 2 3 #ifndef __NETBSD_COMPAT_DEFS_H__ 4 #define __NETBSD_COMPAT_DEFS_H__ 5 6 /* 7 * On NetBSD, ensure that _NETBSD_SOURCE does not get defined, so that 8 * accidental attempts to use NetBSD-specific features instead of more 9 * portable features is likely to be noticed when the tools are built 10 * on NetBSD. Define enough other feature test macros to expose the 11 * features we need. 12 */ 13 #ifdef __NetBSD__ 14 #define _ISOC99_SOURCE 15 #define _POSIX_SOURCE 1 16 #define _POSIX_C_SOURCE 200112L 17 #define _XOPEN_SOURCE 600 18 #endif /* __NetBSD__ */ 19 20 /* 21 * Linux: <features.h> turns on _POSIX_SOURCE by default, even though the 22 * program (not the OS) should do that. Preload <features.h> and 23 * then override some of the feature test macros. 24 */ 25 26 #if defined(__linux__) && HAVE_FEATURES_H 27 #include <features.h> 28 #undef _POSIX_SOURCE 29 #undef _POSIX_C_SOURCE 30 #define __USE_ISOC99 1 31 #endif /* __linux__ && HAVE_FEATURES_H */ 32 33 /* 34 * Type substitutes. 35 * These are controlled via HAVE_TYPE protections and some of them are needed 36 * in other header files (in the build tree not in the host). This is because 37 * we are mixing the header files (which don't need them) with extensions 38 * such as the Solaris headers which depend on types defined by the native 39 * system headers, and might be missing in the build host. 40 */ 41 42 #if !HAVE_ID_T 43 typedef unsigned int id_t; 44 #endif 45 46 #if !HAVE_DADDR_T 47 typedef unsigned long long daddr_t; 48 #endif 49 50 #if !HAVE_SOCKLEN_T 51 /* 52 * This is defined as int for compatibility with legacy systems (and not 53 * unsigned int), since universally it was int in most systems that did not 54 * define it. 55 */ 56 typedef int socklen_t; 57 #endif 58 59 #if !HAVE_ENUM_UIO_RW 60 enum uio_rw { UIO_READ, UIO_WRITE }; 61 #endif 62 63 #if !HAVE_ENUM_UIO_SEG 64 enum uio_seg { 65 UIO_USERSPACE, /* from user data space */ 66 UIO_SYSSPACE /* from system space */ 67 }; 68 #endif 69 70 #if !HAVE_U_LONG 71 typedef unsigned long u_long; 72 #endif 73 74 #if !HAVE_U_CHAR 75 typedef unsigned char u_char; 76 #endif 77 78 #if !HAVE_U_INT 79 typedef unsigned int u_int; 80 #endif 81 82 #if !HAVE_U_SHORT 83 typedef unsigned short u_short; 84 #endif 85 86 #if !HAVE_UCHAR_T 87 typedef unsigned char uchar_t; 88 #endif 89 90 #if !HAVE_USHORT_T 91 typedef unsigned short ushort_t; 92 #endif 93 94 #if !HAVE_UINT_T 95 typedef unsigned int uint_t; 96 #endif 97 98 #if !HAVE_ULONG_T 99 typedef unsigned long ulong_t; 100 #endif 101 102 /* System headers needed for (re)definitions below. */ 103 104 #include <sys/types.h> 105 #include <sys/mman.h> 106 #include <sys/param.h> 107 /* time.h needs to be pulled in first at least on netbsd w/o _NETBSD_SOURCE */ 108 #include <sys/time.h> 109 #include <sys/stat.h> 110 #include <errno.h> 111 #include <fcntl.h> 112 #include <limits.h> 113 #include <paths.h> 114 #include <ctype.h> 115 #include <stdarg.h> 116 #include <stdio.h> 117 #include <stdlib.h> 118 #include <string.h> 119 #if HAVE_ERR_H 120 #include <err.h> 121 #endif 122 123 #if HAVE_SYS_CDEFS_H 124 #include <sys/cdefs.h> 125 #endif 126 #if HAVE_SYS_SYSLIMITS_H 127 #include <sys/syslimits.h> 128 #endif 129 #if HAVE_SYS_SYSMACROS_H 130 /* major(), minor() on SVR4 */ 131 #include <sys/sysmacros.h> 132 #endif 133 #if HAVE_INTTYPES_H 134 #include <inttypes.h> 135 #endif 136 #if HAVE_STDDEF_H 137 #include <stddef.h> 138 #endif 139 #if HAVE_LIBGEN_H 140 #include <libgen.h> 141 #endif 142 143 #if HAVE_RPC_TYPES_H 144 #include <rpc/types.h> 145 #endif 146 147 #if HAVE_SYS_UIO_H 148 #include <sys/uio.h> 149 #endif 150 151 #ifdef _NETBSD_SOURCE 152 #error _NETBSD_SOURCE is *not* to be defined. 153 #endif 154 155 /* Need this since we can't depend on NetBSD's version to be around */ 156 #ifdef __UNCONST 157 #undef __UNCONST 158 #endif 159 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 160 #ifdef __UNVOLATILE 161 #undef __UNVOLATILE 162 #endif 163 #define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a)) 164 165 166 #undef __predict_false 167 #define __predict_false(x) (x) 168 #undef __predict_true 169 #define __predict_true(x) (x) 170 171 /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */ 172 struct passwd; 173 174 /* We don't include <grp.h> either */ 175 struct group; 176 177 /* Assume an ANSI compiler for the host. */ 178 179 #undef __P 180 #define __P(x) x 181 182 #ifndef __BEGIN_DECLS 183 #define __BEGIN_DECLS 184 #endif 185 #ifndef __END_DECLS 186 #define __END_DECLS 187 #endif 188 189 /* Some things in NetBSD <sys/cdefs.h>. */ 190 191 #ifndef __CONCAT 192 #define __CONCAT(x,y) x ## y 193 #endif 194 #if !defined(__attribute__) && !defined(__GNUC__) 195 #define __attribute__(x) 196 #endif 197 #if !defined(__packed) 198 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) 199 #define __packed __attribute__((__packed__)) 200 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) 201 #define __packed __attribute__((__packed__)) 202 #else 203 #define __packed error: no __packed for this compiler 204 #endif 205 #endif /* !__packed */ 206 #ifndef __RENAME 207 #define __RENAME(x) 208 #endif 209 #undef __aconst 210 #define __aconst 211 #undef __dead 212 #define __dead 213 #undef __printflike 214 #define __printflike(x,y) 215 #undef __format_arg 216 #define __format_arg(x) 217 #undef __restrict 218 #define __restrict 219 #undef __unused 220 #define __unused 221 #undef __arraycount 222 #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0])) 223 #undef __USE 224 #define __USE(a) ((void)(a)) 225 #undef __type_min_s 226 #define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1)))) 227 #undef __type_max_s 228 #define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1)))) 229 #undef __type_min_u 230 #define __type_min_u(t) ((t)0ULL) 231 #undef __type_max_u 232 #define __type_max_u(t) ((t)~0ULL) 233 #undef __type_is_signed 234 #define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1) 235 #undef __type_min 236 #define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t)) 237 #undef __type_max 238 #define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t)) 239 240 /* Dirent support. */ 241 242 #if HAVE_DIRENT_H 243 # if defined(__linux__) && defined(__USE_BSD) 244 # undef __USE_BSD 245 # include <dirent.h> 246 # define __USE_BSD 1 247 # undef d_fileno 248 # else 249 # include <dirent.h> 250 # if defined(__DARWIN_UNIX03) 251 # undef d_fileno 252 # endif 253 # endif 254 # define NAMLEN(dirent) (strlen((dirent)->d_name)) 255 #else 256 # define dirent direct 257 # define NAMLEN(dirent) ((dirent)->d_namlen) 258 # if HAVE_SYS_NDIR_H 259 # include <sys/ndir.h> 260 # endif 261 # if HAVE_SYS_DIR_H 262 # include <sys/dir.h> 263 # endif 264 # if HAVE_NDIR_H 265 # include <ndir.h> 266 # endif 267 #endif 268 269 /* Prototypes for replacement functions. */ 270 271 #if !HAVE_DECL_ATOLL 272 long long int atoll(const char *); 273 #endif 274 275 #if !HAVE_DECL_ASPRINTF 276 int asprintf(char **, const char *, ...); 277 #endif 278 279 #if !HAVE_DECL_ASNPRINTF 280 int asnprintf(char **, size_t, const char *, ...); 281 #endif 282 283 #if !HAVE_DECL_BASENAME 284 char *basename(char *); 285 #endif 286 287 #if !HAVE_DECL_OPTIND 288 int getopt(int, char *const *, const char *); 289 extern char *optarg; 290 extern int optind, opterr, optopt; 291 #endif 292 293 #if !HAVE_DECL_GETSUBOPT 294 int getsubopt(char **, char * const *, char **); 295 #endif 296 297 #if !HAVE_DECL_DIRNAME 298 char *dirname(char *); 299 #endif 300 301 #if !HAVE_DECL_FPURGE 302 int fpurge(FILE *); 303 #endif 304 305 #if !HAVE_DIRFD 306 #if HAVE_DIR_DD_FD 307 #define dirfd(dirp) ((dirp)->dd_fd) 308 #elif HAVE_DIR___DD_FD 309 #define dirfd(dirp) ((dirp)->__dd_fd) 310 #else 311 /*XXX: Very hacky but no other way to bring this into scope w/o defining 312 _NETBSD_SOURCE which we're avoiding. */ 313 #ifdef __NetBSD__ 314 struct _dirdesc { 315 int dd_fd; /* file descriptor associated with directory */ 316 long dd_loc; /* offset in current buffer */ 317 long dd_size; /* amount of data returned by getdents */ 318 char *dd_buf; /* data buffer */ 319 int dd_len; /* size of data buffer */ 320 off_t dd_seek; /* magic cookie returned by getdents */ 321 long dd_rewind; /* magic cookie for rewinding */ 322 int dd_flags; /* flags for readdir */ 323 void *dd_lock; /* lock for concurrent access */ 324 }; 325 #define dirfd(dirp) (((struct _dirdesc *)dirp)->dd_fd) 326 #else 327 #error cannot figure out how to turn a DIR * into a fd 328 #endif 329 #endif 330 #endif 331 332 #if !HAVE_DECL_ERR 333 void err(int, const char *, ...); 334 #endif 335 #if !HAVE_DECL_ERRC 336 void errc(int, int, const char *, ...); 337 #endif 338 #if !HAVE_DECL_ERRX 339 void errx(int, const char *, ...); 340 #endif 341 #if !HAVE_DECL_VERRC 342 void verrc(int, int, const char *, va_list); 343 #endif 344 #if !HAVE_DECL_VERRX 345 void verrx(int, const char *, va_list); 346 #endif 347 #if !HAVE_DECL_WARN 348 void warn(const char *, ...); 349 #endif 350 #if !HAVE_DECL_WARNC 351 void warnc(int, const char *, ...); 352 #endif 353 #if !HAVE_DECL_WARNX 354 void warnx(const char *, ...); 355 #endif 356 #if !HAVE_DECL_VWARNC 357 void vwarnc(int, const char *, va_list); 358 #endif 359 #if !HAVE_DECL_VWARNX 360 void vwarnx(const char *, va_list); 361 #endif 362 363 #if !HAVE_DECL_MI_VECTOR_HASH 364 void mi_vector_hash(const void * __restrict, size_t, uint32_t, 365 uint32_t[3]); 366 #endif 367 368 369 #if !HAVE_ESETFUNC 370 void (*esetfunc(void (*)(int, const char *, ...)))(int, const char *, ...); 371 size_t estrlcpy(char *, const char *, size_t); 372 size_t estrlcat(char *, const char *, size_t); 373 char *estrdup(const char *); 374 char *estrndup(const char *, size_t); 375 void *ecalloc(size_t, size_t); 376 void *emalloc(size_t); 377 void *erealloc(void *, size_t); 378 FILE *efopen(const char *, const char *); 379 int easprintf(char **, const char *, ...); 380 int evasprintf(char **, const char *, va_list); 381 #endif 382 383 #if !HAVE_DECL_FGETLN 384 char *fgetln(FILE *, size_t *); 385 #endif 386 #if !HAVE_DECL_DPRINTF 387 int dprintf(int, const char *, ...); 388 #endif 389 390 #if !HAVE_FLOCK 391 # define LOCK_SH 0x01 392 # define LOCK_EX 0x02 393 # define LOCK_NB 0x04 394 # define LOCK_UN 0x08 395 int flock(int, int); 396 #endif 397 398 #if !HAVE_DECL_FPARSELN || BROKEN_FPARSELN 399 # define FPARSELN_UNESCESC 0x01 400 # define FPARSELN_UNESCCONT 0x02 401 # define FPARSELN_UNESCCOMM 0x04 402 # define FPARSELN_UNESCREST 0x08 403 # define FPARSELN_UNESCALL 0x0f 404 char *fparseln(FILE *, size_t *, size_t *, const char [3], int); 405 #endif 406 407 #if !HAVE_DECL_GETDELIM 408 ssize_t getdelim(char **, size_t *, int, FILE *); 409 #endif 410 #if !HAVE_DECL_GETLINE 411 ssize_t getline(char **, size_t *, FILE *); 412 #endif 413 414 #if !HAVE_DECL_ISSETUGID 415 int issetugid(void); 416 #endif 417 418 #if !HAVE_DECL_ISBLANK && !defined(isblank) 419 #define isblank(x) ((x) == ' ' || (x) == '\t') 420 #endif 421 422 #define __nbcompat_bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff)) 423 424 #define __nbcompat_bswap32(x) ((((x) << 24) & 0xff000000) | \ 425 (((x) << 8) & 0x00ff0000) | \ 426 (((x) >> 8) & 0x0000ff00) | \ 427 (((x) >> 24) & 0x000000ff)) 428 429 #define __nbcompat_bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \ 430 ((u_int64_t)bswap32((x) >> 32))) 431 432 #if ! HAVE_DECL_BSWAP16 433 #ifdef bswap16 434 #undef bswap16 435 #endif 436 #define bswap16(x) __nbcompat_bswap16(x) 437 #endif 438 #if ! HAVE_DECL_BSWAP32 439 #ifdef bswap32 440 #undef bswap32 441 #endif 442 #define bswap32(x) __nbcompat_bswap32(x) 443 #endif 444 #if ! HAVE_DECL_BSWAP64 445 #ifdef bswap64 446 #undef bswap64 447 #endif 448 #define bswap64(x) __nbcompat_bswap64(x) 449 #endif 450 451 #if !HAVE_DECL_MKSTEMP 452 int mkstemp(char *); 453 #endif 454 455 #if !HAVE_DECL_MKSTEMPS 456 int mkstemps(char *, int); 457 #endif 458 459 #if !HAVE_DECL_MKDTEMP 460 char *mkdtemp(char *); 461 #endif 462 463 #if !HAVE_MKSTEMP || !HAVE_MKDTEMP 464 /* This is a prototype for the internal function defined in 465 * src/lib/libc/stdio/gettemp.c */ 466 int __nbcompat_gettemp(char *, int *, int, int, int); 467 #endif 468 469 #if !HAVE_DECL_PREAD 470 ssize_t pread(int, void *, size_t, off_t); 471 #endif 472 473 int __nbcompat_heapsort(void *, size_t, size_t, 474 int (*)(const void *, const void *)); 475 int __nbcompat_heapsort_r(void *, size_t, size_t, 476 int (*)(const void *, const void *, void *), void *); 477 #define heapsort __nbcompat_heapsort 478 #define heapsort_r __nbcompat_heapsort_r 479 480 #if !HAVE_DECL_HEAPSORT 481 int heapsort (void *, size_t, size_t, int (*)(const void *, const void *)); 482 #endif 483 484 char *flags_to_string(unsigned long, const char *); 485 int string_to_flags(char **, unsigned long *, unsigned long *); 486 487 /* 488 * HAVE_X_FROM_Y and HAVE_PWCACHE_FOODB go together, because we cannot 489 * supply an implementation of one without the others -- some parts are 490 * libc internal and this varies from system to system. 491 * 492 * XXX this is dubious anyway: we assume (see HAVE_DECLs below) that if the 493 * XXX host system has all of these functions, all of their interfaces 494 * XXX and interactions are exactly the same as in our libc/libutil -- ugh. 495 */ 496 #if !HAVE_USER_FROM_UID || !HAVE_UID_FROM_USER || !HAVE_GROUP_FROM_GID || \ 497 !HAVE_GID_FROM_GROUP || !HAVE_PWCACHE_USERDB || !HAVE_PWCACHE_GROUDB 498 /* Make them use our version */ 499 # define user_from_uid __nbcompat_user_from_uid 500 # define uid_from_user __nbcompat_uid_from_user 501 # define pwcache_userdb __nbcompat_pwcache_userdb 502 # define group_from_gid __nbcompat_group_from_gid 503 # define gid_from_group __nbcompat_gid_from_group 504 # define pwcache_groupdb __nbcompat_pwcache_groupdb 505 #endif 506 507 #if !HAVE_DECL_UID_FROM_USER 508 int uid_from_user(const char *, uid_t *); 509 #endif 510 511 #if !HAVE_DECL_USER_FROM_UID 512 const char *user_from_uid(uid_t, int); 513 #endif 514 515 #if !HAVE_DECL_PWCACHE_USERDB 516 int pwcache_userdb(int (*)(int), void (*)(void), 517 struct passwd * (*)(const char *), struct passwd * (*)(uid_t)); 518 #endif 519 520 #if !HAVE_DECL_GID_FROM_GROUP 521 int gid_from_group(const char *, gid_t *); 522 #endif 523 524 #if !HAVE_DECL_GROUP_FROM_GID 525 const char *group_from_gid(gid_t, int); 526 #endif 527 528 #if !HAVE_DECL_PWCACHE_GROUPDB 529 int pwcache_groupdb(int (*)(int), void (*)(void), 530 struct group * (*)(const char *), struct group * (*)(gid_t)); 531 #endif 532 533 #if !HAVE_DECL_SHQUOTE 534 size_t shquote(const char *, char *, size_t); 535 #endif 536 #if !HAVE_DECL_STRLCAT 537 size_t strlcat(char *, const char *, size_t); 538 #endif 539 #if !HAVE_DECL_STRLCPY 540 size_t strlcpy(char *, const char *, size_t); 541 #endif 542 #if !HAVE_DECL_STRNDUP 543 char *strndup(const char *, size_t); 544 #endif 545 #if !HAVE_DECL_STRNLEN 546 size_t strnlen(const char *, size_t); 547 #endif 548 #if !HAVE_DECL_STRCASECMP 549 int strcasecmp(const char *, const char *); 550 #endif 551 #if !HAVE_DECL_STRNCASECMP 552 int strncasecmp(const char *, const char *, size_t); 553 #endif 554 #if !HAVE_DECL_STRCASESTR 555 char *strcasestr(const char *, const char *); 556 #endif 557 #if !HAVE_DECL_LCHFLAGS 558 int lchflags(const char *, unsigned long); 559 #endif 560 #if !HAVE_DECL_LCHMOD 561 int lchmod(const char *, mode_t); 562 #endif 563 #if !HAVE_DECL_LCHOWN 564 int lchown(const char *, uid_t, gid_t); 565 #endif 566 567 #if !HAVE_DECL_PWRITE 568 ssize_t pwrite(int, const void *, size_t, off_t); 569 #endif 570 571 #if !HAVE_RAISE_DEFAULT_SIGNAL 572 int raise_default_signal(int); 573 #endif 574 575 #if !HAVE_DECL_REALLOCARR 576 int reallocarr(void *, size_t, size_t); 577 #endif 578 579 #if !HAVE_DECL_REALLOCARRAY 580 void *reallocarray(void *, size_t, size_t); 581 #endif 582 583 #if !HAVE_DECL_SETENV 584 int setenv(const char *, const char *, int); 585 #endif 586 587 #if !HAVE_DECL_SETGROUPENT 588 int setgroupent(int); 589 #endif 590 591 #if !HAVE_DECL_SETPASSENT 592 int setpassent(int); 593 #endif 594 595 #if !HAVE_DECL_GETPROGNAME 596 const char *getprogname(void); 597 #endif 598 #if !HAVE_DECL_SETPROGNAME 599 void setprogname(const char *); 600 #endif 601 602 #if !HAVE_SNPRINTB_M 603 int snprintb(char *, size_t, const char *, uint64_t); 604 int snprintb_m(char *, size_t, const char *, uint64_t, size_t); 605 #endif 606 607 #if !HAVE_DECL_SNPRINTF && !defined(snprintf) 608 int snprintf(char *, size_t, const char *, ...); 609 #endif 610 611 #if !HAVE_DECL_STRMODE 612 void strmode(mode_t, char *); 613 #endif 614 615 #if !HAVE_DECL_STRNDUP 616 char *strndup(const char *, size_t); 617 #endif 618 619 #if !HAVE_DECL_STRSEP 620 char *strsep(char **, const char *); 621 #endif 622 623 #if !HAVE_DECL_MEMPCPY 624 void *mempcpy(void *, const void *, size_t); 625 #endif 626 627 #if !HAVE_DECL_STRSUFTOLL 628 long long strsuftoll(const char *, const char *, long long, long long); 629 long long strsuftollx(const char *, const char *, 630 long long, long long, char *, size_t); 631 #endif 632 633 #if !HAVE_DECL_STRTOLL 634 long long strtoll(const char *, char **, int); 635 #endif 636 637 #if !HAVE_DECL_STRTONUM 638 long long strtonum(const char *, long long, long long, const char **); 639 #endif 640 641 #if !HAVE_DECL_STRTOI 642 intmax_t strtoi(const char * __restrict, char ** __restrict, int, 643 intmax_t, intmax_t, int *); 644 #endif 645 646 #if !HAVE_DECL_STRTOU 647 uintmax_t strtou(const char * __restrict, char ** __restrict, int, 648 uintmax_t, uintmax_t, int *); 649 #endif 650 651 #if !HAVE_DECL_USER_FROM_UID 652 const char *user_from_uid(uid_t, int); 653 #endif 654 655 #if !HAVE_DECL_GROUP_FROM_GID 656 const char *group_from_gid(gid_t, int); 657 #endif 658 659 #if !HAVE_DECL_VASPRINTF 660 int vasprintf(char **, const char *, va_list); 661 #endif 662 663 #if !HAVE_DECL_VASNPRINTF 664 int vasnprintf(char **, size_t, const char *, va_list); 665 #endif 666 667 #if !HAVE_DECL_VSNPRINTF && !defined(vsnprintf) 668 int vsnprintf(char *, size_t, const char *, va_list); 669 #endif 670 671 #if !HAVE_DECL_VSYSLOG 672 void vsyslog(int, const char *, va_list); 673 #endif 674 675 /* 676 * getmode() and setmode() are always defined, as these function names 677 * exist but with very different meanings on other OS's. The compat 678 * versions here simply accept an octal mode number; the "u+x,g-w" type 679 * of syntax is not accepted. 680 */ 681 682 #define getmode __nbcompat_getmode 683 #define setmode __nbcompat_setmode 684 685 mode_t getmode(const void *, mode_t); 686 void *setmode(const char *); 687 688 /* Eliminate assertions embedded in binaries. */ 689 690 #undef _DIAGASSERT 691 #define _DIAGASSERT(x) 692 693 /* Various sources use this */ 694 #undef __RCSID 695 #define __RCSID(x) struct XXXNETBSD_RCSID 696 #undef __SCCSID 697 #define __SCCSID(x) 698 #undef __COPYRIGHT 699 #define __COPYRIGHT(x) struct XXXNETBSD_COPYRIGHT 700 #undef __KERNEL_RCSID 701 #define __KERNEL_RCSID(x,y) 702 703 /* Heimdal expects this one. */ 704 705 #undef RCSID 706 #define RCSID(x) 707 708 /* Some definitions not available on all systems. */ 709 710 #ifndef __inline 711 #define __inline inline 712 #endif 713 714 /* <errno.h> */ 715 716 #ifndef EFTYPE 717 #define EFTYPE EIO 718 #endif 719 720 /* <fcntl.h> */ 721 722 #ifndef O_EXLOCK 723 #define O_EXLOCK 0 724 #endif 725 #ifndef O_SHLOCK 726 #define O_SHLOCK 0 727 #endif 728 #ifndef O_CLOEXEC 729 #define O_CLOEXEC 0 730 #endif 731 732 /* <inttypes.h> */ 733 734 #if UCHAR_MAX == 0xffU /* char is an 8-bit type */ 735 #ifndef PRId8 736 #define PRId8 "hhd" 737 #endif 738 #ifndef PRIi8 739 #define PRIi8 "hhi" 740 #endif 741 #ifndef PRIo8 742 #define PRIo8 "hho" 743 #endif 744 #ifndef PRIu8 745 #define PRIu8 "hhu" 746 #endif 747 #ifndef PRIx8 748 #define PRIx8 "hhx" 749 #endif 750 #ifndef PRIX8 751 #define PRIX8 "hhX" 752 #endif 753 #ifndef SCNd8 754 #define SCNd8 "hhd" 755 #endif 756 #ifndef SCNi8 757 #define SCNi8 "hhi" 758 #endif 759 #ifndef SCNo8 760 #define SCNo8 "hho" 761 #endif 762 #ifndef SCNu8 763 #define SCNu8 "hhu" 764 #endif 765 #ifndef SCNx8 766 #define SCNx8 "hhx" 767 #endif 768 #ifndef SCNX8 769 #define SCNX8 "hhX" 770 #endif 771 #endif /* char is an 8-bit type */ 772 #if ! (defined(PRId8) && defined(PRIi8) && defined(PRIo8) && \ 773 defined(PRIu8) && defined(PRIx8) && defined(PRIX8)) 774 #error "Don't know how to define PRI[diouxX]8" 775 #endif 776 #if ! (defined(SCNd8) && defined(SCNi8) && defined(SCNo8) && \ 777 defined(SCNu8) && defined(SCNx8) && defined(SCNX8)) 778 #error "Don't know how to define SCN[diouxX]8" 779 #endif 780 781 #if USHRT_MAX == 0xffffU /* short is a 16-bit type */ 782 #ifndef PRId16 783 #define PRId16 "hd" 784 #endif 785 #ifndef PRIi16 786 #define PRIi16 "hi" 787 #endif 788 #ifndef PRIo16 789 #define PRIo16 "ho" 790 #endif 791 #ifndef PRIu16 792 #define PRIu16 "hu" 793 #endif 794 #ifndef PRIx16 795 #define PRIx16 "hx" 796 #endif 797 #ifndef PRIX16 798 #define PRIX16 "hX" 799 #endif 800 #ifndef SCNd16 801 #define SCNd16 "hd" 802 #endif 803 #ifndef SCNi16 804 #define SCNi16 "hi" 805 #endif 806 #ifndef SCNo16 807 #define SCNo16 "ho" 808 #endif 809 #ifndef SCNu16 810 #define SCNu16 "hu" 811 #endif 812 #ifndef SCNx16 813 #define SCNx16 "hx" 814 #endif 815 #ifndef SCNX16 816 #define SCNX16 "hX" 817 #endif 818 #endif /* short is a 16-bit type */ 819 #if ! (defined(PRId16) && defined(PRIi16) && defined(PRIo16) && \ 820 defined(PRIu16) && defined(PRIx16) && defined(PRIX16)) 821 #error "Don't know how to define PRI[diouxX]16" 822 #endif 823 #if ! (defined(SCNd16) && defined(SCNi16) && defined(SCNo16) && \ 824 defined(SCNu16) && defined(SCNx16) && defined(SCNX16)) 825 #error "Don't know how to define SCN[diouxX]16" 826 #endif 827 828 #if UINT_MAX == 0xffffffffU /* int is a 32-bit type */ 829 #ifndef PRId32 830 #define PRId32 "d" 831 #endif 832 #ifndef PRIi32 833 #define PRIi32 "i" 834 #endif 835 #ifndef PRIo32 836 #define PRIo32 "o" 837 #endif 838 #ifndef PRIu32 839 #define PRIu32 "u" 840 #endif 841 #ifndef PRIx32 842 #define PRIx32 "x" 843 #endif 844 #ifndef PRIX32 845 #define PRIX32 "X" 846 #endif 847 #ifndef SCNd32 848 #define SCNd32 "d" 849 #endif 850 #ifndef SCNi32 851 #define SCNi32 "i" 852 #endif 853 #ifndef SCNo32 854 #define SCNo32 "o" 855 #endif 856 #ifndef SCNu32 857 #define SCNu32 "u" 858 #endif 859 #ifndef SCNx32 860 #define SCNx32 "x" 861 #endif 862 #ifndef SCNX32 863 #define SCNX32 "X" 864 #endif 865 #endif /* int is a 32-bit type */ 866 #if ULONG_MAX == 0xffffffffU /* long is a 32-bit type */ 867 #ifndef PRId32 868 #define PRId32 "ld" 869 #endif 870 #ifndef PRIi32 871 #define PRIi32 "li" 872 #endif 873 #ifndef PRIo32 874 #define PRIo32 "lo" 875 #endif 876 #ifndef PRIu32 877 #define PRIu32 "lu" 878 #endif 879 #ifndef PRIx32 880 #define PRIx32 "lx" 881 #endif 882 #ifndef PRIX32 883 #define PRIX32 "lX" 884 #endif 885 #ifndef SCNd32 886 #define SCNd32 "ld" 887 #endif 888 #ifndef SCNi32 889 #define SCNi32 "li" 890 #endif 891 #ifndef SCNo32 892 #define SCNo32 "lo" 893 #endif 894 #ifndef SCNu32 895 #define SCNu32 "lu" 896 #endif 897 #ifndef SCNx32 898 #define SCNx32 "lx" 899 #endif 900 #ifndef SCNX32 901 #define SCNX32 "lX" 902 #endif 903 #endif /* long is a 32-bit type */ 904 #if ! (defined(PRId32) && defined(PRIi32) && defined(PRIo32) && \ 905 defined(PRIu32) && defined(PRIx32) && defined(PRIX32)) 906 #error "Don't know how to define PRI[diouxX]32" 907 #endif 908 #if ! (defined(SCNd32) && defined(SCNi32) && defined(SCNo32) && \ 909 defined(SCNu32) && defined(SCNx32) && defined(SCNX32)) 910 #error "Don't know how to define SCN[diouxX]32" 911 #endif 912 913 #if ULONG_MAX == 0xffffffffffffffffU /* long is a 64-bit type */ 914 #ifndef PRId64 915 #define PRId64 "ld" 916 #endif 917 #ifndef PRIi64 918 #define PRIi64 "li" 919 #endif 920 #ifndef PRIo64 921 #define PRIo64 "lo" 922 #endif 923 #ifndef PRIu64 924 #define PRIu64 "lu" 925 #endif 926 #ifndef PRIx64 927 #define PRIx64 "lx" 928 #endif 929 #ifndef PRIX64 930 #define PRIX64 "lX" 931 #endif 932 #ifndef SCNd64 933 #define SCNd64 "ld" 934 #endif 935 #ifndef SCNi64 936 #define SCNi64 "li" 937 #endif 938 #ifndef SCNo64 939 #define SCNo64 "lo" 940 #endif 941 #ifndef SCNu64 942 #define SCNu64 "lu" 943 #endif 944 #ifndef SCNx64 945 #define SCNx64 "lx" 946 #endif 947 #ifndef SCNX64 948 #define SCNX64 "lX" 949 #endif 950 #endif /* long is a 64-bit type */ 951 #if ULLONG_MAX == 0xffffffffffffffffU /* long long is a 64-bit type */ 952 #ifndef PRId64 953 #define PRId64 "lld" 954 #endif 955 #ifndef PRIi64 956 #define PRIi64 "lli" 957 #endif 958 #ifndef PRIo64 959 #define PRIo64 "llo" 960 #endif 961 #ifndef PRIu64 962 #define PRIu64 "llu" 963 #endif 964 #ifndef PRIx64 965 #define PRIx64 "llx" 966 #endif 967 #ifndef PRIX64 968 #define PRIX64 "llX" 969 #endif 970 #ifndef SCNd64 971 #define SCNd64 "lld" 972 #endif 973 #ifndef SCNi64 974 #define SCNi64 "lli" 975 #endif 976 #ifndef SCNo64 977 #define SCNo64 "llo" 978 #endif 979 #ifndef SCNu64 980 #define SCNu64 "llu" 981 #endif 982 #ifndef SCNx64 983 #define SCNx64 "llx" 984 #endif 985 #ifndef SCNX64 986 #define SCNX64 "llX" 987 #endif 988 #endif /* long long is a 64-bit type */ 989 #if ! (defined(PRId64) && defined(PRIi64) && defined(PRIo64) && \ 990 defined(PRIu64) && defined(PRIx64) && defined(PRIX64)) 991 #error "Don't know how to define PRI[diouxX]64" 992 #endif 993 #if ! (defined(SCNd64) && defined(SCNi64) && defined(SCNo64) && \ 994 defined(SCNu64) && defined(SCNx64) && defined(SCNX64)) 995 #error "Don't know how to define SCN[diouxX]64" 996 #endif 997 998 /* <limits.h> */ 999 1000 #ifndef UID_MAX 1001 #define UID_MAX 32767 1002 #endif 1003 #ifndef GID_MAX 1004 #define GID_MAX UID_MAX 1005 #endif 1006 1007 #ifndef UQUAD_MAX 1008 #define UQUAD_MAX ((u_quad_t)-1) 1009 #endif 1010 #ifndef QUAD_MAX 1011 #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1)) 1012 #endif 1013 #ifndef QUAD_MIN 1014 #define QUAD_MIN ((quad_t)(~QUAD_MAX)) 1015 #endif 1016 #ifndef ULLONG_MAX 1017 #define ULLONG_MAX ((unsigned long long)-1) 1018 #endif 1019 #ifndef LLONG_MAX 1020 #define LLONG_MAX ((long long)(ULLONG_MAX >> 1)) 1021 #endif 1022 #ifndef LLONG_MIN 1023 #define LLONG_MIN ((long long)(~LLONG_MAX)) 1024 #endif 1025 1026 #ifndef MAXPATHLEN 1027 #define MAXPATHLEN 4096 1028 #endif 1029 1030 #ifndef NAME_MAX 1031 #ifdef _XOPEN_NAME_MAX 1032 #define NAME_MAX _XOPEN_NAME_MAX 1033 #else 1034 #error "Both NAME_MAX and _XOPEN_NAME_MAX are not defined" 1035 #endif 1036 #endif 1037 1038 #ifndef PATH_MAX 1039 #define PATH_MAX MAXPATHLEN 1040 #endif 1041 1042 /* <paths.h> */ 1043 1044 /* The host's _PATH_BSHELL might be broken, so override it. */ 1045 #undef _PATH_BSHELL 1046 #define _PATH_BSHELL PATH_BSHELL 1047 #ifndef _PATH_DEFPATH 1048 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin" 1049 #endif 1050 #ifndef _PATH_DEV 1051 #define _PATH_DEV "/dev/" 1052 #endif 1053 #ifndef _PATH_DEVNULL 1054 #define _PATH_DEVNULL _PATH_DEV "null" 1055 #endif 1056 #ifndef _PATH_TMP 1057 #define _PATH_TMP "/tmp/" 1058 #endif 1059 #ifndef _PATH_DEFTAPE 1060 #define _PATH_DEFTAPE "/dev/nrst0" 1061 #endif 1062 #ifndef _PATH_VI 1063 #define _PATH_VI "/usr/bin/vi" 1064 #endif 1065 1066 /* <stdint.h> */ 1067 1068 #if !defined(SIZE_MAX) && defined(SIZE_T_MAX) 1069 #define SIZE_MAX SIZE_T_MAX 1070 #endif 1071 1072 #ifndef UINT8_MAX 1073 #define UINT8_MAX 0xffU 1074 #endif 1075 1076 #ifndef UINT16_MAX 1077 #define UINT16_MAX 0xffffU 1078 #endif 1079 1080 #ifndef UINT32_MAX 1081 #define UINT32_MAX 0xffffffffU 1082 #endif 1083 1084 /* <stdlib.h> */ 1085 1086 #ifndef __GNUC__ 1087 # if HAVE_ALLOCA_H 1088 # include <alloca.h> 1089 # else 1090 # ifndef alloca /* predefined by HP cc +Olibcalls */ 1091 char *alloca (); 1092 # endif 1093 # endif 1094 #endif 1095 1096 /* avoid prototype conflicts with host */ 1097 #define cgetcap __nbcompat_cgetcap 1098 #define cgetclose __nbcompat_cgetclose 1099 #define cgetent __nbcompat_cgetent 1100 #define cgetfirst __nbcompat_cgetfirst 1101 #define cgetmatch __nbcompat_cgetmatch 1102 #define cgetnext __nbcompat_cgetnext 1103 #define cgetnum __nbcompat_cgetnum 1104 #define cgetset __nbcompat_cgetset 1105 #define cgetstr __nbcompat_cgetstr 1106 #define cgetustr __nbcompat_cgetustr 1107 1108 char *cgetcap(char *, const char *, int); 1109 int cgetclose(void); 1110 int cgetent(char **, const char * const *, const char *); 1111 int cgetfirst(char **, const char * const *); 1112 int cgetmatch(const char *, const char *); 1113 int cgetnext(char **, const char * const *); 1114 int cgetnum(char *, const char *, long *); 1115 int cgetset(const char *); 1116 int cgetstr(char *, const char *, char **); 1117 int cgetustr(char *, const char *, char **); 1118 1119 1120 #ifdef HAVE_SYS_ENDIAN_H 1121 #include <sys/endian.h> 1122 #elif defined(HAVE_ENDIAN_H) 1123 #include <endian.h> 1124 #endif 1125 1126 #if WORDS_BIGENDIAN 1127 #if !HAVE_DECL_HTOBE16 && !defined(htobe16) 1128 #define htobe16(x) (x) 1129 #endif 1130 #if !HAVE_DECL_HTOBE32 && !defined(htobe32) 1131 #define htobe32(x) (x) 1132 #endif 1133 #if !HAVE_DECL_HTOBE64 && !defined(htobe64) 1134 #define htobe64(x) (x) 1135 #endif 1136 #if !HAVE_DECL_HTOLE16 && !defined(htole16) 1137 #define htole16(x) bswap16((u_int16_t)(x)) 1138 #endif 1139 #if !HAVE_DECL_HTOLE32 && !defined(htole32) 1140 #define htole32(x) bswap32((u_int32_t)(x)) 1141 #endif 1142 #if !HAVE_DECL_HTOLE64 && !defined(htole64) 1143 #define htole64(x) bswap64((u_int64_t)(x)) 1144 #endif 1145 #else 1146 #if !HAVE_DECL_HTOBE16 && !defined(htobe16) 1147 #define htobe16(x) bswap16((u_int16_t)(x)) 1148 #endif 1149 #if !HAVE_DECL_HTOBE32 && !defined(htobe32) 1150 #define htobe32(x) bswap32((u_int32_t)(x)) 1151 #endif 1152 #if !HAVE_DECL_HTOBE64 && !defined(htobe64) 1153 #define htobe64(x) bswap64((u_int64_t)(x)) 1154 #endif 1155 #if !HAVE_DECL_HTOLE16 && !defined(htole16) 1156 #define htole16(x) (x) 1157 #endif 1158 #if !HAVE_DECL_HTOLE32 && !defined(htole32) 1159 #define htole32(x) (x) 1160 #endif 1161 #if !HAVE_DECL_HTOLE64 && !defined(htole64) 1162 #define htole64(x) (x) 1163 #endif 1164 #endif 1165 #if !HAVE_DECL_BE16TOH && !defined(be16toh) 1166 #define be16toh(x) htobe16(x) 1167 #endif 1168 #if !HAVE_DECL_BE32TOH && !defined(be32toh) 1169 #define be32toh(x) htobe32(x) 1170 #endif 1171 #if !HAVE_DECL_BE64TOH && !defined(be64toh) 1172 #define be64toh(x) htobe64(x) 1173 #endif 1174 #if !HAVE_DECL_LE16TOH && !defined(le16toh) 1175 #define le16toh(x) htole16(x) 1176 #endif 1177 #if !HAVE_DECL_LE32TOH && !defined(le32toh) 1178 #define le32toh(x) htole32(x) 1179 #endif 1180 #if !HAVE_DECL_LE64TOH && !defined(le64toh) 1181 #define le64toh(x) htole64(x) 1182 #endif 1183 1184 #define __GEN_ENDIAN_ENC(bits, endian) \ 1185 static void \ 1186 endian ## bits ## enc(void *dst, uint ## bits ## _t u) \ 1187 { \ 1188 u = hto ## endian ## bits (u); \ 1189 memcpy(dst, &u, sizeof(u)); \ 1190 } 1191 #if !HAVE_DECL_BE16ENC 1192 __GEN_ENDIAN_ENC(16, be) 1193 #endif 1194 #if !HAVE_DECL_BE32ENC 1195 __GEN_ENDIAN_ENC(32, be) 1196 #endif 1197 #if !HAVE_DECL_BE64ENC 1198 __GEN_ENDIAN_ENC(64, be) 1199 #endif 1200 #if !HAVE_DECL_LE16ENC 1201 __GEN_ENDIAN_ENC(16, le) 1202 #endif 1203 #if !HAVE_DECL_LE32ENC 1204 __GEN_ENDIAN_ENC(32, le) 1205 #endif 1206 #if !HAVE_DECL_LE64ENC 1207 __GEN_ENDIAN_ENC(64, le) 1208 #endif 1209 #undef __GEN_ENDIAN_ENC 1210 1211 #define __GEN_ENDIAN_DEC(bits, endian) \ 1212 static uint ## bits ## _t \ 1213 endian ## bits ## dec(const void *buf) \ 1214 { \ 1215 uint ## bits ## _t u; \ 1216 memcpy(&u, buf, sizeof(u)); \ 1217 return endian ## bits ## toh (u); \ 1218 } 1219 #if !HAVE_DECL_BE16DEC 1220 __GEN_ENDIAN_DEC(16, be) 1221 #endif 1222 #if !HAVE_DECL_BE32DEC 1223 __GEN_ENDIAN_DEC(32, be) 1224 #endif 1225 #if !HAVE_DECL_BE64DEC 1226 __GEN_ENDIAN_DEC(64, be) 1227 #endif 1228 #if !HAVE_DECL_LE16DEC 1229 __GEN_ENDIAN_DEC(16, le) 1230 #endif 1231 #if !HAVE_DECL_LE32DEC 1232 __GEN_ENDIAN_DEC(32, le) 1233 #endif 1234 #if !HAVE_DECL_LE64DEC 1235 __GEN_ENDIAN_DEC(64, le) 1236 #endif 1237 #undef __GEN_ENDIAN_DEC 1238 1239 /* <sys/mman.h> */ 1240 1241 #ifndef MAP_FILE 1242 #define MAP_FILE 0 1243 #endif 1244 1245 /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */ 1246 #ifndef MAP_ANON 1247 #ifdef MAP_ANONYMOUS 1248 #define MAP_ANON MAP_ANONYMOUS 1249 #endif 1250 #endif 1251 1252 /* <sys/param.h> */ 1253 1254 #undef BIG_ENDIAN 1255 #undef LITTLE_ENDIAN 1256 #undef PDP_ENDIAN 1257 #define BIG_ENDIAN 4321 1258 #define LITTLE_ENDIAN 1234 1259 #define PDP_ENDIAN 3412 1260 1261 #undef BYTE_ORDER 1262 #if WORDS_BIGENDIAN 1263 #define BYTE_ORDER BIG_ENDIAN 1264 #else 1265 #define BYTE_ORDER LITTLE_ENDIAN 1266 #endif 1267 1268 /* all references of DEV_BSIZE in tools are for NetBSD's file images */ 1269 #undef DEV_BSIZE 1270 #define DEV_BSIZE (1 << 9) 1271 1272 #undef MIN 1273 #undef MAX 1274 #define MIN(a,b) ((a) < (b) ? (a) : (b)) 1275 #define MAX(a,b) ((a) > (b) ? (a) : (b)) 1276 1277 #ifndef MAXBSIZE 1278 #define MAXBSIZE (64 * 1024) 1279 #endif 1280 #ifndef MAXFRAG 1281 #define MAXFRAG 8 1282 #endif 1283 #ifndef MAXPHYS 1284 #define MAXPHYS (64 * 1024) 1285 #endif 1286 #ifndef MAXHOSTNAMELEN 1287 #define MAXHOSTNAMELEN 256 1288 #endif 1289 1290 /* XXX needed by makefs; this should be done in a better way */ 1291 #undef btodb 1292 #define btodb(x) ((x) << 9) 1293 1294 #undef setbit 1295 #undef clrbit 1296 #undef isset 1297 #undef isclr 1298 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY)) 1299 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) 1300 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY))) 1301 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) 1302 1303 #ifndef powerof2 1304 #define powerof2(x) ((((x)-1)&(x))==0) 1305 #endif 1306 1307 #undef roundup 1308 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) 1309 1310 #undef roundup2 1311 #define roundup2(x, m) ((((x) - 1) | ((m) - 1)) + 1) 1312 1313 /* <sys/stat.h> */ 1314 1315 #ifndef ALLPERMS 1316 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) 1317 #endif 1318 #ifndef DEFFILEMODE 1319 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 1320 #endif 1321 #ifndef S_ISTXT 1322 #ifdef S_ISVTX 1323 #define S_ISTXT S_ISVTX 1324 #else 1325 #define S_ISTXT 0 1326 #endif 1327 #endif 1328 1329 /* Protected by _NETBSD_SOURCE otherwise. */ 1330 #if HAVE_STRUCT_STAT_ST_FLAGS && defined(__NetBSD__) 1331 #define UF_SETTABLE 0x0000ffff 1332 #define UF_NODUMP 0x00000001 1333 #define UF_IMMUTABLE 0x00000002 1334 #define UF_APPEND 0x00000004 1335 #define UF_OPAQUE 0x00000008 1336 #define SF_SETTABLE 0xffff0000 1337 #define SF_ARCHIVED 0x00010000 1338 #define SF_IMMUTABLE 0x00020000 1339 #define SF_APPEND 0x00040000 1340 #endif 1341 1342 /* <sys/syslimits.h> */ 1343 1344 #ifndef LINE_MAX 1345 #define LINE_MAX 2048 1346 #endif 1347 1348 /* <sys/time.h> */ 1349 1350 #ifndef timercmp 1351 #define timercmp(tvp, uvp, cmp) \ 1352 (((tvp)->tv_sec == (uvp)->tv_sec) ? \ 1353 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ 1354 ((tvp)->tv_sec cmp (uvp)->tv_sec)) 1355 #endif 1356 #ifndef timeradd 1357 #define timeradd(tvp, uvp, vvp) \ 1358 do { \ 1359 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ 1360 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ 1361 if ((vvp)->tv_usec >= 1000000) { \ 1362 (vvp)->tv_sec++; \ 1363 (vvp)->tv_usec -= 1000000; \ 1364 } \ 1365 } while (/* CONSTCOND */ 0) 1366 #endif 1367 #ifndef timersub 1368 #define timersub(tvp, uvp, vvp) \ 1369 do { \ 1370 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ 1371 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ 1372 if ((vvp)->tv_usec < 0) { \ 1373 (vvp)->tv_sec--; \ 1374 (vvp)->tv_usec += 1000000; \ 1375 } \ 1376 } while (/* CONSTCOND */ 0) 1377 #endif 1378 1379 /* <sys/types.h> */ 1380 1381 #ifdef major 1382 #undef major 1383 #endif 1384 #define major(x) ((int32_t)((((x) & 0x000fff00) >> 8))) 1385 1386 #ifdef minor 1387 #undef minor 1388 #endif 1389 #define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \ 1390 (((x) & 0x000000ff) >> 0))) 1391 #ifdef makedev 1392 #undef makedev 1393 #endif 1394 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \ 1395 (((y) << 12) & 0xfff00000) | \ 1396 (((y) << 0) & 0x000000ff))) 1397 #ifndef NBBY 1398 #define NBBY 8 1399 #endif 1400 1401 #if !HAVE_U_QUAD_T 1402 /* #define, not typedef, as quad_t exists as a struct on some systems */ 1403 #define quad_t long long 1404 #define u_quad_t unsigned long long 1405 #define strtoq strtoll 1406 #define strtouq strtoull 1407 #endif 1408 1409 /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */ 1410 #ifdef __NetBSD__ 1411 quad_t strtoq(const char *, char **, int); 1412 u_quad_t strtouq(const char *, char **, int); 1413 #endif 1414 1415 #endif /* !__NETBSD_COMPAT_DEFS_H__ */ 1416