mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-19 07:05:45 +01:00
write a portable version of endian.h, to replace the system's endian.h.
utilising GNU C standard library for some of the functionality, or GNU C extensions.
This commit is contained in:
@@ -3,12 +3,12 @@
|
||||
#include "mcx.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <endian.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../util/compat/endian.h"
|
||||
#include "../util/intdef.h"
|
||||
|
||||
#define TABLE 0x2000 // table byte size
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
#include "nbt.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <endian.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../util/compat/endian.h"
|
||||
#include "../util/intdef.h"
|
||||
|
||||
#define MAX_DEPTH 512
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <assert.h>
|
||||
#include <endian.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../util/atrb.h"
|
||||
#include "../util/compat/endian.h"
|
||||
#include "../util/intdef.h"
|
||||
|
||||
/* NBT (named binary tag) is a tree data structure. Tags have a numeric type ID, name and a payload.
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#if __has_include(<endian.h>)
|
||||
#include <endian.h>
|
||||
#else
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
#define le16toh(x) __uint16_identity(x)
|
||||
#define le32toh(x) __uint32_identity(x)
|
||||
#define le64toh(x) __uint64_identity(x)
|
||||
#define htole16(x) __uint16_identity(x)
|
||||
#define htole32(x) __uint32_identity(x)
|
||||
#define htole64(x) __uint64_identity(x)
|
||||
#define be16toh(x) __builtin_bswap16(x)
|
||||
#define be32toh(x) __builtin_bswap32(x)
|
||||
#define be64toh(x) __builtin_bswap64(x)
|
||||
#define htobe16(x) __builtin_bswap16(x)
|
||||
#define htobe32(x) __builtin_bswap32(x)
|
||||
#define htobe64(x) __builtin_bswap64(x)
|
||||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
#define le16toh(x) __builtin_bswap16(x)
|
||||
#define le32toh(x) __builtin_bswap32(x)
|
||||
#define le64toh(x) __builtin_bswap64(x)
|
||||
#define htole16(x) __builtin_bswap16(x)
|
||||
#define htole32(x) __builtin_bswap32(x)
|
||||
#define htole64(x) __builtin_bswap64(x)
|
||||
#define be16toh(x) __uint16_identity(x)
|
||||
#define be32toh(x) __uint32_identity(x)
|
||||
#define be64toh(x) __uint64_identity(x)
|
||||
#define htobe16(x) __uint16_identity(x)
|
||||
#define htobe32(x) __uint32_identity(x)
|
||||
#define htobe64(x) __uint64_identity(x)
|
||||
#else
|
||||
#error machine architecture unsupported! Expected either big-endian or little-endian, make sure to use a compiler which defines __BYTE_ORDER__ (like clang or gcc)
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user