[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
Fri Nov 10 07:01:07 PST 2023
================
@@ -125,6 +142,36 @@ static bool FitsInDescriptor(
kind, terminator, value);
}
+void removeNewLine(char *str) {
+ char *newlinePos = std::strchr(str, '\n');
+ if (newlinePos) {
+ *newlinePos = '\0'; // Replace with null terminator
+ }
+}
+
+std::int32_t RTNAME(FDate)(const Descriptor *value, const Descriptor *errmsg) {
+ FillWithSpaces(*value);
+
+ std::time_t current_time;
+ std::time(¤t_time);
+ std::array<char, 26> str;
+ // Day Mon dd hh:mm:ss yyyy\n is 26 character,
+ // e.g. Tue May 26 21:51:03 2015\n\0
+
+ ctime_alloc(str.data(), str.size(), current_time);
+ removeNewLine(str.data());
+ std::int64_t stringLen{StringLength(str.data())};
----------------
DavidTruby wrote:
Again, I think we always know the string will be 24 characters long right? (26 - the null terminator - the newline).
Then maybe we don't even need to bother replacing the newline with \0.
https://github.com/llvm/llvm-project/pull/71222
More information about the flang-commits
mailing list