Home | History | Annotate | Line # | Download | only in librumpuser
rumpuser_port.h revision 1.12
      1 /*	$NetBSD: rumpuser_port.h,v 1.12 2013/01/17 21:42:22 pooka Exp $	*/
      2 
      3 /*
      4  * Portability header for non-NetBSD platforms.
      5  * Quick & dirty.
      6  * Maybe should try to use the infrastructure in tools/compat instead?
      7  */
      8 
      9 /*
     10  * XXX:
     11  * There is currently no errno translation for the error values reported
     12  * by the hypercall layer.
     13  */
     14 
     15 #ifndef _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
     16 #define _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_
     17 
     18 #ifdef __NetBSD__
     19 #include <sys/cdefs.h>
     20 #include <sys/param.h>
     21 
     22 #define PLATFORM_HAS_KQUEUE
     23 #define PLATFORM_HAS_CHFLAGS
     24 #define PLATFORM_HAS_NBMOUNT
     25 #define PLATFORM_HAS_NFSSVC
     26 #define PLATFORM_HAS_FSYNC_RANGE
     27 #define PLATFORM_HAS_NBSYSCTL
     28 #define PLATFORM_HAS_NBFILEHANDLE
     29 
     30 #if __NetBSD_Prereq__(5,99,48)
     31 #define PLATFORM_HAS_NBQUOTA
     32 #endif
     33 
     34 /*
     35  * This includes also statvfs1() and fstatvfs1().  They could be
     36  * reasonably easily emulated on other platforms.
     37  */
     38 #define PLATFORM_HAS_NBVFSSTAT
     39 #endif
     40 
     41 #ifdef __linux__
     42 #define _XOPEN_SOURCE 600
     43 #define _BSD_SOURCE
     44 #define _FILE_OFFSET_BITS 64
     45 #define _GNU_SOURCE
     46 #include <features.h>
     47 #endif
     48 
     49 #include <sys/types.h>
     50 #include <sys/param.h>
     51 
     52 /* maybe this should be !__NetBSD__ ? */
     53 #if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__)	\
     54     || defined(__DragonFly__) || defined(__CYGWIN__)
     55 #include <errno.h>
     56 #include <stdlib.h>
     57 #include <string.h>
     58 
     59 /* this is inline simply to make this header self-contained */
     60 static inline int
     61 getenv_r(const char *name, char *buf, size_t buflen)
     62 {
     63 	char *tmp;
     64 
     65 	if ((tmp = getenv(name)) != NULL) {
     66 		if (strlen(tmp) >= buflen) {
     67 			errno = ERANGE;
     68 			return -1;
     69 		}
     70 		strcpy(buf, tmp);
     71 		return 0;
     72 	} else {
     73 		errno = ENOENT;
     74 		return -1;
     75 	}
     76 }
     77 #endif
     78 
     79 #if defined(__sun__)
     80 #include <sys/sysmacros.h>
     81 
     82 /* Solarisa 10 has memalign() but no posix_memalign() */
     83 #include <stdlib.h>
     84 
     85 static inline int
     86 posix_memalign(void **ptr, size_t align, size_t size)
     87 {
     88 
     89 	*ptr = memalign(align, size);
     90 	if (*ptr == NULL)
     91 		return ENOMEM;
     92 	return 0;
     93 }
     94 #endif /* __sun__ */
     95 
     96 #ifndef __RCSID
     97 #define __RCSID(a)
     98 #endif
     99 
    100 #ifndef INFTIM
    101 #define INFTIM (-1)
    102 #endif
    103 
    104 #ifndef _DIAGASSERT
    105 #define _DIAGASSERT(_p_)
    106 #endif
    107 
    108 #if defined(__linux__) || defined(__sun__) || defined(__CYGWIN__)
    109 #define SIN_SETLEN(a,b)
    110 #else /* BSD */
    111 #define SIN_SETLEN(_sin_, _len_) _sin_.sin_len = _len_
    112 #endif
    113 
    114 #ifndef __predict_true
    115 #define __predict_true(a) a
    116 #define __predict_false(a) a
    117 #endif
    118 
    119 #ifndef __dead
    120 #define __dead __attribute__((__noreturn__))
    121 #endif
    122 
    123 #ifndef __printflike
    124 #define __printflike(a,b)
    125 #endif
    126 
    127 #ifndef __noinline
    128 #ifdef __GNUC__
    129 #define __noinline __attribute__((__noinline__))
    130 #else
    131 #define __noinline
    132 #endif
    133 #endif
    134 
    135 #ifndef __arraycount
    136 #define __arraycount(_ar_) (sizeof(_ar_)/sizeof(_ar_[0]))
    137 #endif
    138 
    139 #ifndef __UNCONST
    140 #define __UNCONST(_a_) ((void *)(unsigned long)(const void *)(_a_))
    141 #endif
    142 
    143 #if defined(__linux__) || defined(__sun__) || defined (__CYGWIN__)
    144 #define arc4random() random()
    145 #define RUMPUSER_USE_RANDOM
    146 #endif
    147 
    148 #ifndef __NetBSD_Prereq__
    149 #define __NetBSD_Prereq__(a,b,c) 0
    150 #endif
    151 
    152 #include <sys/socket.h>
    153 
    154 #if !defined(__CMSG_ALIGN)
    155 #ifdef CMSG_ALIGN
    156 #define __CMSG_ALIGN(a) CMSG_ALIGN(a)
    157 #endif
    158 #endif
    159 
    160 #ifndef PF_LOCAL
    161 #define PF_LOCAL PF_UNIX
    162 #endif
    163 #ifndef AF_LOCAL
    164 #define AF_LOCAL AF_UNIX
    165 #endif
    166 
    167 /* pfft, but what are you going to do? */
    168 #ifndef MSG_NOSIGNAL
    169 #define MSG_NOSIGNAL 0
    170 #endif
    171 
    172 #if defined(__sun__) && !defined(RUMP_REGISTER_T)
    173 #define RUMP_REGISTER_T long
    174 typedef RUMP_REGISTER_T register_t;
    175 #endif
    176 
    177 #endif /* _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ */
    178