1 /* $NetBSD: compat_defs.h,v 1.103 2015/09/21 21:50:16 pooka Exp $ */
3 #ifndef __NETBSD_COMPAT_DEFS_H__
4 #define __NETBSD_COMPAT_DEFS_H__
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
14 #define _ISOC99_SOURCE
15 #define _POSIX_SOURCE 1
16 #define _POSIX_C_SOURCE 200112L
17 #define _XOPEN_SOURCE 600
18 #endif /* __NetBSD__ */
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.
26 #if defined(__linux__) && HAVE_FEATURES_H
29 #undef _POSIX_C_SOURCE
30 #define __USE_ISOC99 1
31 #endif /* __linux__ && HAVE_FEATURES_H */
33 /* System headers needed for (re)definitions below. */
35 #include <sys/types.h>
37 #include <sys/param.h>
38 /* time.h needs to be pulled in first at least on netbsd w/o _NETBSD_SOURCE */
51 #include <sys/cdefs.h>
53 #if HAVE_SYS_SYSLIMITS_H
54 #include <sys/syslimits.h>
56 #if HAVE_SYS_SYSMACROS_H
57 /* major(), minor() on SVR4 */
58 #include <sys/sysmacros.h>
68 #include <rpc/types.h>
72 #error _NETBSD_SOURCE is *not* to be defined.
75 /* Need this since we can't depend on NetBSD's version to be around */
79 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
83 #define __UNVOLATILE(a) ((void *)(unsigned long)(volatile void *)(a))
86 #undef __predict_false
87 #define __predict_false(x) (x)
89 #define __predict_true(x) (x)
91 /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
94 /* We don't include <grp.h> either */
97 /* Assume an ANSI compiler for the host. */
102 #ifndef __BEGIN_DECLS
103 #define __BEGIN_DECLS
109 /* Some things in NetBSD <sys/cdefs.h>. */
112 #define __CONCAT(x,y) x ## y
114 #if !defined(__attribute__) && !defined(__GNUC__)
115 #define __attribute__(x)
117 #if !defined(__packed)
118 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
119 #define __packed __attribute__((__packed__))
120 #elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
121 #define __packed __attribute__((__packed__))
123 #define __packed error: no __packed for this compiler
125 #endif /* !__packed */
134 #define __printflike(x,y)
136 #define __format_arg(x)
142 #define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
144 #define __USE(a) ((void)(a))
146 #define __type_min_s(t) ((t)((1ULL << (sizeof(t) * NBBY - 1))))
148 #define __type_max_s(t) ((t)~((1ULL << (sizeof(t) * NBBY - 1))))
150 #define __type_min_u(t) ((t)0ULL)
152 #define __type_max_u(t) ((t)~0ULL)
153 #undef __type_is_signed
154 #define __type_is_signed(t) (/*LINTED*/__type_min_s(t) + (t)1 < (t)1)
156 #define __type_min(t) (__type_is_signed(t) ? __type_min_s(t) : __type_min_u(t))
158 #define __type_max(t) (__type_is_signed(t) ? __type_max_s(t) : __type_max_u(t))
160 /* Dirent support. */
163 # if defined(__linux__) && defined(__USE_BSD)
170 # if defined(__DARWIN_UNIX03)
174 # define NAMLEN(dirent) (strlen((dirent)->d_name))
176 # define dirent direct
177 # define NAMLEN(dirent) ((dirent)->d_namlen)
179 # include <sys/ndir.h>
182 # include <sys/dir.h>
189 /* Type substitutes. */
192 typedef unsigned int id_t
;
197 * This is defined as int for compatibility with legacy systems (and not
198 * unsigned int), since universally it was int in most systems that did not
201 typedef int socklen_t
;
205 typedef unsigned long u_long
;
209 typedef unsigned char u_char
;
213 typedef unsigned int u_int
;
217 typedef unsigned short u_short
;
220 /* Prototypes for replacement functions. */
223 long long int atoll(const char *);
227 int asprintf(char **, const char *, ...);
231 int asnprintf(char **, size_t, const char *, ...);
235 char *basename(char *);
238 #if !HAVE_DECL_OPTIND
239 int getopt(int, char *const *, const char *);
241 extern int optind
, opterr
, optopt
;
245 char *dirname(char *);
250 #define dirfd(dirp) ((dirp)->dd_fd)
251 #elif HAVE_DIR___DD_FD
252 #define dirfd(dirp) ((dirp)->__dd_fd)
254 /*XXX: Very hacky but no other way to bring this into scope w/o defining
255 _NETBSD_SOURCE which we're avoiding. */
256 #if defined(__NetBSD__) || defined(__minix)
258 int dd_fd
; /* file descriptor associated with directory */
259 long dd_loc
; /* offset in current buffer */
260 long dd_size
; /* amount of data returned by getdents */
261 char *dd_buf
; /* data buffer */
262 int dd_len
; /* size of data buffer */
263 off_t dd_seek
; /* magic cookie returned by getdents */
264 long dd_rewind
; /* magic cookie for rewinding */
265 int dd_flags
; /* flags for readdir */
266 void *dd_lock
; /* lock for concurrent access */
268 #define dirfd(dirp) (((struct _dirdesc *)dirp)->dd_fd)
270 #error cannot figure out how to turn a DIR * into a fd
276 void err(int, const char *, ...);
277 void errx(int, const char *, ...);
278 void warn(const char *, ...);
279 void warnx(const char *, ...);
280 void vwarnx(const char *, va_list);
283 void warnc(int, const char *, ...);
285 #if !HAVE_DECL_VWARNC
286 void vwarnc(int, const char *, va_list);
289 void errc(int, int, const char *, ...);
292 void verrc(int, int, const char *, va_list);
296 void (*esetfunc(void (*)(int, const char *, ...)))(int, const char *, ...);
297 size_t estrlcpy(char *, const char *, size_t);
298 size_t estrlcat(char *, const char *, size_t);
299 char *estrdup(const char *);
300 char *estrndup(const char *, size_t);
301 void *ecalloc(size_t, size_t);
302 void *emalloc(size_t);
303 void *erealloc(void *, size_t);
304 FILE *efopen(const char *, const char *);
305 int easprintf(char **, const char *, ...);
306 int evasprintf(char **, const char *, va_list);
309 #if !HAVE_FGETLN || defined(__NetBSD__) || defined(__minix)
310 char *fgetln(FILE *, size_t *);
313 int dprintf(int, const char *, ...);
317 # define LOCK_SH 0x01
318 # define LOCK_EX 0x02
319 # define LOCK_NB 0x04
320 # define LOCK_UN 0x08
324 #if !HAVE_FPARSELN || BROKEN_FPARSELN || defined(__NetBSD__) || defined(__minix)
325 # define FPARSELN_UNESCESC 0x01
326 # define FPARSELN_UNESCCONT 0x02
327 # define FPARSELN_UNESCCOMM 0x04
328 # define FPARSELN_UNESCREST 0x08
329 # define FPARSELN_UNESCALL 0x0f
330 char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
334 ssize_t
getdelim(char **, size_t *, int, FILE *);
335 ssize_t
getline(char **, size_t *, FILE *);
342 #if !HAVE_ISBLANK && !defined(isblank)
343 #define isblank(x) ((x) == ' ' || (x) == '\t')
346 #define __nbcompat_bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
348 #define __nbcompat_bswap32(x) ((((x) << 24) & 0xff000000) | \
349 (((x) << 8) & 0x00ff0000) | \
350 (((x) >> 8) & 0x0000ff00) | \
351 (((x) >> 24) & 0x000000ff))
353 #define __nbcompat_bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \
354 ((u_int64_t)bswap32((x) >> 32)))
356 #if ! HAVE_DECL_BSWAP16
360 #define bswap16(x) __nbcompat_bswap16(x)
362 #if ! HAVE_DECL_BSWAP32
366 #define bswap32(x) __nbcompat_bswap32(x)
368 #if ! HAVE_DECL_BSWAP64
372 #define bswap64(x) __nbcompat_bswap64(x)
380 char *mkdtemp(char *);
383 #if !HAVE_MKSTEMP || !HAVE_MKDTEMP
384 /* This is a prototype for the internal function defined in
385 * src/lib/lib/stdio/gettemp.c */
386 int __nbcompat_gettemp(char *, int *, int);
390 ssize_t
pread(int, void *, size_t, off_t
);
394 int heapsort (void *, size_t, size_t, int (*)(const void *, const void *));
396 /* Make them use our version */
397 # define heapsort __nbcompat_heapsort
399 char *flags_to_string(unsigned long, const char *);
400 int string_to_flags(char **, unsigned long *, unsigned long *);
403 * HAVE_X_FROM_Y and HAVE_PWCACHE_FOODB go together, because we cannot
404 * supply an implementation of one without the others -- some parts are
405 * libc internal and this varies from system to system.
407 * XXX this is dubious anyway: we assume (see HAVE_DECLs below) that if the
408 * XXX host system has all of these functions, all of their interfaces
409 * XXX and interactions are exactly the same as in our libc/libutil -- ugh.
411 #if !HAVE_USER_FROM_UID || !HAVE_UID_FROM_USER || !HAVE_GROUP_FROM_GID || \
412 !HAVE_GID_FROM_GROUP || !HAVE_PWCACHE_USERDB || !HAVE_PWCACHE_GROUDB
413 /* Make them use our version */
414 # define user_from_uid __nbcompat_user_from_uid
415 # define uid_from_user __nbcompat_uid_from_user
416 # define pwcache_userdb __nbcompat_pwcache_userdb
417 # define group_from_gid __nbcompat_group_from_gid
418 # define gid_from_group __nbcompat_gid_from_group
419 # define pwcache_groupdb __nbcompat_pwcache_groupdb
422 #if !HAVE_DECL_UID_FROM_USER
423 int uid_from_user(const char *, uid_t
*);
426 #if !HAVE_DECL_USER_FROM_UID
427 const char *user_from_uid(uid_t
, int);
430 #if !HAVE_DECL_PWCACHE_USERDB
431 int pwcache_userdb(int (*)(int), void (*)(void),
432 struct passwd
* (*)(const char *), struct passwd
* (*)(uid_t
));
435 #if !HAVE_DECL_GID_FROM_GROUP
436 int gid_from_group(const char *, gid_t
*);
439 #if !HAVE_DECL_GROUP_FROM_GID
440 const char *group_from_gid(gid_t
, int);
443 #if !HAVE_DECL_PWCACHE_GROUPDB
444 int pwcache_groupdb(int (*)(int), void (*)(void),
445 struct group
* (*)(const char *), struct group
* (*)(gid_t
));
448 #if !HAVE_DECL_STRNDUP
449 char *strndup(const char *, size_t);
451 #if !HAVE_DECL_STRNLEN
452 size_t strnlen(const char *, size_t);
454 #if !HAVE_DECL_LCHFLAGS
455 int lchflags(const char *, unsigned long);
457 #if !HAVE_DECL_LCHMOD
458 int lchmod(const char *, mode_t
);
460 #if !HAVE_DECL_LCHOWN
461 int lchown(const char *, uid_t
, gid_t
);
465 ssize_t
pwrite(int, const void *, size_t, off_t
);
468 #if !HAVE_RAISE_DEFAULT_SIGNAL
469 int raise_default_signal(int);
473 int reallocarr(void *, size_t, size_t);
477 int setenv(const char *, const char *, int);
480 #if !HAVE_DECL_SETGROUPENT
481 int setgroupent(int);
484 #if !HAVE_DECL_SETPASSENT
488 #if !HAVE_SETPROGNAME || defined(__NetBSD__) || defined(__minix)
489 const char *getprogname(void);
490 void setprogname(const char *);
494 int snprintb(char *, size_t, const char *, uint64_t);
495 int snprintb_m(char *, size_t, const char *, uint64_t, size_t);
499 int snprintf(char *, size_t, const char *, ...);
503 size_t strlcat(char *, const char *, size_t);
507 size_t strlcpy(char *, const char *, size_t);
511 void strmode(mode_t
, char *);
515 char *strndup(const char *, size_t);
518 #if !HAVE_STRSEP || defined(__NetBSD__) || defined(__minix)
519 char *strsep(char **, const char *);
522 #if !HAVE_DECL_STRSUFTOLL
523 long long strsuftoll(const char *, const char *, long long, long long);
524 long long strsuftollx(const char *, const char *,
525 long long, long long, char *, size_t);
529 long long strtoll(const char *, char **, int);
533 intmax_t strtoi(const char * __restrict
, char ** __restrict
, int,
534 intmax_t, intmax_t, int *);
538 uintmax_t strtou(const char * __restrict
, char ** __restrict
, int,
539 uintmax_t, uintmax_t, int *);
542 #if !HAVE_USER_FROM_UID
543 const char *user_from_uid(uid_t
, int);
546 #if !HAVE_GROUP_FROM_GID
547 const char *group_from_gid(gid_t
, int);
551 int vasprintf(char **, const char *, va_list);
555 int vasnprintf(char **, size_t, const char *, va_list);
559 int vsnprintf(char *, size_t, const char *, va_list);
563 * getmode() and setmode() are always defined, as these function names
564 * exist but with very different meanings on other OS's. The compat
565 * versions here simply accept an octal mode number; the "u+x,g-w" type
566 * of syntax is not accepted.
569 #define getmode __nbcompat_getmode
570 #define setmode __nbcompat_setmode
572 mode_t
getmode(const void *, mode_t
);
573 void *setmode(const char *);
575 /* Eliminate assertions embedded in binaries. */
578 #define _DIAGASSERT(x)
580 /* Various sources use this */
582 #define __RCSID(x) struct XXXNETBSD_RCSID
586 #define __COPYRIGHT(x) struct XXXNETBSD_COPYRIGHT
587 #undef __KERNEL_RCSID
588 #define __KERNEL_RCSID(x,y)
590 /* Heimdal expects this one. */
595 /* Some definitions not available on all systems. */
598 #define __inline inline
621 #if UCHAR_MAX == 0xffU /* char is an 8-bit type */
658 #endif /* char is an 8-bit type */
659 #if ! (defined(PRId8) && defined(PRIi8) && defined(PRIo8) && \
660 defined(PRIu8) && defined(PRIx8) && defined(PRIX8))
661 #error "Don't know how to define PRI[diouxX]8"
663 #if ! (defined(SCNd8) && defined(SCNi8) && defined(SCNo8) && \
664 defined(SCNu8) && defined(SCNx8) && defined(SCNX8))
665 #error "Don't know how to define SCN[diouxX]8"
668 #if USHRT_MAX == 0xffffU /* short is a 16-bit type */
705 #endif /* short is a 16-bit type */
706 #if ! (defined(PRId16) && defined(PRIi16) && defined(PRIo16) && \
707 defined(PRIu16) && defined(PRIx16) && defined(PRIX16))
708 #error "Don't know how to define PRI[diouxX]16"
710 #if ! (defined(SCNd16) && defined(SCNi16) && defined(SCNo16) && \
711 defined(SCNu16) && defined(SCNx16) && defined(SCNX16))
712 #error "Don't know how to define SCN[diouxX]16"
715 #if UINT_MAX == 0xffffffffU /* int is a 32-bit type */
752 #endif /* int is a 32-bit type */
753 #if ULONG_MAX == 0xffffffffU /* long is a 32-bit type */
790 #endif /* long is a 32-bit type */
791 #if ! (defined(PRId32) && defined(PRIi32) && defined(PRIo32) && \
792 defined(PRIu32) && defined(PRIx32) && defined(PRIX32))
793 #error "Don't know how to define PRI[diouxX]32"
795 #if ! (defined(SCNd32) && defined(SCNi32) && defined(SCNo32) && \
796 defined(SCNu32) && defined(SCNx32) && defined(SCNX32))
797 #error "Don't know how to define SCN[diouxX]32"
800 #if ULONG_MAX == 0xffffffffffffffffU /* long is a 64-bit type */
837 #endif /* long is a 64-bit type */
838 #if ULLONG_MAX == 0xffffffffffffffffU /* long long is a 64-bit type */
875 #endif /* long long is a 64-bit type */
876 #if ! (defined(PRId64) && defined(PRIi64) && defined(PRIo64) && \
877 defined(PRIu64) && defined(PRIx64) && defined(PRIX64))
878 #error "Don't know how to define PRI[diouxX]64"
880 #if ! (defined(SCNd64) && defined(SCNi64) && defined(SCNo64) && \
881 defined(SCNu64) && defined(SCNx64) && defined(SCNX64))
882 #error "Don't know how to define SCN[diouxX]64"
888 #define UID_MAX 32767
891 #define GID_MAX UID_MAX
895 #define UQUAD_MAX ((u_quad_t)-1)
898 #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
901 #define QUAD_MIN ((quad_t)(~QUAD_MAX))
904 #define ULLONG_MAX ((unsigned long long)-1)
907 #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
910 #define LLONG_MIN ((long long)(~LLONG_MAX))
914 #define MAXPATHLEN 4096
917 #define PATH_MAX MAXPATHLEN
922 /* The host's _PATH_BSHELL might be broken, so override it. */
924 #define _PATH_BSHELL PATH_BSHELL
925 #ifndef _PATH_DEFPATH
926 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
929 #define _PATH_DEV "/dev/"
931 #ifndef _PATH_DEVNULL
932 #define _PATH_DEVNULL _PATH_DEV "null"
935 #define _PATH_TMP "/tmp/"
937 #ifndef _PATH_DEFTAPE
938 #define _PATH_DEFTAPE "/dev/nrst0"
941 #define _PATH_VI "/usr/bin/vi"
946 #if !defined(SIZE_MAX) && defined(SIZE_T_MAX)
947 #define SIZE_MAX SIZE_T_MAX
951 #define UINT8_MAX 0xffU
955 #define UINT16_MAX 0xffffU
959 #define UINT32_MAX 0xffffffffU
968 # ifndef alloca /* predefined by HP cc +Olibcalls */
974 /* avoid prototype conflicts with host */
975 #define cgetcap __nbcompat_cgetcap
976 #define cgetclose __nbcompat_cgetclose
977 #define cgetent __nbcompat_cgetent
978 #define cgetfirst __nbcompat_cgetfirst
979 #define cgetmatch __nbcompat_cgetmatch
980 #define cgetnext __nbcompat_cgetnext
981 #define cgetnum __nbcompat_cgetnum
982 #define cgetset __nbcompat_cgetset
983 #define cgetstr __nbcompat_cgetstr
984 #define cgetustr __nbcompat_cgetustr
986 char *cgetcap(char *, const char *, int);
988 int cgetent(char **, const char * const *, const char *);
989 int cgetfirst(char **, const char * const *);
990 int cgetmatch(const char *, const char *);
991 int cgetnext(char **, const char * const *);
992 int cgetnum(char *, const char *, long *);
993 int cgetset(const char *);
994 int cgetstr(char *, const char *, char **);
995 int cgetustr(char *, const char *, char **);
1000 #if !HAVE_DECL_HTOBE16
1001 #define htobe16(x) (x)
1003 #if !HAVE_DECL_HTOBE32
1004 #define htobe32(x) (x)
1006 #if !HAVE_DECL_HTOBE64
1007 #define htobe64(x) (x)
1009 #if !HAVE_DECL_HTOLE16
1010 #define htole16(x) bswap16((u_int16_t)(x))
1012 #if !HAVE_DECL_HTOLE32
1013 #define htole32(x) bswap32((u_int32_t)(x))
1015 #if !HAVE_DECL_HTOLE64
1016 #define htole64(x) bswap64((u_int64_t)(x))
1019 #if !HAVE_DECL_HTOBE16
1020 #define htobe16(x) bswap16((u_int16_t)(x))
1022 #if !HAVE_DECL_HTOBE32
1023 #define htobe32(x) bswap32((u_int32_t)(x))
1025 #if !HAVE_DECL_HTOBE64
1026 #define htobe64(x) bswap64((u_int64_t)(x))
1028 #if !HAVE_DECL_HTOLE16
1029 #define htole16(x) (x)
1031 #if !HAVE_DECL_HTOLE32
1032 #define htole32(x) (x)
1034 #if !HAVE_DECL_HTOLE64
1035 #define htole64(x) (x)
1038 #if !HAVE_DECL_BE16TOH
1039 #define be16toh(x) htobe16(x)
1041 #if !HAVE_DECL_BE32TOH
1042 #define be32toh(x) htobe32(x)
1044 #if !HAVE_DECL_BE64TOH
1045 #define be64toh(x) htobe64(x)
1047 #if !HAVE_DECL_LE16TOH
1048 #define le16toh(x) htole16(x)
1050 #if !HAVE_DECL_LE32TOH
1051 #define le32toh(x) htole32(x)
1053 #if !HAVE_DECL_LE64TOH
1054 #define le64toh(x) htole64(x)
1057 #define __GEN_ENDIAN_ENC(bits, endian) \
1059 endian ## bits ## enc(void *dst, uint ## bits ## _t u) \
1061 u = hto ## endian ## bits (u); \
1062 memcpy(dst, &u, sizeof(u)); \
1064 #if !HAVE_DECL_BE16ENC
1065 __GEN_ENDIAN_ENC(16, be
)
1067 #if !HAVE_DECL_BE32ENC
1068 __GEN_ENDIAN_ENC(32, be
)
1070 #if !HAVE_DECL_BE64ENC
1071 __GEN_ENDIAN_ENC(64, be
)
1073 #if !HAVE_DECL_LE16ENC
1074 __GEN_ENDIAN_ENC(16, le
)
1076 #if !HAVE_DECL_LE32ENC
1077 __GEN_ENDIAN_ENC(32, le
)
1079 #if !HAVE_DECL_LE64ENC
1080 __GEN_ENDIAN_ENC(64, le
)
1082 #undef __GEN_ENDIAN_ENC
1084 #define __GEN_ENDIAN_DEC(bits, endian) \
1085 static uint ## bits ## _t \
1086 endian ## bits ## dec(const void *buf) \
1088 uint ## bits ## _t u; \
1089 memcpy(&u, buf, sizeof(u)); \
1090 return endian ## bits ## toh (u); \
1092 #if !HAVE_DECL_BE16DEC
1093 __GEN_ENDIAN_DEC(16, be
)
1095 #if !HAVE_DECL_BE32DEC
1096 __GEN_ENDIAN_DEC(32, be
)
1098 #if !HAVE_DECL_BE64DEC
1099 __GEN_ENDIAN_DEC(64, be
)
1101 #if !HAVE_DECL_LE16DEC
1102 __GEN_ENDIAN_DEC(16, le
)
1104 #if !HAVE_DECL_LE32DEC
1105 __GEN_ENDIAN_DEC(32, le
)
1107 #if !HAVE_DECL_LE64DEC
1108 __GEN_ENDIAN_DEC(64, le
)
1110 #undef __GEN_ENDIAN_DEC
1118 /* HP-UX has MAP_ANONYMOUS but not MAP_ANON */
1120 #ifdef MAP_ANONYMOUS
1121 #define MAP_ANON MAP_ANONYMOUS
1128 #undef LITTLE_ENDIAN
1130 #define BIG_ENDIAN 4321
1131 #define LITTLE_ENDIAN 1234
1132 #define PDP_ENDIAN 3412
1136 #define BYTE_ORDER BIG_ENDIAN
1138 #define BYTE_ORDER LITTLE_ENDIAN
1141 /* all references of DEV_BSIZE in tools are for NetBSD's file images */
1143 #define DEV_BSIZE (1 << 9)
1147 #define MIN(a,b) ((a) < (b) ? (a) : (b))
1148 #define MAX(a,b) ((a) > (b) ? (a) : (b))
1151 #define MAXBSIZE (64 * 1024)
1157 #define MAXPHYS (64 * 1024)
1159 #ifndef MAXHOSTNAMELEN
1160 #define MAXHOSTNAMELEN 256
1163 /* XXX needed by makefs; this should be done in a better way */
1165 #define btodb(x) ((x) << 9)
1171 #define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
1172 #define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
1173 #define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
1174 #define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
1177 #define powerof2(x) ((((x)-1)&(x))==0)
1181 #define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
1186 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
1189 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
1193 #define S_ISTXT S_ISVTX
1199 /* Protected by _NETBSD_SOURCE otherwise. */
1200 #if HAVE_STRUCT_STAT_ST_FLAGS && (defined(__NetBSD__) || defined(__minix))
1201 #define UF_SETTABLE 0x0000ffff
1202 #define UF_NODUMP 0x00000001
1203 #define UF_IMMUTABLE 0x00000002
1204 #define UF_APPEND 0x00000004
1205 #define UF_OPAQUE 0x00000008
1206 #define SF_SETTABLE 0xffff0000
1207 #define SF_ARCHIVED 0x00010000
1208 #define SF_IMMUTABLE 0x00020000
1209 #define SF_APPEND 0x00040000
1212 /* <sys/syslimits.h> */
1215 #define LINE_MAX 2048
1221 #define timercmp(tvp, uvp, cmp) \
1222 (((tvp)->tv_sec == (uvp)->tv_sec) ? \
1223 ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
1224 ((tvp)->tv_sec cmp (uvp)->tv_sec))
1227 #define timeradd(tvp, uvp, vvp) \
1229 (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
1230 (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
1231 if ((vvp)->tv_usec >= 1000000) { \
1233 (vvp)->tv_usec -= 1000000; \
1235 } while (/* CONSTCOND */ 0)
1238 #define timersub(tvp, uvp, vvp) \
1240 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
1241 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
1242 if ((vvp)->tv_usec < 0) { \
1244 (vvp)->tv_usec += 1000000; \
1246 } while (/* CONSTCOND */ 0)
1254 #define major(x) ((int32_t)((((x) & 0x000fff00) >> 8)))
1259 #define minor(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \
1260 (((x) & 0x000000ff) >> 0)))
1264 #define makedev(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \
1265 (((y) << 12) & 0xfff00000) | \
1266 (((y) << 0) & 0x000000ff)))
1272 /* #define, not typedef, as quad_t exists as a struct on some systems */
1273 #define quad_t long long
1274 #define u_quad_t unsigned long long
1275 #define strtoq strtoll
1276 #define strtouq strtoull
1279 /* Has quad_t but these prototypes don't get pulled into scope. w/o we lose */
1280 #if defined(__NetBSD__) || defined(__minix)
1281 quad_t
strtoq(const char *, char **, int);
1282 u_quad_t
strtouq(const char *, char **, int);
1285 #endif /* !__NETBSD_COMPAT_DEFS_H__ */