shithub: sl

ref: a969b42b0d893df35c38956a6f433b515bbdaf58
dir: /src/plan9/platform.h/

View raw version
#pragma once

#include <u.h>
#include <libc.h>
#include <ctype.h>
#include <mp.h>

#ifdef NDEBUG
#undef assert
#define assert(x)
#define static_assert(a,b)
#else
#define static_assert_cat(a, b) a##b
#define static_assert_name(line) static_assert_cat(static_assert_, line)
#define static_assert(must_be_true, message) \
	static const void *static_assert_name(__LINE__) \
		[must_be_true ? 2 : -1] = { \
			message, \
			static_assert_name(__LINE__), \
		}
#endif

#define __os_name__ "plan9"

int fl_popcount(unsigned int w);
int fl_clz(unsigned int x);

extern double D_PNAN, D_PINF;

#if defined(__amd64__) || \
    defined(__arm64__) || \
    defined(__mips64__) || \
    defined(__power64__) || \
    defined(__sparc64__)
#define BITS64
#define PRIdPTR PRId64
#define PRIuPTR PRIu64
#else
#define PRIdPTR "ld"
#define PRIuPTR "lud"
#endif

#if defined(__386__) || defined(__amd64__) || defined(__arm64__)
#define MEM_UNALIGNED_ACCESS
#endif

#define unsetenv(name) putenv(name, "")
#define setenv(name, val, overwrite) putenv(name, val)
#define exit(x) exits((x) ? "error" : nil)
#define isinf(x) isInf(x, 0)
#define isnan(x) isNaN(x)

#define getcwd getwd
#define vsnprintf vsnprint
#define vdprintf vfprint
#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 PRId32 "d"
#define PRIu32 "ud"
#define PRIx32 "x"
#define PRId64 "lld"
#define PRIu64 "llud"
#define PRIx64 "llx"

#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 ULONG_MAX UINT32_MAX

#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

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 fl_iswprint(Rune c);
int fl_wcwidth(Rune c);
int ftruncate(int f, off_t sz);

#if !defined(INITIAL_HEAP_SIZE)
#define INITIAL_HEAP_SIZE 16*1024*1024
#endif
#if !defined(ALLOC_LIMIT_TRIGGER)
#define ALLOC_LIMIT_TRIGGER INITIAL_HEAP_SIZE
#endif

#include "cc.h"
#include "mem.h"