[libc] [llvm] Add sysexits.h header with BSD exit codes (total-18) (PR #126112)

Ajay Raj via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 11 02:35:14 PST 2025


https://github.com/ajayrajsaini updated https://github.com/llvm/llvm-project/pull/126112

>From d4d32a4022feba5d656e1a38a6f8ef71fecdb5f9 Mon Sep 17 00:00:00 2001
From: Ajay Raj <ajayrajsaini333 at gmail.com>
Date: Fri, 7 Feb 2025 00:23:49 +0530
Subject: [PATCH 1/3] Add sysexits.h header with BSD exit codes (total-18)

---
 llvm/include/llvm/Support/SysExits.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 llvm/include/llvm/Support/SysExits.h

diff --git a/llvm/include/llvm/Support/SysExits.h b/llvm/include/llvm/Support/SysExits.h
new file mode 100644
index 000000000000000..06b3ada101756e7
--- /dev/null
+++ b/llvm/include/llvm/Support/SysExits.h
@@ -0,0 +1,24 @@
+#ifndef SYSEXITS_H
+#define SYSEXITS_H
+
+// BSD Exit Codes (18 total) — These are the commonly used exit codes without POSIX dependencies
+#define EX_OK         0    // Successful termination
+#define EX_USAGE      64   // Command line usage error
+#define EX_DATAERR    65   // Data format error
+#define EX_NOINPUT    66   // Cannot open input
+#define EX_NOUSER     67   // Addressee unknown
+#define EX_NOHOST     68   // Host name unknown
+#define EX_UNAVAILABLE 69  // Service unavailable
+#define EX_SOFTWARE   70   // Internal software error
+#define EX_OSERR      71   // Operating system error
+#define EX_OSFILE     72   // System file error
+#define EX_CANTCREAT  73   // Cannot create (user) output file
+#define EX_IOERR      74   // Input/output error
+#define EX_TEMPFAIL   75   // Temporary failure, try again
+#define EX_PROTOCOL   76   // Remote protocol error
+#define EX_NOPERM     77   // Permission denied
+#define EX_CONFIG     78   // Configuration error
+#define EX_INTERNAL   80   // Internal error
+#define EX_INVALIDARG 81   // Invalid argument
+
+#endif // SYSEXITS_H

>From e46aba5bdfeb5aa052f54a26610197484c1b95ff Mon Sep 17 00:00:00 2001
From: Ajay Raj <ajayrajsaini333 at gmail.com>
Date: Sat, 8 Feb 2025 21:33:46 +0530
Subject: [PATCH 2/3] moved SysExits.h to /libc/lib

---
 {llvm/include/llvm/Support => libc/lib}/SysExits.h | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename {llvm/include/llvm/Support => libc/lib}/SysExits.h (100%)

diff --git a/llvm/include/llvm/Support/SysExits.h b/libc/lib/SysExits.h
similarity index 100%
rename from llvm/include/llvm/Support/SysExits.h
rename to libc/lib/SysExits.h

>From 32f2156d3e036a2672a0ffbf8090accf4f5331e5 Mon Sep 17 00:00:00 2001
From: Ajay Raj <ajayrajsaini333 at gmail.com>
Date: Tue, 11 Feb 2025 10:10:37 +0000
Subject: [PATCH 3/3] added sysexits.h successfully

---
 libc/config/linux/aarch64/headers.txt           |  1 +
 libc/config/linux/x86_64/headers.txt            |  1 +
 libc/include/CMakeLists.txt                     | 10 ++++++++++
 libc/include/llvm-libc-macros/CMakeLists.txt    |  7 +++++++
 .../llvm-libc-macros/sysexits-macros.h}         |  7 +++----
 libc/include/sysexits.h.def                     | 17 +++++++++++++++++
 libc/include/sysexits.yaml                      |  9 +++++++++
 7 files changed, 48 insertions(+), 4 deletions(-)
 rename libc/{lib/SysExits.h => include/llvm-libc-macros/sysexits-macros.h} (85%)
 create mode 100644 libc/include/sysexits.h.def
 create mode 100644 libc/include/sysexits.yaml

