[libc-commits] [libc] [libc] implement localtime (PR #110363)

Зишан Мирза via libc-commits libc-commits at lists.llvm.org
Sun Oct 6 13:52:31 PDT 2024


================
@@ -26,6 +27,26 @@ static int64_t computeRemainingYears(int64_t daysPerYears,
   return years;
 }
 
+volatile int lock = 0;
+
+void release_file(FILE *fp) {
+  lock = 0;
+  fclose(fp);
+}
+
+void acquire_file(FILE *fp, char *timezone) {
+  while (1) {
+    if (lock == 0) {
+      lock = 1;
+      break;
+    }
+  }
+
+  if (fgets(timezone, sizeof(timezone), fp) == NULL) {
+    release_file(fp);
+  }
+}
----------------
zimirza wrote:

Sure, I had to use `int` in `fgets` since it only accepts in `int`. The parameter is `size_t`.

https://github.com/llvm/llvm-project/pull/110363


More information about the libc-commits mailing list