[libc-commits] [libc] [libc] add endian.h as specified in POSIX.1-2024 (PR #99768)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Sat Jul 20 08:48:09 PDT 2024


https://github.com/SchrodingerZhu created https://github.com/llvm/llvm-project/pull/99768

None

>From a99e723f39e061eb41afc776a97f2975b666c6a5 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <i at zhuyi.fan>
Date: Sat, 20 Jul 2024 08:47:14 -0700
Subject: [PATCH] [libc] add endian.h as specified in POSIX.1-2024

---
 libc/include/endian.h.def                     | 21 +++++++++++++++++++
 libc/include/llvm-libc-macros/endian-macros.h |  8 +++++++
 2 files changed, 29 insertions(+)
 create mode 100644 libc/include/endian.h.def
 create mode 100644 libc/include/llvm-libc-macros/endian-macros.h

diff --git a/libc/include/endian.h.def b/libc/include/endian.h.def
new file mode 100644
index 0000000000000..19625ad6c1790
--- /dev/null
+++ b/libc/include/endian.h.def
@@ -0,0 +1,21 @@
+//===-- POSIX header endian.h ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_ENDIAN_H
+#define LLVM_LIBC_ENDIAN_H
+
+#include "__llvm-libc-common.h"
+#include "llvm-libc-macros/endian-macros.h"
+
+// POSIX.1-2024
+// Inclusion of the <endian.h> header may also make visible all symbols from <stdint.h>.
+#include <stdint.h>
+
+%%public_api()
+
+#endif // LLVM_LIBC_ENDIAN_H
diff --git a/libc/include/llvm-libc-macros/endian-macros.h b/libc/include/llvm-libc-macros/endian-macros.h
new file mode 100644
index 0000000000000..0acef158a3c78
--- /dev/null
+++ b/libc/include/llvm-libc-macros/endian-macros.h
@@ -0,0 +1,8 @@
+#ifndef LLVM_LIBC_MACROS_ENDIAN_MACROS_H
+#define LLVM_LIBC_MACROS_ENDIAN_MACROS_H
+
+#define BYTE_ORDER __BYTE_ORDER__
+#define BIG_ENDIAN __ORDER_BIG_ENDIAN__
+#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
+
+#endif // LLVM_LIBC_MACROS_ENDIAN_MACROS_H



More information about the libc-commits mailing list