[flang-commits] [llvm] [flang] [compiler-rt] [clang] [libc] [lldb] [clang-tools-extra] [libcxx] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)
Yi Wu via flang-commits
flang-commits at lists.llvm.org
Wed Jan 3 08:59:34 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(¤t_time);
+ CtimeBuffer(str, sizeof(str), current_time, terminator);
+
+ // Pad space on \n\0 as well, start at index 24 (included).
----------------
yi-wu-arm wrote:
`ctime` returns a string that follow the format:
`Day Mon dd hh:mm:ss yyyy\n\0`: `Tue May 26 21:51:03 2015\n\0`, 26 characters in total, the last two character, new line and null-terminator will be pad with space as well
https://github.com/llvm/llvm-project/pull/71222
More information about the flang-commits
mailing list