Skip to content

Commit b98c190

Browse files
[libc][NFC] Switch use of errno in src/time and test/src/time to libc_errno.
Switch use of errno in src/time and test/src/time to libc_errno. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D145192
1 parent 7e770f9 commit b98c190

17 files changed

+35
-45
lines changed

libc/src/time/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ add_object_library(
99
HDRS
1010
time_utils.h
1111
DEPENDS
12-
libc.include.errno
1312
libc.include.time
1413
libc.src.errno.errno
1514
)
@@ -67,7 +66,6 @@ add_entrypoint_object(
6766
gettimeofday.h
6867
DEPENDS
6968
.clock_gettime
70-
libc.include.errno
7169
libc.include.time
7270
libc.include.sys_syscall
7371
libc.src.__support.OSUtil.osutil
@@ -104,7 +102,6 @@ add_entrypoint_object(
104102
mktime.h
105103
DEPENDS
106104
.time_utils
107-
libc.include.errno
108105
libc.include.time
109106
libc.src.errno.errno
110107
)
@@ -116,7 +113,6 @@ add_entrypoint_object(
116113
HDRS
117114
nanosleep.h
118115
DEPENDS
119-
libc.include.errno
120116
libc.include.time
121117
libc.include.sys_syscall
122118
libc.src.__support.OSUtil.osutil

libc/src/time/clock_gettime.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1212
#include "src/__support/common.h"
13+
#include "src/errno/libc_errno.h"
1314

14-
#include <errno.h>
1515
#include <sys/syscall.h> // For syscall numbers.
1616
#include <time.h>
1717

@@ -25,7 +25,7 @@ LLVM_LIBC_FUNCTION(int, clock_gettime,
2525
// A negative return value indicates an error with the magnitude of the
2626
// value being the error code.
2727
if (ret_val < 0) {
28-
errno = -ret_val;
28+
libc_errno = -ret_val;
2929
return -1;
3030
}
3131

libc/src/time/gettimeofday.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1212
#include "src/__support/common.h"
13+
#include "src/errno/libc_errno.h"
1314

14-
#include <errno.h>
1515
#include <sys/syscall.h> // For syscall numbers.
1616

1717
namespace __llvm_libc {
@@ -27,7 +27,7 @@ LLVM_LIBC_FUNCTION(int, gettimeofday,
2727
// A negative return value indicates an error with the magnitude of the
2828
// value being the error code.
2929
if (ret_val < 0) {
30-
errno = -ret_val;
30+
libc_errno = -ret_val;
3131
return -1;
3232
}
3333
tv->tv_sec = tp.tv_sec;

libc/src/time/linux/clock.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
#include "src/__support/CPP/limits.h"
1212
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1313
#include "src/__support/common.h"
14+
#include "src/errno/libc_errno.h"
1415

15-
#include <errno.h>
1616
#include <sys/syscall.h> // For syscall numbers.
1717
#include <time.h>
1818

@@ -23,7 +23,7 @@ LLVM_LIBC_FUNCTION(clock_t, clock, ()) {
2323
long ret_val = __llvm_libc::syscall_impl(
2424
SYS_clock_gettime, CLOCK_PROCESS_CPUTIME_ID, reinterpret_cast<long>(&ts));
2525
if (ret_val < 0) {
26-
errno = -ret_val;
26+
libc_errno = -ret_val;
2727
return clock_t(-1);
2828
}
2929

libc/src/time/linux/time.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1212
#include "src/__support/common.h"
13+
#include "src/errno/libc_errno.h"
1314

14-
#include <errno.h>
1515
#include <sys/syscall.h> // For syscall numbers.
1616
#include <time.h>
1717

@@ -23,7 +23,7 @@ LLVM_LIBC_FUNCTION(time_t, time, (time_t * tp)) {
2323
long ret_val = __llvm_libc::syscall_impl(SYS_clock_gettime, CLOCK_REALTIME,
2424
reinterpret_cast<long>(&ts));
2525
if (ret_val < 0) {
26-
errno = -ret_val;
26+
libc_errno = -ret_val;
2727
return -1;
2828
}
2929

libc/src/time/nanosleep.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
//===----------------------------------------------------------------------===//
99

1010
#include "src/time/nanosleep.h"
11+
1112
#include "include/sys/syscall.h" // For syscall numbers.
1213
#include "src/__support/OSUtil/syscall.h" // For syscall functions.
1314
#include "src/__support/common.h"
14-
15-
#include <errno.h>
15+
#include "src/errno/libc_errno.h"
1616

1717
namespace __llvm_libc {
1818

libc/src/time/time_utils.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111

1212
#include <stddef.h> // For size_t.
1313

14-
#include "include/errno.h"
15-
1614
#include "src/__support/common.h"
17-
#include "src/errno/llvmlibc_errno.h"
15+
#include "src/errno/libc_errno.h"
1816
#include "src/time/mktime.h"
1917

2018
#include <stdint.h>
@@ -86,11 +84,11 @@ extern int64_t update_from_seconds(int64_t total_seconds, struct tm *tm);
8684

8785
// POSIX.1-2017 requires this.
8886
LIBC_INLINE time_t out_of_range() {
89-
llvmlibc_errno = EOVERFLOW;
87+
libc_errno = EOVERFLOW;
9088
return static_cast<time_t>(-1);
9189
}
9290

93-
LIBC_INLINE void invalid_value() { llvmlibc_errno = EINVAL; }
91+
LIBC_INLINE void invalid_value() { libc_errno = EINVAL; }
9492

9593
LIBC_INLINE char *asctime(const struct tm *timeptr, char *buffer,
9694
size_t bufferLength) {

libc/test/src/time/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ add_libc_unittest(
6262
CXX_STANDARD
6363
20
6464
DEPENDS
65-
libc.include.errno
6665
libc.include.time
6766
libc.src.time.gettimeofday
6867
libc.src.time.nanosleep
68+
libc.src.errno.errno
6969
)
7070

7171
add_libc_unittest(
@@ -119,9 +119,9 @@ add_libc_unittest(
119119
CXX_STANDARD
120120
20
121121
DEPENDS
122-
libc.include.errno
123122
libc.include.time
124123
libc.src.time.nanosleep
124+
libc.src.errno.errno
125125
)
126126

127127
add_libc_unittest(
@@ -131,9 +131,9 @@ add_libc_unittest(
131131
SRCS
132132
time_test.cpp
133133
DEPENDS
134-
libc.include.errno
135134
libc.include.time
136135
libc.src.time.time
136+
libc.src.errno.errno
137137
)
138138

139139
add_libc_unittest(
@@ -143,7 +143,7 @@ add_libc_unittest(
143143
SRCS
144144
clock_test.cpp
145145
DEPENDS
146-
libc.include.errno
147146
libc.include.time
148147
libc.src.time.clock
148+
libc.src.errno.errno
149149
)

libc/test/src/time/asctime_r_test.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10+
#include "src/errno/libc_errno.h"
1011
#include "src/time/asctime_r.h"
1112
#include "src/time/time_utils.h"
1213
#include "test/UnitTest/Test.h"
@@ -27,17 +28,17 @@ static inline char *call_asctime_r(struct tm *tm_data, int year, int month,
2728
TEST(LlvmLibcAsctimeR, Nullptr) {
2829
char *result;
2930
result = __llvm_libc::asctime_r(nullptr, nullptr);
30-
ASSERT_EQ(EINVAL, llvmlibc_errno);
31+
ASSERT_EQ(EINVAL, libc_errno);
3132
ASSERT_STREQ(nullptr, result);
3233

3334
char buffer[TimeConstants::ASCTIME_BUFFER_SIZE];
3435
result = __llvm_libc::asctime_r(nullptr, buffer);
35-
ASSERT_EQ(EINVAL, llvmlibc_errno);
36+
ASSERT_EQ(EINVAL, libc_errno);
3637
ASSERT_STREQ(nullptr, result);
3738

3839
struct tm tm_data;
3940
result = __llvm_libc::asctime_r(&tm_data, nullptr);
40-
ASSERT_EQ(EINVAL, llvmlibc_errno);
41+
ASSERT_EQ(EINVAL, libc_errno);
4142
ASSERT_STREQ(nullptr, result);
4243
}
4344

libc/test/src/time/asctime_test.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "src/errno/libc_errno.h"
910
#include "src/time/asctime.h"
1011
#include "test/UnitTest/Test.h"
1112
#include "test/src/time/TmHelper.h"
@@ -21,7 +22,7 @@ static inline char *call_asctime(struct tm *tm_data, int year, int month,
2122
TEST(LlvmLibcAsctime, Nullptr) {
2223
char *result;
2324
result = __llvm_libc::asctime(nullptr);
24-
ASSERT_EQ(EINVAL, llvmlibc_errno);
25+
ASSERT_EQ(EINVAL, libc_errno);
2526
ASSERT_STREQ(nullptr, result);
2627
}
2728

@@ -39,7 +40,7 @@ TEST(LlvmLibcAsctime, InvalidWday) {
3940
0, // sec
4041
-1, // wday
4142
0); // yday
42-
ASSERT_EQ(EINVAL, llvmlibc_errno);
43+
ASSERT_EQ(EINVAL, libc_errno);
4344

4445
// Test with wday = 7.
4546
call_asctime(&tm_data,
@@ -51,7 +52,7 @@ TEST(LlvmLibcAsctime, InvalidWday) {
5152
0, // sec
5253
7, // wday
5354
0); // yday
54-
ASSERT_EQ(EINVAL, llvmlibc_errno);
55+
ASSERT_EQ(EINVAL, libc_errno);
5556
}
5657

5758
// Months are from January to December. Test passing invalid value in month.
@@ -68,7 +69,7 @@ TEST(LlvmLibcAsctime, InvalidMonth) {
6869
0, // sec
6970
4, // wday
7071
0); // yday
71-
ASSERT_EQ(EINVAL, llvmlibc_errno);
72+
ASSERT_EQ(EINVAL, libc_errno);
7273

7374
// Test with month = 13.
7475
call_asctime(&tm_data,
@@ -80,7 +81,7 @@ TEST(LlvmLibcAsctime, InvalidMonth) {
8081
0, // sec
8182
4, // wday
8283
0); // yday
83-
ASSERT_EQ(EINVAL, llvmlibc_errno);
84+
ASSERT_EQ(EINVAL, libc_errno);
8485
}
8586

8687
TEST(LlvmLibcAsctime, ValidWeekdays) {
@@ -208,6 +209,6 @@ TEST(LlvmLibcAsctime, Max64BitYear) {
208209
50, // sec
209210
2, // wday
210211
50); // yday
211-
ASSERT_EQ(EOVERFLOW, llvmlibc_errno);
212+
ASSERT_EQ(EOVERFLOW, libc_errno);
212213
ASSERT_STREQ(nullptr, result);
213214
}

libc/test/src/time/clock_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "src/time/clock.h"
1010
#include "test/UnitTest/Test.h"
1111

12-
#include <errno.h>
1312
#include <limits.h>
1413
#include <time.h>
1514

libc/test/src/time/difftime_test.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include "test/ErrnoSetterMatcher.h"
1313
#include "test/UnitTest/Test.h"
1414

15-
#include <errno.h>
16-
1715
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
1816
using __llvm_libc::time_utils::TimeConstants;
1917

libc/test/src/time/gettimeofday_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include <errno.h>
109
#include <time.h>
1110

1211
#include "src/time/gettimeofday.h"

libc/test/src/time/gmtime_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "src/errno/libc_errno.h"
910
#include "src/time/gmtime.h"
1011
#include "src/time/time_utils.h"
1112
#include "test/ErrnoSetterMatcher.h"
1213
#include "test/UnitTest/Test.h"
1314
#include "test/src/time/TmMatcher.h"
1415

15-
#include <errno.h>
1616
#include <limits.h>
1717

1818
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;
@@ -25,15 +25,15 @@ TEST(LlvmLibcGmTime, OutOfRange) {
2525
TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR);
2626
struct tm *tm_data = __llvm_libc::gmtime(&seconds);
2727
EXPECT_TRUE(tm_data == nullptr);
28-
EXPECT_EQ(llvmlibc_errno, EOVERFLOW);
28+
EXPECT_EQ(libc_errno, EOVERFLOW);
2929

30-
llvmlibc_errno = 0;
30+
libc_errno = 0;
3131
seconds = INT_MIN * static_cast<int64_t>(
3232
TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR) -
3333
1;
3434
tm_data = __llvm_libc::gmtime(&seconds);
3535
EXPECT_TRUE(tm_data == nullptr);
36-
EXPECT_EQ(llvmlibc_errno, EOVERFLOW);
36+
EXPECT_EQ(libc_errno, EOVERFLOW);
3737
}
3838

3939
TEST(LlvmLibcGmTime, InvalidSeconds) {

libc/test/src/time/mktime_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "test/src/time/TmHelper.h"
1414
#include "test/src/time/TmMatcher.h"
1515

16-
#include <errno.h>
1716
#include <limits.h>
1817

1918
using __llvm_libc::testing::ErrnoSetterMatcher::Fails;

libc/test/src/time/nanosleep_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10-
#include <errno.h>
1110
#include <time.h>
1211

12+
#include "src/errno/libc_errno.h"
1313
#include "src/time/nanosleep.h"
1414
#include "test/ErrnoSetterMatcher.h"
1515
#include "test/UnitTest/Test.h"
@@ -19,11 +19,11 @@ namespace cpp = __llvm_libc::cpp;
1919
TEST(LlvmLibcNanosleep, SmokeTest) {
2020
// TODO: When we have the code to read clocks, test that time has passed.
2121
using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
22-
errno = 0;
22+
libc_errno = 0;
2323

2424
struct timespec tim = {1, 500};
2525
struct timespec tim2 = {0, 0};
2626
int ret = __llvm_libc::nanosleep(&tim, &tim2);
27-
ASSERT_EQ(errno, 0);
27+
ASSERT_EQ(libc_errno, 0);
2828
ASSERT_EQ(ret, 0);
2929
}

libc/test/src/time/time_test.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "src/time/time_func.h"
1010
#include "test/UnitTest/Test.h"
1111

12-
#include <errno.h>
1312
#include <limits.h>
1413
#include <time.h>
1514

0 commit comments

Comments
 (0)