[libc-commits] [libc] [compiler-rt] [libcxx] [clang-tools-extra] [lldb] [llvm] [clang] [flang] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

via libc-commits libc-commits at lists.llvm.org
Tue Nov 21 04:48:48 PST 2023


================
@@ -10,9 +10,26 @@
 // extensions that will eventually be implemented in Fortran.
 
 #include "flang/Runtime/extensions.h"
+#include "terminator.h"
 #include "flang/Runtime/command.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/io-api.h"
+#include "flang/Runtime/time-intrinsic.h" // copyBufferAndPad
+#include <ctime>
+
+#ifdef _WIN32
+inline void ctime_alloc(char *buffer, size_t bufsize, const time_t cur_time,
+    Fortran::runtime::Terminator terminator) {
+  int error = ctime_s(buffer, bufsize, &cur_time);
+  RUNTIME_CHECK(terminator, error == 0);
+}
+#else
+inline void ctime_alloc(char *buffer, size_t bufsize, const time_t cur_time,
+    Fortran::runtime::Terminator terminator) {
+  const char *res = ctime_r(&cur_time, buffer);
----------------
jeanPerier wrote:

Isn't some POSIX macros required here to use ctime_r?: https://linux.die.net/man/3/ctime_r

You can define a fallback that sets an empty string '/0'.

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


More information about the libc-commits mailing list