Skip to content

Commit 5e750b8

Browse files
author
Siva Chandra Reddy
committed
[libc] Simplify generation of errno.h.
Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D140375
1 parent 35887ea commit 5e750b8

File tree

6 files changed

+88
-43
lines changed

6 files changed

+88
-43
lines changed

libc/config/linux/api.td

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ def NullMacro : MacroDef<"NULL"> {
4343
}];
4444
}
4545

46-
def ErrnoMacro : MacroDef<"errno"> {
47-
let Defn = [{
48-
extern _Thread_local int __llvmlibc_errno;
49-
#define errno __llvmlibc_errno
50-
}];
51-
}
52-
5346
def AssertAPI : PublicAPI<"assert.h"> {
5447
let Macros = [
5548
AssertMacro,
@@ -183,25 +176,6 @@ def TimeAPI : PublicAPI<"time.h"> {
183176
];
184177
}
185178

186-
def ErrnoAPI : PublicAPI<"errno.h"> {
187-
let Macros = [
188-
ErrnoMacro,
189-
// We largely depend on linux/errno.h to give us the
190-
// various error macro definitions. However, some libc
191-
// implementations have chosen to provide definitions
192-
// for some of the error macros to account for the ones
193-
// missing in linux/errno.h. There is no harm in doing
194-
// the same here if we define the macros only when they
195-
// are not already defined.
196-
MacroDefineIfNot<"ENOTSUP", "EOPNOTSUPP">,
197-
MacroDefineIfNot<"ECANCELED", "125">,
198-
MacroDefineIfNot<"EOWNERDEAD", "130">,
199-
MacroDefineIfNot<"ENOTRECOVERABLE", "131">,
200-
MacroDefineIfNot<"ERFKILL", "132">,
201-
MacroDefineIfNot<"EHWPOISON", "133">,
202-
];
203-
}
204-
205179
def SchedAPI : PublicAPI<"sched.h"> {
206180
let Types = ["pid_t", "size_t", "cpu_set_t"];
207181
}

libc/config/linux/errno.h.in

Lines changed: 0 additions & 11 deletions
This file was deleted.

libc/include/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,9 @@ add_gen_header(
128128
add_gen_header(
129129
errno
130130
DEF_FILE errno.h.def
131-
PARAMS
132-
platform_errno=../config/${LIBC_TARGET_OS}/errno.h.in
133131
GEN_HDR errno.h
134-
DATA_FILES
135-
../config/${LIBC_TARGET_OS}/errno.h.in
132+
DEPENDS
133+
.llvm-libc-macros.generic_error_number_macros
136134
)
137135

138136
add_gen_header(

libc/include/errno.h.def

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,39 @@
1111

1212
#include <__llvm-libc-common.h>
1313

14-
%%include_file(${platform_errno})
14+
#ifdef __linux__
1515

16-
%%public_api()
16+
#include <linux/errno.h>
17+
18+
#ifndef ERFKILL
19+
#define ERFKILL 132
20+
#endif // ERFKILL
21+
22+
#ifndef EOWNERDEAD
23+
#define EOWNERDEAD 130
24+
#endif // EOWNERDEAD
25+
26+
#ifndef EHWPOISON
27+
#define EHWPOISON 133
28+
#endif // EHWPOISON
29+
30+
#ifndef ECANCELED
31+
#define ECANCELED 125
32+
#endif // ECANCELED
33+
34+
#ifndef ENOTSUP
35+
#define ENOTSUP EOPNOTSUPP
36+
#endif // ENOTSUP
37+
38+
#ifndef ENOTRECOVERABLE
39+
#define ENOTRECOVERABLE 131
40+
#endif // ENOTRECOVERABLE
41+
42+
#else // __linux__
43+
#include <llvm-libc-macros/generic-error-number-macros.h>
44+
#endif
45+
46+
extern _Thread_local int __llvmlibc_errno;
47+
#define errno __llvmlibc_errno
1748

1849
#endif // LLVM_LIBC_ERRNO_H

libc/include/llvm-libc-macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
add_subdirectory(linux)
22

3+
add_header(
4+
generic_error_number_macros
5+
HDR
6+
generic-error-number-macros.h
7+
)
8+
39
add_header(
410
fcntl_macros
511
HDR
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===-- Definition of generic error number macros -------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __LLVM_LIBC_MACROS_GENERIC_ERROR_NUMBER_MACROS_H
10+
#define __LLVM_LIBC_MACROS_GENERIC_ERROR_NUMBER_MACROS_H
11+
12+
#define EPERM 1
13+
#define ENOENT 2
14+
#define ESRCH 3
15+
#define EINTR 4
16+
#define EIO 5
17+
#define ENXIO 6
18+
#define E2BIG 7
19+
#define ENOEXEC 8
20+
#define EBADF 9
21+
#define ECHILD 10
22+
#define EAGAIN 11
23+
#define ENOMEM 12
24+
#define EACCES 13
25+
#define EFAULT 14
26+
#define ENOTBLK 15
27+
#define EBUSY 16
28+
#define EEXIST 17
29+
#define EXDEV 18
30+
#define ENODEV 19
31+
#define ENOTDIR 20
32+
#define EISDIR 21
33+
#define EINVAL 22
34+
#define ENFILE 23
35+
#define EMFILE 24
36+
#define ENOTTY 25
37+
#define ETXTBSY 26
38+
#define EFBIG 27
39+
#define ENOSPC 28
40+
#define ESPIPE 29
41+
#define EROFS 30
42+
#define EMLINK 31
43+
#define EPIPE 32
44+
#define EDOM 33
45+
#define ERANGE 34
46+
47+
#endif // __LLVM_LIBC_MACROS_GENERIC_ERROR_NUMBER_MACROS_H

0 commit comments

Comments
 (0)