shithub: sl

ref: 52d518b5e346b66e9023ec35101480f706810977
dir: /src/posix/platform.h/

View raw version
#pragma once

#define _XOPEN_SOURCE 700
#include <assert.h>
#include <ctype.h>
#if defined(__APPLE__)
#include <machine/endian.h>
#else
#include <endian.h>
#endif
#include <errno.h>
#include <fcntl.h>
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <stdbool.h>
#include <stdarg.h>
#include <stdio.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#include <wctype.h>
#include <wchar.h>

#if defined(__linux__)
#define __os_name__ "linux"
#elif defined(__OpenBSD__)
#define __os_name__ "openbsd"
#elif defined(__FreeBSD__)
#define __os_name__ "freebsd"
#elif defined(__NetBSD__)
#define __os_name__ "netbsd"
#elif defined(__DragonFly__)
#define __os_name__ "dragonflybsd"
#elif defined(__APPLE__)
#define __os_name__ "macosx"
#elif defined(__HAIKU__)
#define __os_name__ "haiku"
#else
#define __os_name__ "unknown"
#endif

extern char __os_version__[];
#define __os_version__ __os_version__

#ifndef __SIZEOF_POINTER__
#error pointer size unknown
#elif __SIZEOF_POINTER__ == 8
#define BITS64
#endif

#define nil NULL
#define USED(x) ((void)(x))
#define nelem(x) (int)(sizeof(x)/sizeof((x)[0]))

#define PATHSEP '/'
#define PATHSEPSTRING "/"
#define PATHLISTSEP ':'
#define PATHLISTSEPSTRING ":"
#define ISPATHSEP(c) ((c) == '/')

#if !defined(BYTE_ORDER)
#if !defined(__BYTE_ORDER)
#define LITTLE_ENDIAN 1234
#define BIG_ENDIAN 4321
#if defined(__LITTLE_ENDIAN__)
#define BYTE_ORDER LITTLE_ENDIAN
#else
#define BYTE_ORDER BIG_ENDIAN
#endif
#else
#define LITTLE_ENDIAN __LITTLE_ENDIAN
#define BIG_ENDIAN __BIG_ENDIAN
#define BYTE_ORDER __BYTE_ORDER
#endif
#endif

// FIXME: __clang__ because no idea how to check if ubsan is enabled.
#if !defined(__clang__) && (defined(__386__) || defined(__x86_64__) || defined(__aarch64__))
#define MEM_UNALIGNED_ACCESS
#endif

#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

#define fl_iswprint(r) iswprint(r)
#define fl_wcwidth(r) wcwidth(r)

#include "cc.h"
#include "mem.h"
#include "mp.h"
#include "utf.h"