Skip to content

Commit 31c82ac

Browse files
committed
[libc][errno] Use macro instead of system header
1 parent 41574f5 commit 31c82ac

File tree

11 files changed

+118
-24
lines changed

11 files changed

+118
-24
lines changed

libc/include/errno.h.def

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,11 @@
1515

1616
#include <linux/errno.h>
1717

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-
3418
#ifndef ENOTSUP
3519
#define ENOTSUP EOPNOTSUPP
3620
#endif // ENOTSUP
3721

38-
#ifndef ENOTRECOVERABLE
39-
#define ENOTRECOVERABLE 131
40-
#endif // ENOTRECOVERABLE
22+
#include "llvm-libc-macros/linux/error-number-macros.h"
4123

4224
#else // __linux__
4325
#include "llvm-libc-macros/generic-error-number-macros.h"

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ add_macro_header(
3737
assert-macros.h
3838
)
3939

40+
add_macro_header(
41+
error_number_macros
42+
HDR
43+
error-number-macros.h
44+
)
45+
4046
add_macro_header(
4147
generic_error_number_macros
4248
HDR
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef LLVM_LIBC_MACROS_ERROR_NUMBER_MACROS_H
2+
#define LLVM_LIBC_MACROS_ERROR_NUMBER_MACROS_H
3+
4+
#ifdef __linux__
5+
#include "linux/error-number-macros.h"
6+
#endif
7+
8+
#endif // LLVM_LIBC_MACROS_ERROR_NUMBER_MACROS_H

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
add_header(
2+
error_number_macros
3+
HDR
4+
error-number-macros.h
5+
DEPENDS
6+
.mips.error_number_macros
7+
.sparc.error_number_macros
8+
)
9+
110
add_header(
211
fcntl_macros
312
HDR
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef LLVM_LIBC_MACROS_LINUX_ERROR_NUMBER_MACROS_H
2+
#define LLVM_LIBC_MACROS_LINUX_ERROR_NUMBER_MACROS_H
3+
4+
#if defined(__mips__)
5+
#include "mips/error-number-macros.h"
6+
7+
#elif defined(__sparc__)
8+
#include "sparc/error-number-macros.h"
9+
10+
#else
11+
#ifndef ECANCELED
12+
#define ECANCELED 125
13+
#endif // ECANCELED
14+
15+
#ifndef EOWNERDEAD
16+
#define EOWNERDEAD 130
17+
#endif // EOWNERDEAD
18+
19+
#ifndef ENOTRECOVERABLE
20+
#define ENOTRECOVERABLE 131
21+
#endif // ENOTRECOVERABLE
22+
23+
#ifndef ERFKILL
24+
#define ERFKILL 132
25+
#endif // ERFKILL
26+
27+
#ifndef EHWPOISON
28+
#define EHWPOISON 133
29+
#endif // EHWPOISON
30+
#endif
31+
32+
#endif // LLVM_LIBC_MACROS_LINUX_ERROR_NUMBER_MACROS_H
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_header(
2+
error_number_macros
3+
HDR
4+
error-number-macros.h
5+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef LLVM_LIBC_MACROS_LINUX_MIPS_ERROR_NUMBER_MACROS_H
2+
#define LLVM_LIBC_MACROS_LINUX_MIPS_ERROR_NUMBER_MACROS_H
3+
4+
#ifndef ECANCELED
5+
#define ECANCELED 158
6+
#endif // ECANCELED
7+
8+
#ifndef EOWNERDEAD
9+
#define EOWNERDEAD 165
10+
#endif // EOWNERDEAD
11+
12+
#ifndef ENOTRECOVERABLE
13+
#define ENOTRECOVERABLE 166
14+
#endif // ENOTRECOVERABLE
15+
16+
#ifndef ERFKILL
17+
#define ERFKILL 167
18+
#endif // ERFKILL
19+
20+
#ifndef EHWPOISON
21+
#define EHWPOISON 168
22+
#endif // EHWPOISON
23+
24+
#endif // LLVM_LIBC_MACROS_LINUX_MIPS_ERROR_NUMBER_MACROS_H
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_header(
2+
error_number_macros
3+
HDR
4+
error-number-macros.h
5+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef LLVM_LIBC_MACROS_LINUX_SPARC_ERROR_NUMBER_MACROS_H
2+
#define LLVM_LIBC_MACROS_LINUX_SPARC_ERROR_NUMBER_MACROS_H
3+
4+
#ifndef ECANCELED
5+
#define ECANCELED 127
6+
#endif // ECANCELED
7+
8+
#ifndef EOWNERDEAD
9+
#define EOWNERDEAD 132
10+
#endif // EOWNERDEAD
11+
12+
#ifndef ENOTRECOVERABLE
13+
#define ENOTRECOVERABLE 133
14+
#endif // ENOTRECOVERABLE
15+
16+
#ifndef ERFKILL
17+
#define ERFKILL 134
18+
#endif // ERFKILL
19+
20+
#ifndef EHWPOISON
21+
#define EHWPOISON 135
22+
#endif // EHWPOISON
23+
24+
#endif // LLVM_LIBC_MACROS_LINUX_SPARC_ERROR_NUMBER_MACROS_H

libc/src/errno/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ add_entrypoint_object(
1919
${full_build_flag}
2020
DEPENDS
2121
libc.include.errno
22+
libc.include.llvm-libc-macros.error_number_macros
23+
libc.include.llvm-libc-macros.generic_error_number_macros
2224
libc.src.__support.common
2325
)

libc/src/errno/libc_errno.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
#include "src/__support/macros/attributes.h"
1313
#include "src/__support/macros/properties/architectures.h"
1414

15-
// TODO: https://github.com/llvm/llvm-project/issues/80172
16-
// Separate just the definition of errno numbers in
17-
// include/llvm-libc-macros/* and only include that instead of the system
18-
// <errno.h>.
19-
#include <errno.h>
15+
#include <include/llvm-libc-macros/error-number-macros.h>
16+
#include <include/llvm-libc-macros/generic-error-number-macros.h>
2017

2118
// This header is to be consumed by internal implementations, in which all of
2219
// them should refer to `libc_errno` instead of using `errno` directly from

0 commit comments

Comments
 (0)