[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:55:15 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(¤t_time);
+
+ char *time_string = ctime(¤t_time);
----------------
DavidTruby wrote:
`ctime` isn't thread safe, but I'm not sure there's a cross platform C function that is; glibc has `ctime_r` but I don't think that exists on Windows or MacOS. I also think we can't depend on the non-header parts of the C++ standard library so we likely can't use `<chrono>`, which _is_ thread safe. Someone else might have a better idea of what to do here. @jeanPerier is my recollection about usage of the C++ standard library correct here?
https://github.com/llvm/llvm-project/pull/71222
More information about the flang-commits
mailing list