Skip to content

Commit 9589699

Browse files
committed
move to extension.cpp
1 parent 64f18c6 commit 9589699

File tree

4 files changed

+27
-43
lines changed

4 files changed

+27
-43
lines changed

flang/include/flang/Runtime/command.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ extern "C" {
2323
// integer kind.
2424
std::int32_t RTNAME(ArgumentCount)();
2525

26-
// Try to get the the current date (same format as CTIME: convert to a string)
27-
// Return a STATUS as described in the standard.
28-
std::int32_t RTNAME(FDate)(
29-
const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
30-
3126
// 16.9.82 GET_COMMAND
3227
// Try to get the value of the whole command. All of the parameters are
3328
// optional.

flang/runtime/command.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,8 @@
1313
#include "tools.h"
1414
#include "flang/Runtime/descriptor.h"
1515
#include <cstdlib>
16-
#include <ctime>
1716
#include <limits>
1817

19-
#ifdef _WIN32
20-
inline const char *ctime_alloc(
21-
char *buffer, size_t bufsize, const time_t cur_time) {
22-
int error = ctime_s(buffer, bufsize, &cur_time);
23-
assert(error == 0 && "ctime_s returned an error");
24-
return buffer;
25-
}
26-
#else
27-
inline const char *ctime_alloc(
28-
char *buffer, size_t bufsize, const time_t cur_time) {
29-
const char *res = ctime_r(&cur_time, buffer);
30-
assert(res != nullptr && "ctime_s returned an error");
31-
return res;
32-
}
33-
#endif
34-
3518
namespace Fortran::runtime {
3619
std::int32_t RTNAME(ArgumentCount)() {
3720
int argc{executionEnvironment.argc};
@@ -142,24 +125,6 @@ static bool FitsInDescriptor(
142125
kind, terminator, value);
143126
}
144127

145-
std::int32_t RTNAME(FDate)(const Descriptor *value, const Descriptor *errmsg) {
146-
FillWithSpaces(*value);
147-
std::time_t current_time;
148-
std::time(&current_time);
149-
std::array<char, 26> str;
150-
// Day Mon dd hh:mm:ss yyyy\n\0 is 26 characters, e.g.
151-
// Tue May 26 21:51:03 2015\n\0
152-
153-
ctime_alloc(str.data(), str.size(), current_time);
154-
str[24] = '\0'; // remove new line
155-
156-
if (value) {
157-
return CopyToDescriptor(*value, str.data(), 24, errmsg);
158-
}
159-
160-
return StatOk;
161-
}
162-
163128
std::int32_t RTNAME(GetCommandArgument)(std::int32_t n, const Descriptor *value,
164129
const Descriptor *length, const Descriptor *errmsg, const char *sourceFile,
165130
int line) {

flang/runtime/extensions.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@
1313
#include "flang/Runtime/command.h"
1414
#include "flang/Runtime/descriptor.h"
1515
#include "flang/Runtime/io-api.h"
16+
#include <ctime>
17+
18+
#ifdef _WIN32
19+
inline const char *ctime_alloc(
20+
char *buffer, size_t bufsize, const time_t cur_time) {
21+
int error = ctime_s(buffer, bufsize, &cur_time);
22+
assert(error == 0 && "ctime_s returned an error");
23+
return buffer;
24+
}
25+
#else
26+
inline const char *ctime_alloc(
27+
char *buffer, size_t bufsize, const time_t cur_time) {
28+
const char *res = ctime_r(&cur_time, buffer);
29+
assert(res != nullptr && "ctime_s returned an error");
30+
return res;
31+
}
32+
#endif
1633

1734
extern "C" {
1835

@@ -31,8 +48,16 @@ void FORTRAN_PROCEDURE_NAME(flush)(const int &unit) {
3148
std::int32_t FORTRAN_PROCEDURE_NAME(iargc)() { return RTNAME(ArgumentCount)(); }
3249

3350
void FORTRAN_PROCEDURE_NAME(fdate)(std::int8_t *arg, std::int64_t length) {
34-
Descriptor value{*Descriptor::Create(1, length, arg, 0)};
35-
(void)RTNAME(FDate)(&value, nullptr);
51+
std::time_t current_time;
52+
std::time(&current_time);
53+
std::array<char, 26> str;
54+
// Day Mon dd hh:mm:ss yyyy\n\0 is 26 characters, e.g.
55+
// Tue May 26 21:51:03 2015\n\0
56+
57+
ctime_alloc(str.data(), str.size(), current_time);
58+
str[24] = '\0'; // remove new line
59+
60+
strncpy(reinterpret_cast<char *>(arg), str.data(), length);
3661
}
3762

3863
// CALL GETARG(N, ARG)

flang/unittests/Runtime/CommandTest.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ TEST_F(SeveralArguments, ArgValueTooShort) {
297297
ASSERT_NE(tooShort, nullptr);
298298
EXPECT_EQ(RTNAME(GetCommandArgument)(1, tooShort.get()), -1);
299299
CheckDescriptorEqStr(tooShort.get(), severalArgsArgv[1]);
300-
EXPECT_EQ(RTNAME(FDate)(tooShort.get()), -1);
301300

302301
OwningPtr<Descriptor> length{EmptyIntDescriptor()};
303302
ASSERT_NE(length, nullptr);

0 commit comments

Comments
 (0)