Skip to content

Commit 90832ea

Browse files
committed
add support of getcwd on Windows
1 parent c0238d1 commit 90832ea

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

flang/runtime/command.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#ifdef _WIN32
1919
#include "flang/Common/windows-include.h"
20+
#include <direct.h>
21+
#define getcwd _getcwd
2022

2123
// On Windows GetCurrentProcessId returns a DWORD aka uint32_t
2224
#include <processthreadsapi.h>
@@ -245,17 +247,16 @@ std::int32_t RTNAME(GetCwd)(
245247

246248
RUNTIME_CHECK(terminator, IsValidCharDescriptor(&cwd));
247249

248-
char *buf = (char *)std::malloc(FILENAME_MAX);
250+
char *buf = getcwd(nullptr, 0);
249251
if (!buf) {
250-
return StatMemAllocation;
251-
}
252-
253-
if (!getcwd(buf, FILENAME_MAX)) {
254252
return StatMissingCurrentWorkDirectory;
255253
}
256254

257255
std::int64_t strLen = StringLength(buf);
258-
return CopyCharsToDescriptor(cwd, buf, strLen);
256+
std::int32_t status = CopyCharsToDescriptor(cwd, buf, strLen);
257+
258+
std::free(buf);
259+
return status;
259260
}
260261

261262
} // namespace Fortran::runtime

0 commit comments

Comments
 (0)