[libc-commits] [libc] [libc] implement localtime (PR #110363)
Зишан Мирза via libc-commits
libc-commits at lists.llvm.org
Tue Oct 8 06:26:32 PDT 2024
================
@@ -129,6 +154,27 @@ int64_t update_from_seconds(int64_t total_seconds, struct tm *tm) {
if (years > INT_MAX || years < INT_MIN)
return time_utils::out_of_range();
+ char *timezone = (char *)malloc(sizeof(char) * TimeConstants::TIMEZONE_SIZE);
+ timezone = getenv("TZ");
+ FILE *fp = NULL;
+ if (timezone == NULL) {
+ timezone =
+ (char *)realloc(timezone, sizeof(char) * TimeConstants::TIMEZONE_SIZE);
+ fp = fopen("/etc/timezone", "rb");
+ if (fp == NULL) {
+ return time_utils::out_of_range();
+ }
+
+ acquire_file(fp, timezone, TimeConstants::TIMEZONE_SIZE);
+ }
+
+ if (fp != NULL && file_usage == 0) {
+ release_file(fp, timezone);
+ return time_utils::out_of_range();
----------------
zimirza wrote:
Thank you for the feedback. I have now used stack allocation of memory instead of heap allocation.
https://github.com/llvm/llvm-project/pull/110363
More information about the libc-commits
mailing list