Home | History | Annotate | Line # | Download | only in compat
compat_defs.h revision 1.3
      1 /*	$NetBSD: compat_defs.h,v 1.3 2002/01/29 10:20:31 tv Exp $	*/
      2 
      3 #ifndef	__NETBSD_COMPAT_DEFS_H__
      4 #define	__NETBSD_COMPAT_DEFS_H__
      5 
      6 /* System headers needed for (re)definitions below. */
      7 
      8 #include <sys/types.h>
      9 #include <sys/mman.h>
     10 #include <sys/param.h>
     11 #include <sys/stat.h>
     12 #include <errno.h>
     13 #include <fcntl.h>
     14 #include <grp.h>
     15 #include <limits.h>
     16 #include <paths.h>
     17 #include <stdarg.h>
     18 #include <stdio.h>
     19 #include <stdlib.h>
     20 #include <string.h>
     21 
     22 #if HAVE_SYS_CDEFS_H
     23 #include <sys/cdefs.h>
     24 #endif
     25 #if HAVE_SYS_SYSMACROS_H
     26 /* major(), minor() on SVR4 */
     27 #include <sys/sysmacros.h>
     28 #endif
     29 #if HAVE_INTTYPES_H
     30 #include <inttypes.h>
     31 #endif
     32 #if HAVE_STDDEF_H
     33 #include <stddef.h>
     34 #endif
     35 
     36 /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
     37 struct passwd;
     38 
     39 /* Assume an ANSI compiler for the host. */
     40 
     41 #undef __P
     42 #define __P(x) x
     43 
     44 #ifndef __BEGIN_DECLS
     45 #define __BEGIN_DECLS
     46 #endif
     47 #ifndef __END_DECLS
     48 #define __END_DECLS
     49 #endif
     50 
     51 /* Some things usually in BSD <sys/param.h>. */
     52 
     53 #undef BIG_ENDIAN
     54 #undef LITTLE_ENDIAN
     55 #define BIG_ENDIAN 4321
     56 #define LITTLE_ENDIAN 1234
     57 
     58 #undef BYTE_ORDER
     59 #if WORDS_BIGENDIAN
     60 #define BYTE_ORDER BIG_ENDIAN
     61 #else
     62 #define BYTE_ORDER LITTLE_ENDIAN
     63 #endif
     64 
     65 #undef MIN
     66 #undef MAX
     67 #define MIN(a,b) ((a) < (b) ? (a) : (b))
     68 #define MAX(a,b) ((a) > (b) ? (a) : (b))
     69 
     70 #if !defined(__attribute__) && !defined(__GNUC__)
     71 #define __attribute__(x)
     72 #endif
     73 #ifndef __RENAME
     74 #define __RENAME(x)
     75 #endif
     76 #undef __aconst
     77 #define __aconst
     78 #undef __dead
     79 #define __dead
     80 
     81 /* Dirent support. */
     82 
     83 #if HAVE_DIRENT_H
     84 # include <dirent.h>
     85 # define NAMLEN(dirent) (strlen((dirent)->d_name))
     86 #else
     87 # define dirent direct
     88 # define NAMLEN(dirent) ((dirent)->d_namlen)
     89 # if HAVE_SYS_NDIR_H
     90 #  include <sys/ndir.h>
     91 # endif
     92 # if HAVE_SYS_DIR_H
     93 #  include <sys/dir.h>
     94 # endif
     95 # if HAVE_NDIR_H
     96 #  include <ndir.h>
     97 # endif
     98 #endif
     99 
    100 /* Some bits pulled from NetBSD libc. */
    101 
    102 #if !HAVE_FTS_H
    103 #include "compat_fts.h"
    104 #endif
    105 #if !HAVE_VIS_H
    106 #include "compat_vis.h"
    107 #endif
    108 
    109 /* Type substitutes. */
    110 
    111 #if !HAVE_ID_T
    112 typedef unsigned long id_t;
    113 #endif
    114 
    115 /* Prototypes for replacement functions. */
    116 
    117 #if !HAVE_ASPRINTF
    118 int asprintf(char **, const char *, ...);
    119 #endif
    120 
    121 #if !HAVE_ASNPRINTF
    122 int asnprintf(char **, size_t, const char *, ...);
    123 #endif
    124 
    125 #if !HAVE_BASENAME
    126 char *basename(char *);
    127 #endif
    128 
    129 #if !HAVE_DIRNAME
    130 char *dirname(char *);
    131 #endif
    132 
    133 #if !HAVE_DIRFD
    134 #if HAVE_DIR_DD_FD
    135 #define dirfd(dirp) ((dirp)->dd_fd)
    136 #else
    137 #error cannot figure out how to turn a DIR * into a fd
    138 #endif
    139 #endif
    140 
    141 #if !HAVE_ERR_H
    142 void err(int, const char *, ...);
    143 void errx(int, const char *, ...);
    144 void warn(const char *, ...);
    145 void warnx(const char *, ...);
    146 #endif
    147 
    148 #if !HAVE_FGETLN
    149 char *fgetln(FILE *, size_t *);
    150 #endif
    151 
    152 #if !HAVE_FLOCK
    153 # define LOCK_SH		0x01
    154 # define LOCK_EX		0x02
    155 # define LOCK_NB		0x04
    156 # define LOCK_UN		0x08
    157 int flock(int, int);
    158 #endif
    159 
    160 #if !HAVE_FPARSELN
    161 # define FPARSELN_UNESCESC	0x01
    162 # define FPARSELN_UNESCCONT	0x02
    163 # define FPARSELN_UNESCCOMM	0x04
    164 # define FPARSELN_UNESCREST	0x08
    165 # define FPARSELN_UNESCALL	0x0f
    166 char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
    167 #endif
    168 
    169 #if !HAVE_ISBLANK && !defined(isblank)
    170 #define isblank(x) ((x) == ' ' || (x) == '\t')
    171 #endif
    172 
    173 #if !HAVE_PREAD
    174 ssize_t pread(int, void *, size_t, off_t);
    175 #endif
    176 
    177 #if !HAVE_PWCACHE_USERDB
    178 const char *user_from_uid(uid_t, int);
    179 int uid_from_user(const char *, uid_t *);
    180 int pwcache_userdb(int (*)(int), void (*)(void),
    181 		struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
    182 const char *group_from_gid(gid_t, int);
    183 int gid_from_group(const char *, gid_t *);
    184 int pwcache_groupdb(int (*)(int), void (*)(void),
    185 		struct group * (*)(const char *), struct group * (*)(gid_t));
    186 #endif
    187 
    188 #if !HAVE_PWRITE
    189 ssize_t pwrite(int, const void *, size_t, off_t);
    190 #endif
    191 
    192 #if !HAVE_SETENV
    193 int setenv(const char *, const char *, int);
    194 #endif
    195 
    196 #if !HAVE_SETGROUPENT
    197 int setgroupent(int);
    198 #endif
    199 
    200 #if !HAVE_SETPASSENT
    201 int setpassent(int);
    202 #endif
    203 
    204 #if !HAVE_SETPROGNAME
    205 const char *getprogname(void);
    206 void setprogname(const char *);
    207 #endif
    208 
    209 #if !HAVE_SNPRINTF
    210 int snprintf(char *, size_t, const char *, ...);
    211 #endif
    212 
    213 #if !HAVE_STRLCAT
    214 size_t strlcat(char *, const char *, size_t);
    215 #endif
    216 
    217 #if !HAVE_STRLCPY
    218 size_t strlcpy(char *, const char *, size_t);
    219 #endif
    220 
    221 #if !HAVE_STRSEP
    222 char *strsep(char **, const char *);
    223 #endif
    224 
    225 #if !HAVE_VASPRINTF
    226 int vasprintf(char **, const char *, va_list);
    227 #endif
    228 
    229 #if !HAVE_VASNPRINTF
    230 int vasnprintf(char **, size_t, const char *, va_list);
    231 #endif
    232 
    233 #if !HAVE_VSNPRINTF
    234 int vsnprintf(char *, size_t, const char *, va_list);
    235 #endif
    236 
    237 /*
    238  * getmode() and setmode() are always defined, as these function names
    239  * exist but with very different meanings on other OS's.  The compat
    240  * versions here simply accept an octal mode number; the "u+x,g-w" type
    241  * of syntax is not accepted.
    242  */
    243 
    244 #define getmode __nbcompat_getmode
    245 #define setmode __nbcompat_setmode
    246 
    247 mode_t getmode(const void *, mode_t);
    248 void *setmode(const char *);
    249 
    250 /* Eliminate assertions embedded in binaries. */
    251 
    252 #undef _DIAGASSERT
    253 #define _DIAGASSERT(x)
    254 #undef RCSID
    255 #define RCSID(x)
    256 
    257 /* Some definitions not available on all systems. */
    258 
    259 #ifndef _BSD_VA_LIST_
    260 #define _BSD_VA_LIST_ va_list
    261 #endif
    262 
    263 #ifndef _PATH_BSHELL
    264 #if defined(__sun)
    265 /* Sun's /bin/sh is obnoxiously broken. */
    266 #define _PATH_BSHELL "/usr/xpg4/bin/sh"
    267 #else
    268 #define _PATH_BSHELL "/bin/sh"
    269 #endif
    270 #endif
    271 #ifndef _PATH_DEFPATH
    272 #define _PATH_DEFPATH "/usr/bin:/bin:/usr/local/bin"
    273 #endif
    274 #ifndef _PATH_DEV
    275 #define _PATH_DEV "/dev/"
    276 #endif
    277 #ifndef _PATH_DEVNULL
    278 #define _PATH_DEVNULL _PATH_DEV "null"
    279 #endif
    280 #ifndef _PATH_TMP
    281 #define _PATH_TMP "/tmp/"
    282 #endif
    283 
    284 #ifndef ALLPERMS
    285 #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
    286 #endif
    287 
    288 #ifndef EFTYPE
    289 #define EFTYPE EIO
    290 #endif
    291 
    292 #ifndef UID_MAX
    293 #define UID_MAX 32767
    294 #endif
    295 #ifndef GID_MAX
    296 #define GID_MAX UID_MAX
    297 #endif
    298 
    299 #ifndef MAP_FILE
    300 #define MAP_FILE 0
    301 #endif
    302 
    303 #ifndef MAXBSIZE
    304 #define MAXBSIZE (64 * 1024)
    305 #endif
    306 
    307 #ifndef O_EXLOCK
    308 #define O_EXLOCK 0
    309 #endif
    310 #ifndef O_SHLOCK
    311 #define O_SHLOCK 0
    312 #endif
    313 
    314 #ifndef QUAD_MAX
    315 #define QUAD_MAX ((quad_t)(((u_quad_t)-1) >> 1))
    316 #endif
    317 
    318 #ifndef S_ISTXT
    319 #ifdef S_ISVTX
    320 #define S_ISTXT S_ISVTX
    321 #else
    322 #define S_ISTXT 0
    323 #endif
    324 #endif
    325 
    326 #endif	/* !__NETBSD_COMPAT_DEFS_H__ */
    327