shithub: femtolisp

ref: 20488fc4915662e0ec50bb8c4ebc2609d6e110b4
dir: /posix/platform.h/

View raw version
#define _XOPEN_SOURCE 700
#include <assert.h>
#include <ctype.h>
#include <endian.h>
#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"
#else
#define __os_name__ "unknown"
#endif

#define MEM_ALLOC(n) malloc((size_t)(n))
#define MEM_REALLOC(p, n) realloc((p), (size_t)(n))
#define MEM_FREE(x) free(x)
#define MEM_STRDUP(s) strdup(s)

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

#define sadd_overflow __builtin_add_overflow
#define sadd_overflow_64 __builtin_add_overflow
#define smul_overflow_64 __builtin_mul_overflow

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

#ifdef __GNUC__
#define __unlikely(x) __builtin_expect(!!(x), 0)
#define __likely(x) __builtin_expect(!!(x), 1)
#endif

#ifdef HAVE_BYTESWAP
#include <byteswap.h>
#else
#define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
#define bswap_32(x) \
    ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
    (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
#define bswap_64(x) \
    (uint64_t)bswap_32((x) & 0xffffffffULL)<<32 | \
    (uint64_t)bswap_32(((x)>>32) & 0xffffffffULL)
#endif

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

#ifndef BYTE_ORDER
#define LITTLE_ENDIAN __LITTLE_ENDIAN
#define BIG_ENDIAN __BIG_ENDIAN
#define BYTE_ORDER __BYTE_ORDER
#endif

#include "mp.h"
#include "utf.h"

#ifndef HAVE_BITREVERSE32
uint32_t __builtin_bitreverse32(uint32_t x);
#endif