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

Зишан Мирза via libc-commits libc-commits at lists.llvm.org
Wed Dec 25 17:59:17 PST 2024


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

I think I have now implemented an RAII correctly. Could you please check?

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


More information about the libc-commits mailing list