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