Initial commit of mktime.
authorRaman Tenneti <rtenneti@google.com>
Tue, 1 Dec 2020 05:06:47 +0000 (21:06 -0800)
committerRaman Tenneti <rtenneti@google.com>
Tue, 1 Dec 2020 05:07:16 +0000 (21:07 -0800)
commit6f0f844e9af98dc935f80d8149f6e4fcebddf8f1
treea71936287cbe416a103acaca96635b0abc000b62
parent40659cd2c6f4347650d477a16e0cf60ce4401fa6
Initial commit of mktime.

This introduces mktime to LLVM libc, based on C99/C2X/Single Unix Spec.

Co-authored-by: Jeff Bailey <jeffbailey@google.com>
This change doesn't handle TIMEZONE,  tm_isdst and leap seconds.  It returns -1 for invalid dates. I have verified the return results for all the possible dates with glibc's mktime.

TODO:
+ Handle leap seconds.
+ Handle out of range time and date values that don't overflow or underflow.
+ Implement the following suggestion Siva - As we start accumulating the seconds, we should be able to check if the next amount of seconds to be added can lead to an overflow. If it does, return the overflow value.  If not keep accumulating. The benefit is that, we don't have to validate every input, and also do not need the special cases for sizeof(time_t) == 4.
+ Handle timezone and update of tm_isdst

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D91551
14 files changed:
libc/config/linux/api.td
libc/config/linux/x86_64/entrypoints.txt
libc/config/linux/x86_64/headers.txt
libc/include/CMakeLists.txt
libc/include/time.h.def [new file with mode: 0644]
libc/spec/spec.td
libc/spec/stdc.td
libc/src/CMakeLists.txt
libc/src/time/CMakeLists.txt [new file with mode: 0644]
libc/src/time/mktime.cpp [new file with mode: 0644]
libc/src/time/mktime.h [new file with mode: 0644]
libc/test/src/CMakeLists.txt
libc/test/src/time/CMakeLists.txt [new file with mode: 0644]
libc/test/src/time/mktime_test.cpp [new file with mode: 0644]