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

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Jan 3 08:43:57 PST 2024


================
@@ -43,6 +66,26 @@ void FORTRAN_PROCEDURE_NAME(flush)(const int &unit) {
 }
 } // namespace io
 
+// CALL FDATE(DATE)
+void FORTRAN_PROCEDURE_NAME(fdate)(std::byte *arg, std::int64_t length) {
+  // Day Mon dd hh:mm:ss yyyy\n\0 is 26 characters, e.g.
+  // Tue May 26 21:51:03 2015\n\0
+  char str[26];
+  // Insufficient space, fill with spaces and return.
+  if (length < 24) {
+    std::memset(reinterpret_cast<char *>(arg), ' ', length);
+    return;
+  }
+
+  Terminator terminator{__FILE__, __LINE__};
+  std::time_t current_time;
+  std::time(&current_time);
+  CtimeBuffer(str, sizeof(str), current_time, terminator);
+
+  // Pad space on \n\0 as well, start at index 24 (included).
----------------
klausler wrote:

What does "Pad space on \n\0 as well" mean?

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


More information about the flang-commits mailing list