-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[libc] implement template functions for localtime #110363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zimirza
wants to merge
226
commits into
llvm:main
Choose a base branch
from
zimirza:localtime_107597
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+448
−6
Open
Changes from all commits
Commits
Show all changes
226 commits
Select commit
Hold shift + click to select a range
a4d501c
[libc] implement localtime
221d2bc
[libc] implement localtime
90ddc6d
[libc] implement localtime
9dd0690
[libc] implement localtime
e88e589
[libc] implement localtime
0ca877f
[libc] implement localtime
7ebb945
[libc] implement localtime
ce7edf9
localtime_s is for windows only, implement localtime_s on gnu/linux for
2082bee
fix: localtime_s
385bed6
fix: path for mktime
b0efb23
fix: localtime_s and dst function
95752bf
added tests for localtime_r
5950145
format code with clang-format
6bfb76e
refactor: timezone
6e3614d
removing mktime as dependency to localtime_s
ee28f97
revert ctime tests
8fbb435
revert ctime_r tests
cce348e
fix: daylight saving time
39c375b
update documentation for libc
04fe862
refactor: file read
8050b80
fix: file read
4b95085
fix: timezone char length
zimirza 30b94e1
timezone implementation
b858ed3
format code with clang-format
a771ae1
use stack allocation of memory instead of heap allocation
8709b2a
remove `free` function because stack allocation of memory is now used
b617cae
added more timezones
299317c
added more timezones
2fd327d
refactor to parse `/etc/localtime`
8d26882
parse `/etc/localtime` implementation
072f090
add support for `tzfile` v3
c4225a6
add `close` function
22d5647
add support for `tzfile` version 4
89e605e
fix: bytes for timezone file
5129e61
fix: merge from main branch
40e2e8f
define structs for timezone data
8107ae2
use pointers in struct
f4d2a49
refactor: get timezone data from tzfile
f4c22bf
refactor: rename function since it returns tzset struct
8e2ec92
update struct fields with additional fields and parse timezone data
81650dd
remove last char in timezone text
6b576c7
use `open` instead of `fopen`
e3d5950
use `static` and add number of transitions times for timezone
f664276
format code with clang-format
71153b9
refactor: parse of tzset file
90a1611
refactor: parse of offsets
da91687
refactor: parse of offsets
19f756b
use timezone implementation for localtime function implementation
03e7627
format code with clang-format
7ce31da
add header file for time_utils in asctime_test
7c34853
fix function name for asctime
6e8220c
fix: add `get_tzset` function to time_utils header file
858f8c4
fix: add timezone header file to time_utils header file
19a94e5
fix: tzet function in time_utils header file
003c050
fix: add timezone header file to tests
1f90338
fix: add header file for size_t
3556f4f
add todo in tests
b7201cb
add timezone to dependencies for tests
1549104
fix path for timezone header file for tests
9a12c24
format code with clang-format
69d1b90
fix dependencies for tests
c53dab0
add header file for size_t
9d65255
add timezone header file to gmtime tests
074e31e
format code with clang-format
09aba03
add timezone to gmtime tests
ecdab14
format code with clang-format
fc98df6
add timezone to mktime
2f1ea3d
add timezone to gmtime
aab0bd5
add timezone to mktime
a0edf88
use `static_cast`
309746c
fix tests for timezone
aae094b
refactor: move definitions to scope
76d0784
format code with clang-format
4df6eac
fix: dependencies for timezone for tests
43301b3
fix: tests
3011ffa
refactor: fix tests
776afe6
refactor: localtime
d730a92
uncomment tests for asctime
f896a65
undo asctime
891c06b
format code with clang-format
a35ed74
undo asctime
5bfde5d
fix: ctime_r
5bb0514
refactor: use `openfile`
99af1e7
fix: add header file for time_utils in localtime
d8126c1
fix localtime
083389c
fix: fixed tests for asctime and removed unnecessary header include
3434b04
refactor: move linux specific implementation to libc/src/time/linux/
2bd53a8
format code with clang-format
5b0e39d
fix: tests
9ead91c
fix: tests
ee617ad
fix: add if macro for linux implementations
abfc697
fix: check if timer variable is nullptr
7a36e3e
fix: return type for localtime_s implementation
eeafc70
fix: tests for difftime
514c153
use LIBC_TARGET_OS for platform independent implementations
6cb524b
fix tests for clock
e6d5010
add localtime
ba6d3a8
remove implementation for a different pull request
8986bce
remove implementation for a different pull request
35e1e7f
remove unit tests for a different pull request
106a389
uncheck ctime and localtime in docs
eed8762
remove entrypoints
057de25
fix merge and tests
a184e9c
format code with clang-format
1a0efb6
fix merge and time
4355e2f
add fopen to mktime
6632dae
comment out offset and isdst
7905d54
update time
f25d380
uncomment get env var function and fix tests
adc641e
add unistd.h to tests
bb3e789
removed time_t.h from localtime_utils
f1e95fa
fix: time
9293534
tmp
88ff1a4
environment variables is only tested on gnu/linux
077611a
fix: environment variables
8479729
remove system header file for time.h
zimirza 6c64877
remove local time.h header file and add system time.h header file
zimirza 734a687
use system header files for integer types
zimirza 9f84b54
undo cmake file for tests
zimirza 425a9d9
undo header include for tests
zimirza ec4b06d
undo header include and fixed ctime header include
zimirza e44db21
undo
zimirza ee72a1c
undo
zimirza c5ddcda
fixed header include for ctime_r tests
zimirza 55467aa
mktime requires fopen
zimirza ad11374
add file dependency
zimirza 617ae23
fix: merge from main branch
zimirza 32e5c79
remove file dependency from ctime_r
zimirza d508cc3
removed localtime_s for this pull request
zimirza e4133b7
remove localtime_s for this pull request
zimirza ce3b89d
removed localtime_s for this pull request
zimirza 8a32b66
removed localtime_s for this pull request
zimirza 481c0a7
moved linux specific code
zimirza 03d2bea
removed localtime_utc function and fixed localtime function
zimirza 986472f
use `getenv` implementation of using `unistd.h`
zimirza 027763c
fix: function signature for localtime
zimirza 5b991a7
revert: function signature for `update_for_seconds`
zimirza 99b81c6
format code with clang-format
zimirza 5900f59
remove `fopen`
zimirza 588c527
fix: environment pointer
zimirza 47fd94a
fix: environment pointer
zimirza 79df4ac
format code with clang-format
zimirza 6f6418b
remove file.h from timezone
zimirza 155fd73
use FILE
zimirza 594b245
include file
zimirza ef93900
format code with clang-format
zimirza c820c04
revert ctime_r_test and remove dst function for another pull request
zimirza e644279
remove constant for a different pull request
zimirza 9b16b05
revert ctime and remove timezone implementation
zimirza 78bc296
add `fopen` to `ctime_r`
zimirza 67e52dc
revert: ctime
zimirza b5cbc48
revert ctime unit tests
zimirza 47510cd
revert: ctime unit tests
zimirza 53d7a2a
revert: ctime
zimirza 3386bd5
revert: update_from_seconds
zimirza c105779
revert: update_from_seconds
zimirza 94e69fa
rerun github actions
zimirza 0d2d560
remove localtime_macros.h
zimirza 1728f2e
function `get_localtime` should not be `extern`
zimirza 9e6e9b3
remove `get_env_var` function from this pull request
zimirza 86a5e91
use c++-style references
zimirza a5fa5a2
format code with clang-format
zimirza fb95bcc
use c++ style references
zimirza 7a70610
removed timezone implementation definitions
zimirza e391fe8
removed app.h from time_utils.cpp
zimirza db9e29c
fix: code format
zimirza 1fe5249
use localtime_internal instead of gmtime_internal
zimirza bf0c2e3
remove comment
zimirza a6a15cc
add struct for tzset
zimirza 389711f
fix: pointers
zimirza e2bba73
removed invalid value from localtime_internal function
zimirza 73591cb
rename and add todo
zimirza 6d072c6
add message to stderr for timezone database implementation
zimirza 17bcf44
add localtime and localtime_r to x86_64 entrypoints
zimirza b483ac7
removed unused variable
zimirza 207b691
remove localtime_utils and timezone from this patch
zimirza 0fe6296
update dependencies for tests
zimirza 6159ed0
remove c++ version dependency
zimirza 95f174e
add localtime and localtime_r to entrypoint objects for linux
zimirza 3861d2d
update comment
zimirza b4d011c
removed dependencies for baremetal implementation of localtime and added
zimirza f3ddce0
add localtime and localtime_r to aarch64 baremetal entrypoints
zimirza b6334f4
remove fortify source and fortify level options
zimirza a99e1f4
fix: dependencies for localtime baremetal implementation
zimirza ce8c367
fix: localtime implementation for baremetal
zimirza 3717dea
add implementation for localtime_r for baremetal
zimirza 8a6caec
remove extern inlines from localtime overlay
zimirza 9221ca3
remove extern inline from localtime overlay
zimirza 8c4a713
add extern inlines and add localtime_r to localtime overlay
zimirza 895895e
fix: dependencies for localtime and localtime_r
zimirza 1282352
remove stderr message
zimirza 17ac718
remove TmHelper.h from localtime and localtime_r tests
zimirza 17be9c7
move localtime.cpp and localtime_r.cpp to time/ instead of time/linux/
zimirza ed0a917
update CMakeFiles.txt for linux
zimirza d18638f
update CMakeFiles.txt for time
zimirza 2815947
update tests for localtime and localtime_r
zimirza 7a54ff7
update localtime and localtime_r
zimirza 2a03937
format code with clang-format
zimirza 8399219
include common.h first
zimirza e9ad746
include common.h first
zimirza 8054387
move including of common.h to localtime.h and localtime_r.h
zimirza 6883736
rename variables
zimirza 9ce9b13
use `LIBC_CRASH_ON_NULLPTR` instead of returning `nullptr`
zimirza 00bff09
add headers for time_utils.h
zimirza ec6a05c
add includes for struct_tm and time_t
zimirza 8443717
format code with clang-format
zimirza 3630c56
update CMakeLists file for tests for localtime
zimirza a8f7457
add tests for localtime and localtime_r
zimirza aafcf1d
use `LIBC_CRASH_ON_NULLPTR` for localtime and localtime_r
zimirza 77d29e2
format code with clang-format
zimirza e26d5fe
add `LIBC_CRASH_ON_NULLPTR` for struct
zimirza 2ad113d
fix tests for localtime_r
zimirza 9f68eea
format code with clang-format
zimirza c05de05
add tests for nullptr
zimirza efa0372
format code with clang-format
zimirza 2e11cb4
add localtime and localtime_r to docs
zimirza bbc3bee
add includes to `struct tm` and `time_t` for localtime and localtime_r
zimirza 5ae0fab
fix: rebase from main branch for time.rst file
zimirza da8d1ff
fix: rebase from main branch - add newline char in time.rst file
zimirza edfee68
Revert "fix: rebase from main branch - add newline char in time.rst f…
zimirza 9d10136
fix: rebase from main branch
zimirza 6592c1f
fix: rebase from main branch
zimirza 6cc6dff
fix: rebase from main branch
zimirza 1d3071f
use `WITH_SIGNAL` in `nullptr` tests for localtime and localtime_r
zimirza edc30fc
format code with clang-format
zimirza dd7e206
add time_utils as dependency to localtime and localtime_r
zimirza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//===-- Including localtime.h in overlay mode -----------------------------===// | ||
// | ||
// 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_HDR_LOCALTIME_OVERLAY_H | ||
#define LLVM_LIBC_HDR_LOCALTIME_OVERLAY_H | ||
|
||
#ifdef LIBC_FULL_BUILD | ||
#error "This header should only be included in overlay mode" | ||
#endif | ||
|
||
// Overlay mode | ||
|
||
// glibc <unistd.h> header might provide extern inline definitions for few | ||
// functions, causing external alias errors. They are guarded by | ||
// `__USE_EXTERN_INLINES` macro. | ||
|
||
#ifdef __USE_EXTERN_INLINES | ||
#define LIBC_OLD_USE_EXTERN_INLINES | ||
#undef __USE_EXTERN_INLINES | ||
#endif | ||
|
||
#ifndef __NO_INLINE__ | ||
#define __NO_INLINE__ 1 | ||
#define LIBC_SET_NO_INLINE | ||
#endif | ||
|
||
#include <localtime.h> | ||
#include <localtime_r.h> | ||
|
||
#ifdef LIBC_SET_NO_INLINE | ||
#undef __NO_INLINE__ | ||
#undef LIBC_SET_NO_INLINE | ||
#endif | ||
|
||
#ifdef LIBC_OLD_USE_EXTERN_INLINES | ||
#define __USE_EXTERN_INLINES | ||
#undef LIBC_OLD_USE_EXTERN_INLINES | ||
#endif | ||
|
||
#endif // LLVM_LIBC_HDR_LOCALTIME_OVERLAY_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===-- Implementation of localtime for baremetal -------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/time/localtime.h" | ||
#include "hdr/types/struct_tm.h" | ||
#include "hdr/types/time_t.h" | ||
#include "src/time/time_utils.h" | ||
zimirza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(struct tm *, localtime, (time_t *timer)) { | ||
static struct tm tm_out; | ||
|
||
return time_utils::localtime_internal(timer, &tm_out); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===-- Implementation of localtime_r for baremetal -----------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/time/localtime_r.h" | ||
#include "hdr/types/struct_tm.h" | ||
#include "hdr/types/time_t.h" | ||
#include "src/__support/macros/null_check.h" | ||
#include "src/time/time_utils.h" | ||
zimirza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(struct tm *, localtime_r, | ||
(const time_t *timer, struct tm *buf)) { | ||
LIBC_CRASH_ON_NULLPTR(timer); | ||
|
||
return time_utils::localtime_internal(timer, buf); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===-- Linux implementation of the localtime function --------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/time/localtime.h" | ||
#include "hdr/types/struct_tm.h" | ||
#include "hdr/types/time_t.h" | ||
#include "src/__support/macros/null_check.h" | ||
#include "src/time/time_utils.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(struct tm *, localtime, (const time_t *timer)) { | ||
LIBC_CRASH_ON_NULLPTR(timer); | ||
|
||
static struct tm tm_out; | ||
return time_utils::localtime_internal(timer, &tm_out); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===-- Implementation header of localtime ----------------------*- C++ -*-===// | ||
// | ||
// 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_SRC_TIME_LOCALTIME_H | ||
#define LLVM_LIBC_SRC_TIME_LOCALTIME_H | ||
|
||
#include "hdr/types/struct_tm.h" | ||
#include "hdr/types/time_t.h" | ||
#include "src/__support/common.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
struct tm *localtime(const time_t *timer); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_TIME_LOCALTIME_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//===-- Linux implementation of localtime_r function ----------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/time/localtime_r.h" | ||
#include "hdr/types/struct_tm.h" | ||
#include "hdr/types/time_t.h" | ||
#include "src/__support/macros/null_check.h" | ||
#include "src/time/time_utils.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(struct tm *, localtime_r, | ||
(const time_t *timer, struct tm *buf)) { | ||
LIBC_CRASH_ON_NULLPTR(timer); | ||
LIBC_CRASH_ON_NULLPTR(buf); | ||
|
||
return time_utils::localtime_internal(timer, buf); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===-- Implementation header of localtime_r --------------------*- C++ -*-===// | ||
// | ||
// 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_SRC_TIME_LOCALTIME_R_H | ||
#define LLVM_LIBC_SRC_TIME_LOCALTIME_R_H | ||
|
||
#include "hdr/types/struct_tm.h" | ||
#include "hdr/types/time_t.h" | ||
#include "src/__support/common.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
struct tm *localtime_r(const time_t *timer, struct tm *buf); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_TIME_LOCALTIME_R_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.