diff --git a/libc/config/linux/aarch64/headers.txt b/libc/config/linux/aarch64/headers.txt
index 05f15a0e4e5cbb5..661693fcc96f900 100644
--- a/libc/config/linux/aarch64/headers.txt
+++ b/libc/config/linux/aarch64/headers.txt
@@ -32,6 +32,7 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.unistd
     libc.include.wchar
     libc.include.uchar
+    libc.include.sysexits
 
     libc.include.sys_ioctl
     # Disabled due to epoll_wait syscalls not being available on this platform.
diff --git a/libc/config/linux/x86_64/headers.txt b/libc/config/linux/x86_64/headers.txt
index 8750100302ea7e8..c8ed37cce08f5a9 100644
--- a/libc/config/linux/x86_64/headers.txt
+++ b/libc/config/linux/x86_64/headers.txt
@@ -56,4 +56,5 @@ set(TARGET_PUBLIC_HEADERS
     libc.include.sys_types
     libc.include.sys_utsname
     libc.include.sys_wait
+    libc.include.sysexits
 )
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index e5ceea360d3965e..03697c08b5c5ef8 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -159,6 +159,16 @@ add_header_macro(
     .llvm-libc-types.stdfix-types
 )
 
+
+add_header_macro(
+  sysexits
+  ../libc/include/sysexits.yaml
+  sysexits.h
+  DEPENDS
+    .llvm-libc-macros.sysexits_macros
+)
+
+
 # TODO: This should be conditional on POSIX networking being included.
 file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/arpa)
 
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 9d5d9f65442889a..6769e13a12e4473 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -321,3 +321,10 @@ add_macro_header(
   HDR
     pthread-macros.h
 )
+
+add_macro_header(
+  sysexits_macros
+  HDR
+    sysexits-macros.h
+)
+
diff --git a/libc/lib/SysExits.h b/libc/include/llvm-libc-macros/sysexits-macros.h
similarity index 85%
rename from libc/lib/SysExits.h
rename to libc/include/llvm-libc-macros/sysexits-macros.h
index 06b3ada101756e7..747f1b68b901866 100644
--- a/libc/lib/SysExits.h
+++ b/libc/include/llvm-libc-macros/sysexits-macros.h
@@ -1,7 +1,6 @@
-#ifndef SYSEXITS_H
-#define SYSEXITS_H
+#ifndef SYSEXITS_MACROS_H
+#define SYSEXITS_MACROS_H
 
-// BSD Exit Codes (18 total) — These are the commonly used exit codes without POSIX dependencies
 #define EX_OK         0    // Successful termination
 #define EX_USAGE      64   // Command line usage error
 #define EX_DATAERR    65   // Data format error
@@ -21,4 +20,4 @@
 #define EX_INTERNAL   80   // Internal error
 #define EX_INVALIDARG 81   // Invalid argument
 
-#endif // SYSEXITS_H
+#endif // SYSEXITS_MACROS_H
diff --git a/libc/include/sysexits.h.def b/libc/include/sysexits.h.def
new file mode 100644
index 000000000000000..58e65a62f4903d3
--- /dev/null
+++ b/libc/include/sysexits.h.def
@@ -0,0 +1,17 @@
+//===-- POSIX header sysexits.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_SYSEXITS_H
+#define LLVM_LIBC_SYSEXITS_H
+
+#include "__llvm-libc-common.h"
+#include "llvm-libc-macros/sysexits-macros.h"
+
+%%public_api()
+
+#endif // LLVM_LIBC_SYSEXITS_H
+
diff --git a/libc/include/sysexits.yaml b/libc/include/sysexits.yaml
new file mode 100644
index 000000000000000..3232016300fe22f
--- /dev/null
+++ b/libc/include/sysexits.yaml
@@ -0,0 +1,9 @@
+header: sysexits.h
+header_template: sysexits.h.def
+standards:
+  - POSIX
+macros: []
+types: []
+enums: []
+objects: []
+functions: []



More information about the llvm-commits mailing list