ref: 6a51a03b801b21f42e2eb3dfa02c99e96c86b10c
dir: /plan9/platform.h/
#include <u.h>
#include <libc.h>
#include <ctype.h>
#include <mp.h>
#ifdef NDEBUG
#undef assert
#define assert(x)
#endif
#define __os_name__ "plan9"
#define __thread
#define __builtin_prefetch(x)
int __builtin_clz(unsigned int x);
#define MEM_ALLOC(n) malloc(n)
#define MEM_REALLOC(p, n) realloc((p), (n))
#define MEM_FREE(x) free(x)
#define MEM_STRDUP(s) strdup(s)
/* FIXME(sigrid): s*_overflow_* can be more optimal */
#define sadd_overflow_64(a, b, c) ( \
(b < 1) ? \
((INT64_MAX-(b) <= (a)) ? ((*(c)=(a)+(b)), 0) : 1) : \
((INT64_MAX-(b) >= (a)) ? ((*(c)=(a)+(b)), 0) : 1) \
)
#define smul_overflow_64(a, b, c) ( \
((a)>0 ? ((b)>0 ? (a)>INT64_MAX/(b) : (b)<INT64_MIN/(a)) \
: ((b)>0 ? (a)<INT64_MIN/(b) : ((a)!=0 && (b)<INT64_MAX/(a)))) \
? 1 \
: ((*(c)=(a)*(b)), 0) \
)
#if defined(__amd64__) || \
defined(__arm64__) || \
defined(__mips64__) || \
defined(__power64__) || \
defined(__sparc64__)
#define BITS64
#define PRIdPTR PRId64
#define sadd_overflow(a, b, c) sadd_overflow_64(a, b, c)
#else
#define PRIdPTR "ld"
#define sadd_overflow(a, b, c) ( \
(b < 1) ? \
((INT32_MAX-(b) <= (a)) ? ((*(c)=(a)+(b)), 0) : 1) : \
((INT32_MAX-(b) >= (a)) ? ((*(c)=(a)+(b)), 0) : 1) \
)
#endif
#define unsetenv(name) putenv(name, "")
#define setenv(name, val, overwrite) putenv(name, val)
#define exit(x) exits((x) ? "error" : nil)
#define isnan(x) isNaN(x)
#define getcwd getwd
#define vsnprintf vsnprint
#define vdprintf fprint
#define snprintf snprint
#define strcasecmp cistrcmp
#define lseek seek
#define towupper toupperrune
#define towlower tolowerrune
#define iswalpha isalpharune
#define signbit(r) ((*(uint64_t*)&(r)) & (1ULL<<63))
#define isfinite(d) (((*(uint64_t*)&(d))&0x7ff0000000000000ULL) != 0x7ff0000000000000ULL)
#define PRIu32 "ud"
#define PRId64 "lld"
#define PRIu64 "llud"
#define INT32_MAX 0x7fffffff
#define UINT32_MAX 0xffffffffU
#define INT32_MIN (-INT32_MAX-1)
#define INT64_MIN ((int64_t)0x8000000000000000LL)
#define INT64_MAX 0x7fffffffffffffffLL
#define UINT64_MAX 0xffffffffffffffffULL
#define PATHSEP '/'
#define PATHSEPSTRING "/"
#define PATHLISTSEP ':'
#define PATHLISTSEPSTRING ":"
#define ISPATHSEP(c) ((c) == '/')
enum {
SEEK_SET,
SEEK_CUR,
SEEK_END,
STDIN_FILENO = 0,
STDOUT_FILENO,
STDERR_FILENO,
};
#define O_RDWR ORDWR
#define O_WRONLY OWRITE
#define O_RDONLY OREAD
#define O_TRUNC OTRUNC
#define F_OK 0
#define LITTLE_ENDIAN 1234
#define BIG_ENDIAN 4321
#if defined(__mips__) || \
defined(__power__) || defined(__power64__) || \
defined(__sparc__) || defined(__sparc64__)
#define BYTE_ORDER BIG_ENDIAN
#else
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#define __unlikely(x) (x)
#define __likely(x) (x)
typedef s8int int8_t;
typedef s16int int16_t;
typedef s32int int32_t;
typedef s64int int64_t;
typedef u8int uint8_t;
typedef u16int uint16_t;
typedef u32int uint32_t;
typedef u64int uint64_t;
typedef vlong off_t;
typedef intptr intptr_t;
typedef uintptr uintptr_t;
typedef intptr ssize_t;
typedef uintptr size_t;
typedef enum { false, true } bool;
int wcwidth(Rune c);