Home | History | Annotate | Line # | Download | only in compat
compat_defs.h revision 1.4
      1  1.4       tv /*	$NetBSD: compat_defs.h,v 1.4 2002/01/31 22:43:45 tv Exp $	*/
      2  1.1  thorpej 
      3  1.1  thorpej #ifndef	__NETBSD_COMPAT_DEFS_H__
      4  1.1  thorpej #define	__NETBSD_COMPAT_DEFS_H__
      5  1.1  thorpej 
      6  1.4       tv /* Work around some complete brain damage. */
      7  1.4       tv 
      8  1.4       tv /*
      9  1.4       tv  * Linux: <features.h> turns on _POSIX_SOURCE by default, even though the
     10  1.4       tv  * program (not the OS) should do that.  Preload <features.h> to keep any
     11  1.4       tv  * of this crap from being pulled in, and undefine _POSIX_SOURCE.
     12  1.4       tv  */
     13  1.4       tv 
     14  1.4       tv #if defined(__linux__) && HAVE_FEATURES_H
     15  1.4       tv #include <features.h>
     16  1.4       tv #endif
     17  1.4       tv 
     18  1.4       tv #undef _POSIX_SOURCE
     19  1.4       tv #undef _POSIX_C_SOURCE
     20  1.4       tv 
     21  1.1  thorpej /* System headers needed for (re)definitions below. */
     22  1.1  thorpej 
     23  1.1  thorpej #include <sys/types.h>
     24  1.3       tv #include <sys/mman.h>
     25  1.3       tv #include <sys/param.h>
     26  1.3       tv #include <sys/stat.h>
     27  1.4       tv #include <sys/time.h>
     28  1.1  thorpej #include <errno.h>
     29  1.1  thorpej #include <fcntl.h>
     30  1.2    lukem #include <grp.h>
     31  1.1  thorpej #include <limits.h>
     32  1.1  thorpej #include <paths.h>
     33  1.3       tv #include <stdarg.h>
     34  1.1  thorpej #include <stdio.h>
     35  1.3       tv #include <stdlib.h>
     36  1.1  thorpej #include <string.h>
     37  1.1  thorpej 
     38  1.3       tv #if HAVE_SYS_CDEFS_H
     39  1.3       tv #include <sys/cdefs.h>
     40  1.3       tv #endif
     41  1.3       tv #if HAVE_SYS_SYSMACROS_H
     42  1.3       tv /* major(), minor() on SVR4 */
     43  1.3       tv #include <sys/sysmacros.h>
     44  1.3       tv #endif
     45  1.1  thorpej #if HAVE_INTTYPES_H
     46  1.1  thorpej #include <inttypes.h>
     47  1.1  thorpej #endif
     48  1.1  thorpej #if HAVE_STDDEF_H
     49  1.1  thorpej #include <stddef.h>
     50  1.1  thorpej #endif
     51  1.3       tv 
     52  1.3       tv /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
     53  1.3       tv struct passwd;
     54  1.3       tv 
     55  1.3       tv /* Assume an ANSI compiler for the host. */
     56  1.3       tv 
     57  1.3       tv #undef __P
     58  1.3       tv #define __P(x) x
     59  1.3       tv 
     60  1.3       tv #ifndef __BEGIN_DECLS
     61  1.3       tv #define __BEGIN_DECLS
     62  1.3       tv #endif
     63  1.3       tv #ifndef __END_DECLS
     64  1.3       tv #define __END_DECLS
     65  1.3       tv #endif
     66  1.3       tv 
     67  1.4       tv /* Some things usually in BSD <sys/cdefs.h>. */
     68  1.3       tv 
     69  1.1  thorpej #if !defined(__attribute__) && !defined(__GNUC__)
     70  1.1  thorpej #define __attribute__(x)
     71  1.1  thorpej #endif
     72  1.3       tv #ifndef __RENAME
     73  1.3       tv #define __RENAME(x)
     74  1.3       tv #endif
     75  1.3       tv #undef __aconst
     76  1.3       tv #define __aconst
     77  1.3       tv #undef __dead
     78  1.3       tv #define __dead
     79  1.3       tv 
     80  1.3       tv /* Dirent support. */
     81  1.3       tv 
     82  1.3       tv #if HAVE_DIRENT_H
     83  1.3       tv # include <dirent.h>
     84  1.3       tv # define NAMLEN(dirent) (strlen((dirent)->d_name))
     85  1.3       tv #else
     86  1.3       tv # define dirent direct
     87  1.3       tv # define NAMLEN(dirent) ((dirent)->d_namlen)
     88  1.3       tv # if HAVE_SYS_NDIR_H
     89  1.3       tv #  include <sys/ndir.h>
     90  1.3       tv # endif
     91  1.3       tv # if HAVE_SYS_DIR_H
     92  1.3       tv #  include <sys/dir.h>
     93  1.3       tv # endif
     94  1.3       tv # if HAVE_NDIR_H
     95  1.3       tv #  include <ndir.h>
     96  1.3       tv # endif
     97  1.3       tv #endif
     98  1.3       tv 
     99  1.1  thorpej /* Type substitutes. */
    100  1.1  thorpej 
    101  1.1  thorpej #if !HAVE_ID_T
    102  1.1  thorpej typedef unsigned long id_t;
    103  1.1  thorpej #endif
    104  1.1  thorpej 
    105  1.1  thorpej /* Prototypes for replacement functions. */
    106  1.1  thorpej 
    107  1.3       tv #if !HAVE_ASPRINTF
    108  1.3       tv int asprintf(char **, const char *, ...);
    109  1.3       tv #endif
    110  1.3       tv 
    111  1.3       tv #if !HAVE_ASNPRINTF
    112  1.3       tv int asnprintf(char **, size_t, const char *, ...);
    113  1.3       tv #endif
    114  1.3       tv 
    115  1.1  thorpej #if !HAVE_BASENAME
    116  1.1  thorpej char *basename(char *);
    117  1.1  thorpej #endif
    118  1.1  thorpej 
    119  1.4       tv #if !HAVE_DECL_OPTIND
    120  1.4       tv int getopt(int, char *const *, const char *);
    121  1.4       tv extern char *optarg;
    122  1.4       tv extern int optind, opterr, optopt;
    123  1.4       tv #endif
    124  1.4       tv 
    125  1.1  thorpej #if !HAVE_DIRNAME
    126  1.1  thorpej char *dirname(char *);
    127  1.1  thorpej #endif
    128  1.1  thorpej 
    129  1.3       tv #if !HAVE_DIRFD
    130  1.3       tv #if HAVE_DIR_DD_FD
    131  1.3       tv #define dirfd(dirp) ((dirp)->dd_fd)
    132  1.3       tv #else
    133  1.3       tv #error cannot figure out how to turn a DIR * into a fd
    134  1.3       tv #endif
    135  1.3       tv #endif
    136  1.3       tv 
    137  1.1  thorpej #if !HAVE_ERR_H
    138  1.3       tv void err(int, const char *, ...);
    139  1.3       tv void errx(int, const char *, ...);
    140  1.1  thorpej void warn(const char *, ...);
    141  1.1  thorpej void warnx(const char *, ...);
    142  1.1  thorpej #endif
    143  1.1  thorpej 
    144  1.1  thorpej #if !HAVE_FGETLN
    145  1.1  thorpej char *fgetln(FILE *, size_t *);
    146  1.1  thorpej #endif
    147  1.1  thorpej 
    148  1.1  thorpej #if !HAVE_FLOCK
    149  1.1  thorpej # define LOCK_SH		0x01
    150  1.1  thorpej # define LOCK_EX		0x02
    151  1.1  thorpej # define LOCK_NB		0x04
    152  1.1  thorpej # define LOCK_UN		0x08
    153  1.1  thorpej int flock(int, int);
    154  1.1  thorpej #endif
    155  1.1  thorpej 
    156  1.1  thorpej #if !HAVE_FPARSELN
    157  1.1  thorpej # define FPARSELN_UNESCESC	0x01
    158  1.1  thorpej # define FPARSELN_UNESCCONT	0x02
    159  1.1  thorpej # define FPARSELN_UNESCCOMM	0x04
    160  1.1  thorpej # define FPARSELN_UNESCREST	0x08
    161  1.1  thorpej # define FPARSELN_UNESCALL	0x0f
    162  1.1  thorpej char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
    163  1.1  thorpej #endif
    164  1.1  thorpej 
    165  1.3       tv #if !HAVE_ISBLANK && !defined(isblank)
    166  1.3       tv #define isblank(x) ((x) == ' ' || (x) == '\t')
    167  1.1  thorpej #endif
    168  1.1  thorpej 
    169  1.4       tv #if !HAVE_MACHINE_BSWAP_H
    170  1.4       tv #define bswap16(x)	((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
    171  1.4       tv 
    172  1.4       tv #define bswap32(x)	((((x) << 24) & 0xff000000) | \
    173  1.4       tv 			 (((x) <<  8) & 0x00ff0000) | \
    174  1.4       tv 			 (((x) >>  8) & 0x0000ff00) | \
    175  1.4       tv 			 (((x) >> 24) & 0x000000ff))
    176  1.4       tv 
    177  1.4       tv #define bswap64(x)	(((u_int64_t)bswap32((x)) << 32) | \
    178  1.4       tv 			 ((u_int64_t)bswap32((x) >> 32)))
    179  1.4       tv #endif
    180  1.4       tv 
    181  1.1  thorpej #if !HAVE_PREAD
    182  1.1  thorpej ssize_t pread(int, void *, size_t, off_t);
    183  1.2    lukem #endif
    184  1.2    lukem 
    185  1.2    lukem #if !HAVE_PWCACHE_USERDB
    186  1.2    lukem const char *user_from_uid(uid_t, int);
    187  1.2    lukem int uid_from_user(const char *, uid_t *);
    188  1.2    lukem int pwcache_userdb(int (*)(int), void (*)(void),
    189  1.2    lukem 		struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
    190  1.2    lukem const char *group_from_gid(gid_t, int);
    191  1.2    lukem int gid_from_group(const char *, gid_t *);
    192  1.2    lukem int pwcache_groupdb(int (*)(int), void (*)(void),
    193  1.2    lukem 		struct group * (*)(const char *), struct group * (*)(gid_t));
    194  1.1  thorpej #endif
    195  1.1  thorpej 
    196  1.1  thorpej #if !HAVE_PWRITE
    197  1.1  thorpej ssize_t pwrite(int, const void *, size_t, off_t);
    198  1.1  thorpej #endif
    199  1.1  thorpej 
    200  1.3       tv #if !HAVE_SETENV
    201  1.3       tv int setenv(const char *, const char *, int);
    202  1.3       tv #endif
    203  1.3       tv 
    204  1.3       tv #if !HAVE_SETGROUPENT
    205  1.3       tv int setgroupent(int);
    206  1.3       tv #endif
    207  1.3       tv 
    208  1.3       tv #if !HAVE_SETPASSENT
    209  1.3       tv int setpassent(int);
    210  1.3       tv #endif
    211  1.3       tv 
    212  1.3       tv #if !HAVE_SETPROGNAME
    213  1.3       tv const char *getprogname(void);
    214  1.3       tv void setprogname(const char *);
    215  1.3       tv #endif
    216  1.3       tv 
    217  1.3       tv #if !HAVE_SNPRINTF
    218  1.3       tv int snprintf(char *, size_t, const char *, ...);
    219  1.3       tv #endif
    220  1.3       tv 
    221  1.3       tv #if !HAVE_STRLCAT
    222  1.3       tv size_t strlcat(char *, const char *, size_t);
    223  1.3       tv #endif
    224  1.3       tv 
    225  1.3       tv #if !HAVE_STRLCPY
    226  1.3       tv size_t strlcpy(char *, const char *, size_t);
    227  1.3       tv #endif
    228  1.3       tv 
    229  1.3       tv #if !HAVE_STRSEP
    230  1.3       tv char *strsep(char **, const char *);
    231  1.3       tv #endif
    232  1.3       tv 
    233  1.3       tv #if !HAVE_VASPRINTF
    234  1.3       tv int vasprintf(char **, const char *, va_list);
    235  1.3       tv #endif
    236  1.3       tv 
    237  1.3       tv #if !HAVE_VASNPRINTF
    238  1.3       tv int vasnprintf(char **, size_t, const char *, va_list);
    239  1.3       tv #endif
    240  1.3       tv 
    241  1.3       tv #if !HAVE_VSNPRINTF
    242  1.3       tv int vsnprintf(char *, size_t, const char *, va_list);
    243  1.3       tv #endif
    244  1.3       tv 
    245  1.1  thorpej /*
    246  1.1  thorpej  * getmode() and setmode() are always defined, as these function names
    247  1.1  thorpej  * exist but with very different meanings on other OS's.  The compat
    248  1.1  thorpej  * versions here simply accept an octal mode number; the "u+x,g-w" type
    249  1.1  thorpej  * of syntax is not accepted.
    250  1.1  thorpej  */
    251  1.1  thorpej 
    252  1.1  thorpej #define getmode __nbcompat_getmode
    253  1.1  thorpej #define setmode __nbcompat_setmode
    254  1.1  thorpej 
    255  1.1  thorpej mode_t getmode(const void *, mode_t);
    256  1.1  thorpej void *setmode(const char *);
    257  1.1  thorpej 
    258  1.3       tv /* Eliminate assertions embedded in binaries. */
    259  1.1  thorpej 
    260  1.1  thorpej #undef _DIAGASSERT
    261  1.3       tv #define _DIAGASSERT(x)
    262  1.4       tv 
    263  1.4       tv /* Heimdal expects this one. */
    264  1.4       tv 
    265  1.3       tv #undef RCSID
    266  1.3       tv #define RCSID(x)
    267  1.1  thorpej 
    268  1.3       tv /* Some definitions not available on all systems. */
    269  1.1  thorpej 
    270  1.4       tv /* <errno.h> */
    271  1.4       tv 
    272  1.4       tv #ifndef EFTYPE
    273  1.4       tv #define EFTYPE EIO
    274  1.4       tv #endif
    275  1.4       tv 
    276  1.4       tv /* <fcntl.h> */
    277  1.4       tv 
    278  1.4       tv #ifndef O_EXLOCK
    279  1.4       tv #define O_EXLOCK 0
    280  1.4       tv #endif
    281  1.4       tv #ifndef O_SHLOCK
    282  1.4       tv #define O_SHLOCK 0
    283  1.4       tv #endif
    284  1.4       tv 
    285  1.4       tv /*<limits.h> */
    286  1.4       tv 
    287  1.4       tv #ifndef UID_MAX
    288  1.4       tv #define UID_MAX 32767
    289  1.4       tv #endif
    290  1.4       tv #ifndef GID_MAX
    291  1.4       tv #define GID_MAX UID_MAX
    292  1.4       tv #endif
    293  1.4       tv 
    294  1.4       tv #ifndef UQUAD_MAX
    295  1.4       tv #define UQUAD_MAX ((u_quad_t)-1)
    296  1.4       tv #endif
    297  1.4       tv #ifndef QUAD_MAX
    298  1.4       tv #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1))
    299  1.4       tv #endif
    300  1.4       tv #ifndef QUAD_MIN
    301  1.4       tv #define QUAD_MIN ((quad_t)(~QUAD_MAX))
    302  1.4       tv #endif
    303  1.4       tv #ifndef ULLONG_MAX
    304  1.4       tv #define ULLONG_MAX ((unsigned long long)-1)
    305  1.4       tv #endif
    306  1.4       tv #ifndef LLONG_MAX
    307  1.4       tv #define LLONG_MAX ((long long)(ULLONG_MAX >> 1))
    308  1.4       tv #endif
    309  1.4       tv #ifndef LLONG_MIN
    310  1.4       tv #define LLONG_MIN ((long long)(~LLONG_MAX))
    311  1.3       tv #endif
    312  1.1  thorpej 
    313  1.4       tv /* <paths.h> */
    314  1.4       tv 
    315  1.3       tv #ifndef _PATH_BSHELL
    316  1.3       tv #if defined(__sun)
    317  1.3       tv /* Sun's /bin/sh is obnoxiously broken. */
    318  1.3       tv #define _PATH_BSHELL "/usr/xpg4/bin/sh"
    319  1.1  thorpej #else
    320  1.3       tv #define _PATH_BSHELL "/bin/sh"
    321  1.3       tv #endif
    322  1.1  thorpej #endif
    323  1.1  thorpej #ifndef _PATH_DEFPATH
    324  1.1  thorpej #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
    325  1.1  thorpej #endif
    326  1.1  thorpej #ifndef _PATH_DEV
    327  1.1  thorpej #define _PATH_DEV "/dev/"
    328  1.1  thorpej #endif
    329  1.1  thorpej #ifndef _PATH_DEVNULL
    330  1.1  thorpej #define _PATH_DEVNULL _PATH_DEV "null"
    331  1.1  thorpej #endif
    332  1.1  thorpej #ifndef _PATH_TMP
    333  1.1  thorpej #define _PATH_TMP "/tmp/"
    334  1.1  thorpej #endif
    335  1.1  thorpej 
    336  1.4       tv /* <stdarg.h> */
    337  1.3       tv 
    338  1.4       tv #ifndef _BSD_VA_LIST_
    339  1.4       tv #define _BSD_VA_LIST_ va_list
    340  1.1  thorpej #endif
    341  1.1  thorpej 
    342  1.4       tv /* <sys/mman.h> */
    343  1.3       tv 
    344  1.3       tv #ifndef MAP_FILE
    345  1.3       tv #define MAP_FILE 0
    346  1.3       tv #endif
    347  1.3       tv 
    348  1.4       tv /* <sys/param.h> */
    349  1.4       tv 
    350  1.4       tv #undef BIG_ENDIAN
    351  1.4       tv #undef LITTLE_ENDIAN
    352  1.4       tv #define BIG_ENDIAN 4321
    353  1.4       tv #define LITTLE_ENDIAN 1234
    354  1.4       tv 
    355  1.4       tv #undef BYTE_ORDER
    356  1.4       tv #if WORDS_BIGENDIAN
    357  1.4       tv #define BYTE_ORDER BIG_ENDIAN
    358  1.4       tv #else
    359  1.4       tv #define BYTE_ORDER LITTLE_ENDIAN
    360  1.4       tv #endif
    361  1.4       tv 
    362  1.4       tv #undef MIN
    363  1.4       tv #undef MAX
    364  1.4       tv #define MIN(a,b) ((a) < (b) ? (a) : (b))
    365  1.4       tv #define MAX(a,b) ((a) > (b) ? (a) : (b))
    366  1.4       tv 
    367  1.1  thorpej #ifndef MAXBSIZE
    368  1.1  thorpej #define MAXBSIZE (64 * 1024)
    369  1.1  thorpej #endif
    370  1.4       tv #ifndef MAXFRAG
    371  1.4       tv #define MAXFRAG 8
    372  1.1  thorpej #endif
    373  1.4       tv #ifndef MAXPHYS
    374  1.4       tv #define MAXPHYS (64 * 1024)
    375  1.3       tv #endif
    376  1.3       tv 
    377  1.4       tv /* XXX needed by makefs; this should be done in a better way */
    378  1.4       tv #undef btodb
    379  1.4       tv #define btodb(x) ((x) << 9)
    380  1.4       tv 
    381  1.4       tv #ifndef powerof2
    382  1.4       tv #define powerof2(x) ((((x)-1)&(x))==0)
    383  1.3       tv #endif
    384  1.3       tv 
    385  1.4       tv /* <sys/stat.h> */
    386  1.4       tv 
    387  1.4       tv #ifndef ALLPERMS
    388  1.4       tv #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
    389  1.4       tv #endif
    390  1.4       tv #ifndef DEFFILEMODE
    391  1.4       tv #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
    392  1.4       tv #endif
    393  1.3       tv #ifndef S_ISTXT
    394  1.3       tv #ifdef S_ISVTX
    395  1.3       tv #define S_ISTXT S_ISVTX
    396  1.3       tv #else
    397  1.3       tv #define S_ISTXT 0
    398  1.3       tv #endif
    399  1.4       tv #endif
    400  1.4       tv 
    401  1.4       tv /* <sys/time.h> */
    402  1.4       tv 
    403  1.4       tv #ifndef timercmp
    404  1.4       tv #define	timercmp(tvp, uvp, cmp)						\
    405  1.4       tv 	(((tvp)->tv_sec == (uvp)->tv_sec) ?				\
    406  1.4       tv 	    ((tvp)->tv_usec cmp (uvp)->tv_usec) :			\
    407  1.4       tv 	    ((tvp)->tv_sec cmp (uvp)->tv_sec))
    408  1.4       tv #endif
    409  1.4       tv #ifndef timeradd
    410  1.4       tv #define	timeradd(tvp, uvp, vvp)						\
    411  1.4       tv 	do {								\
    412  1.4       tv 		(vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec;		\
    413  1.4       tv 		(vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec;	\
    414  1.4       tv 		if ((vvp)->tv_usec >= 1000000) {			\
    415  1.4       tv 			(vvp)->tv_sec++;				\
    416  1.4       tv 			(vvp)->tv_usec -= 1000000;			\
    417  1.4       tv 		}							\
    418  1.4       tv 	} while (/* CONSTCOND */ 0)
    419  1.4       tv #endif
    420  1.4       tv #ifndef timersub
    421  1.4       tv #define	timersub(tvp, uvp, vvp)						\
    422  1.4       tv 	do {								\
    423  1.4       tv 		(vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec;		\
    424  1.4       tv 		(vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec;	\
    425  1.4       tv 		if ((vvp)->tv_usec < 0) {				\
    426  1.4       tv 			(vvp)->tv_sec--;				\
    427  1.4       tv 			(vvp)->tv_usec += 1000000;			\
    428  1.4       tv 		}							\
    429  1.4       tv 	} while (/* CONSTCOND */ 0)
    430  1.4       tv #endif
    431  1.4       tv 
    432  1.4       tv /* <sys/types.h> */
    433  1.4       tv 
    434  1.4       tv #if !HAVE_U_QUAD_T
    435  1.4       tv /* #define, not typedef, as quad_t exists as a struct on some systems */
    436  1.4       tv #define quad_t long long
    437  1.4       tv #define u_quad_t unsigned long long
    438  1.4       tv #define strtouq strtoull
    439  1.1  thorpej #endif
    440  1.1  thorpej 
    441  1.1  thorpej #endif	/* !__NETBSD_COMPAT_DEFS_H__ */
    442