[libc] Add definitions of a few missing macros and types.
authorSiva Chandra Reddy <sivachandra@google.com>
Tue, 1 Nov 2022 22:27:21 +0000 (22:27 +0000)
committerSiva Chandra Reddy <sivachandra@google.com>
Wed, 2 Nov 2022 07:17:33 +0000 (07:17 +0000)
libc/config/linux/api.td
libc/include/CMakeLists.txt
libc/include/llvm-libc-macros/CMakeLists.txt
libc/include/llvm-libc-macros/linux/sys-wait-macros.h
libc/include/llvm-libc-macros/stdio-macros.h [new file with mode: 0644]
libc/include/llvm-libc-macros/stdlib-macros.h
libc/include/llvm-libc-types/CMakeLists.txt
libc/include/llvm-libc-types/sig_atomic_t.h [new file with mode: 0644]
libc/include/stdio.h.def
libc/spec/stdc.td

index a22b377..a84ab38 100644 (file)
@@ -106,6 +106,7 @@ def MathAPI : PublicAPI<"math.h"> {
     SimpleMacroDef<"MATH_ERREXCEPT", "2">,
     MathErrHandlingMacro,
 
+    SimpleMacroDef<"HUGE_VAL", "__builtin_huge_val()">,
     SimpleMacroDef<"INFINITY", "__builtin_inff()">,
     SimpleMacroDef<"NAN", "__builtin_nanf(\"\")">,
 
@@ -207,6 +208,7 @@ def SysMManAPI : PublicAPI<"sys/mman.h"> {
 
 def SignalAPI : PublicAPI<"signal.h"> {
   let Types = [
+    "sig_atomic_t",
     "sigset_t",
     "struct sigaction",
     "union sigval",
index 066c778..ac4e575 100644 (file)
@@ -144,10 +144,11 @@ add_gen_header(
     ../config/${LIBC_TARGET_OS}/signal.h.in
   DEPENDS
     .llvm-libc-macros.signal_macros
-    .llvm-libc-types.struct_sigaction
     .llvm-libc-types.__sighandler_t
-    .llvm-libc-types.stack_t
     .llvm-libc-types.sigset_t
+    .llvm-libc-types.sig_atomic_t
+    .llvm-libc-types.stack_t
+    .llvm-libc-types.struct_sigaction
     .llvm-libc-types.pid_t
 )
 
@@ -158,6 +159,7 @@ add_gen_header(
   DEPENDS
     .llvm_libc_common_h
     .llvm-libc-macros.file_seek_macros
+    .llvm-libc-macros.stdio_macros
     .llvm-libc-types.cookie_io_functions_t
     .llvm-libc-types.FILE
     .llvm-libc-types.size_t
index 7469145..fe2652a 100644 (file)
@@ -31,6 +31,12 @@ add_header(
 )
 
 add_header(
+  stdio_macros
+  HDR
+    stdio-macros.h
+)
+
+add_header(
   stdlib_macros
   HDR
     stdlib-macros.h
index aaafe42..ad66d05 100644 (file)
@@ -18,5 +18,7 @@
 #define WTERMSIG(status) (((status)&0x7F))
 #define WIFEXITED(status) (WTERMSIG(status) == 0)
 #define WEXITSTATUS(status) (((status)&0xFF00) >> 8)
+#define WIFSIGNALED(status)                                                    \
+  ((WTERMSIG(status) < 0x7F) && (WTERMSIG(status) > 0))
 
 #endif // __LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H
diff --git a/libc/include/llvm-libc-macros/stdio-macros.h b/libc/include/llvm-libc-macros/stdio-macros.h
new file mode 100644 (file)
index 0000000..b2c62ec
--- /dev/null
@@ -0,0 +1,14 @@
+//===-- Macros defined in stdio.h header file -----------------------------===//
+//
+// 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_MACROS_STDIO_MACROS_H
+#define __LLVM_LIBC_MACROS_STDIO_MACROS_H
+
+#define BUFSIZ 1024
+
+#endif // __LLVM_LIBC_MACROS_STDIO_MACROS_H
index 930938d..1c66a43 100644 (file)
@@ -9,6 +9,14 @@
 #ifndef __LLVM_LIBC_MACROS_STDLIB_MACROS_H
 #define __LLVM_LIBC_MACROS_STDLIB_MACROS_H
 
+#ifndef NULL
+#define __need_NULL
+#include <stddef.h>
+#endif // NULL
+
+#define EXIT_SUCCESS 0
+#define EXIT_FAILURE 1
+
 #define RAND_MAX 32767
 
 #endif // __LLVM_LIBC_MACROS_STDLIB_MACROS_H
index 4bd69be..7be2441 100644 (file)
@@ -62,6 +62,7 @@ add_header(ssize_t HDR ssize_t.h)
 add_header(struct_dirent HDR struct_dirent.h DEPENDS .ino_t .off_t)
 add_header(union_sigval HDR union_sigval.h)
 add_header(siginfo_t HDR siginfo_t.h DEPENDS .union_sigval .pid_t .uid_t)
+add_header(sig_atomic_t HDR sig_atomic_t.h)
 add_header(sigset_t HDR sigset_t.h DEPENDS libc.include.llvm-libc-macros.signal_macros)
 add_header(struct_sigaction HDR struct_sigaction.h DEPENDS .sigset_t .siginfo_t)
 add_header(struct_timespec HDR struct_timespec.h DEPENDS .time_t)
diff --git a/libc/include/llvm-libc-types/sig_atomic_t.h b/libc/include/llvm-libc-types/sig_atomic_t.h
new file mode 100644 (file)
index 0000000..324629c
--- /dev/null
@@ -0,0 +1,14 @@
+//===-- Definition of sig_atomic_t type -----------------------------------===//
+//
+// 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_TYPES_SIG_ATOMIC_T_H__
+#define __LLVM_LIBC_TYPES_SIG_ATOMIC_T_H__
+
+typedef int sig_atomic_t;
+
+#endif // __LLVM_LIBC_TYPES_SIG_ATOMIC_T_H__
index a643e22..5eb0e98 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <__llvm-libc-common.h>
 #include <llvm-libc-macros/file-seek-macros.h>
+#include <llvm-libc-macros/stdio-macros.h>
 
 %%public_api()
 
index 964b3e7..a7a9df4 100644 (file)
@@ -338,6 +338,7 @@ def StdC : StandardSpec<"stdc"> {
           Macro<"MATH_ERREXCEPT">,
           Macro<"math_errhandling">,
 
+          Macro<"HUGE_VAL">,
           Macro<"INFINITY">,
           Macro<"NAN">,
 
@@ -740,6 +741,7 @@ def StdC : StandardSpec<"stdc"> {
       ]
   >;
 
+  NamedType SigAtomicT = NamedType<"sig_atomic_t">;
   HeaderSpec Signal = HeaderSpec<
       "signal.h",
       [
@@ -756,6 +758,7 @@ def StdC : StandardSpec<"stdc"> {
       ],
       [
         SizeTType,
+        SigAtomicT,
         SigHandlerT,
       ],
       [], // Enumerations