[flang-commits] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

David Truby via flang-commits flang-commits at lists.llvm.org
Thu Nov 9 08:57:06 PST 2023


================
@@ -125,6 +126,33 @@ static bool FitsInDescriptor(
       kind, terminator, value);
 }
 
+void removeNewLine(char *str) {
+  char *newlinePos = strchr(str, '\n');
+  if (newlinePos != NULL) {
+    *newlinePos = '\0'; // Replace with null terminator
+  }
+}
+
+std::int32_t RTNAME(FDate)(const Descriptor *value, const Descriptor *errmsg) {
+  FillWithSpaces(*value);
+
+  time_t current_time;
+  time(&current_time);
+
+  char *time_string = ctime(&current_time);
----------------
DavidTruby wrote:

Actually, it looks like C11 added a `ctime_s` function that is thread safe that should be available on all platforms. Can we use that instead?

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


More information about the flang-commits mailing list