1 /* $NetBSD: rumpuser_port.h,v 1.16 2013/03/20 12:59:10 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 #if defined(__sun__) 50 # if defined(RUMPUSER_NO_FILE_OFFSET_BITS) 51 # undef _FILE_OFFSET_BITS 52 # else 53 # define _FILE_OFFSET_BITS 64 54 # endif 55 #endif 56 57 #include <sys/types.h> 58 #include <sys/param.h> 59 60 /* maybe this should be !__NetBSD__ ? */ 61 #if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \ 62 || defined(__DragonFly__) || defined(__CYGWIN__) 63 #include <errno.h> 64 #include <stdlib.h> 65 #include <string.h> 66 67 /* this is inline simply to make this header self-contained */ 68 static inline int 69 getenv_r(const char *name, char *buf, size_t buflen) 70 { 71 char *tmp; 72 73 if ((tmp = getenv(name)) != NULL) { 74 if (strlen(tmp) >= buflen) { 75 errno = ERANGE; 76 return -1; 77 } 78 strcpy(buf, tmp); 79 return 0; 80 } else { 81 errno = ENOENT; 82 return -1; 83 } 84 } 85 #endif 86 87 #if defined(__sun__) 88 #include <sys/sysmacros.h> 89 90 #if !defined(HAVE_POSIX_MEMALIGN) 91 /* Solarisa 10 has memalign() but no posix_memalign() */ 92 #include <stdlib.h> 93 94 static inline int 95 posix_memalign(void **ptr, size_t align, size_t size) 96 { 97 98 *ptr = memalign(align, size); 99 if (*ptr == NULL) 100 return ENOMEM; 101 return 0; 102 } 103 #endif /* !HAVE_POSIX_MEMALIGN */ 104 #endif /* __sun__ */ 105 106 #ifndef __RCSID 107 #define __RCSID(a) 108 #endif 109 110 #ifndef INFTIM 111 #define INFTIM (-1) 112 #endif 113 114 #ifndef _DIAGASSERT 115 #define _DIAGASSERT(_p_) 116 #endif 117 118 #if defined(__linux__) || defined(__sun__) || defined(__CYGWIN__) 119 #define SIN_SETLEN(a,b) 120 #else /* BSD */ 121 #define SIN_SETLEN(_sin_, _len_) _sin_.sin_len = _len_ 122 #endif 123 124 #ifndef __predict_true 125 #define __predict_true(a) a 126 #define __predict_false(a) a 127 #endif 128 129 #ifndef __dead 130 #define __dead __attribute__((__noreturn__)) 131 #endif 132 133 #ifndef __printflike 134 #define __printflike(a,b) 135 #endif 136 137 #ifndef __noinline 138 #ifdef __GNUC__ 139 #define __noinline __attribute__((__noinline__)) 140 #else 141 #define __noinline 142 #endif 143 #endif 144 145 #ifndef __arraycount 146 #define __arraycount(_ar_) (sizeof(_ar_)/sizeof(_ar_[0])) 147 #endif 148 149 #ifndef __UNCONST 150 #define __UNCONST(_a_) ((void *)(unsigned long)(const void *)(_a_)) 151 #endif 152 153 #if defined(__linux__) || defined(__sun__) || defined (__CYGWIN__) 154 #define arc4random() random() 155 #define RUMPUSER_USE_RANDOM 156 #endif 157 158 #ifndef __NetBSD_Prereq__ 159 #define __NetBSD_Prereq__(a,b,c) 0 160 #endif 161 162 #include <sys/socket.h> 163 164 #if !defined(__CMSG_ALIGN) 165 #ifdef CMSG_ALIGN 166 #define __CMSG_ALIGN(a) CMSG_ALIGN(a) 167 #endif 168 #endif 169 170 #ifndef PF_LOCAL 171 #define PF_LOCAL PF_UNIX 172 #endif 173 #ifndef AF_LOCAL 174 #define AF_LOCAL AF_UNIX 175 #endif 176 177 /* pfft, but what are you going to do? */ 178 #ifndef MSG_NOSIGNAL 179 #define MSG_NOSIGNAL 0 180 #endif 181 182 #if defined(__sun__) && !defined(RUMP_REGISTER_T) 183 #define RUMP_REGISTER_T long 184 typedef RUMP_REGISTER_T register_t; 185 #endif 186 187 #endif /* _LIB_LIBRUMPUSER_RUMPUSER_PORT_H_ */ 188