diff --git a/kernel/kernel/FS/FAT/Inode.cpp b/kernel/kernel/FS/FAT/Inode.cpp index 642ec785..49d12f2a 100644 --- a/kernel/kernel/FS/FAT/Inode.cpp +++ b/kernel/kernel/FS/FAT/Inode.cpp @@ -30,19 +30,19 @@ namespace Kernel timespec FATInode::atime() const { - uint64_t epoch = fat_date_to_epoch(m_entry.last_access_date, {}); + const time_t epoch = fat_date_to_epoch(m_entry.last_access_date, {}); return timespec { .tv_sec = epoch, .tv_nsec = 0 }; } timespec FATInode::mtime() const { - uint64_t epoch = fat_date_to_epoch(m_entry.write_date, m_entry.write_time); + const time_t epoch = fat_date_to_epoch(m_entry.write_date, m_entry.write_time); return timespec { .tv_sec = epoch, .tv_nsec = 0 }; } timespec FATInode::ctime() const { - uint64_t epoch = fat_date_to_epoch(m_entry.creation_date, m_entry.creation_time); + const time_t epoch = fat_date_to_epoch(m_entry.creation_date, m_entry.creation_time); return timespec { .tv_sec = epoch, .tv_nsec = 0 }; } diff --git a/kernel/kernel/Timer/HPET.cpp b/kernel/kernel/Timer/HPET.cpp index e7cdf2a2..e4b9cd1c 100644 --- a/kernel/kernel/Timer/HPET.cpp +++ b/kernel/kernel/Timer/HPET.cpp @@ -299,7 +299,7 @@ namespace Kernel long ns_this_second = ticks_this_second * regs.counter_clk_period / FS_PER_NS; return timespec { - .tv_sec = seconds, + .tv_sec = static_cast(seconds), .tv_nsec = ns_this_second }; } diff --git a/userspace/libraries/LibC/include/sys/types.h b/userspace/libraries/LibC/include/sys/types.h index 896ce206..a6bf10b0 100644 --- a/userspace/libraries/LibC/include/sys/types.h +++ b/userspace/libraries/LibC/include/sys/types.h @@ -146,7 +146,7 @@ __BEGIN_DECLS #if !defined(__time_t_defined) && (defined(__need_all_types) || defined(__need_time_t)) #define __time_t_defined 1 - typedef unsigned long long time_t; + typedef long long time_t; #endif #undef __need_time_t diff --git a/userspace/libraries/LibC/time.cpp b/userspace/libraries/LibC/time.cpp index 9817f776..a7f13463 100644 --- a/userspace/libraries/LibC/time.cpp +++ b/userspace/libraries/LibC/time.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -167,15 +168,18 @@ time_t mktime(struct tm* tm) struct tm* gmtime_r(const time_t* timer, struct tm* __restrict result) { + // FIXME: allow negative times :) + ASSERT(*timer >= 0); + constexpr uint64_t month_days[] { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; - time_t time = *timer; + unsigned long long time = *timer; result->tm_sec = time % 60; time /= 60; result->tm_min = time % 60; time /= 60; result->tm_hour = time % 24; time /= 24; - time_t total_days = time; + unsigned long long total_days = time; result->tm_wday = (total_days + 4) % 7; result->tm_year = 1970; while (total_days >= 365U + is_leap_year(result->tm_year))