diff options
Diffstat (limited to 'flang/runtime/command.cpp')
| -rw-r--r-- | flang/runtime/command.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp index b573c5dfd797..e642248a25e6 100644 --- a/flang/runtime/command.cpp +++ b/flang/runtime/command.cpp @@ -17,12 +17,19 @@ #ifdef _WIN32 #include "flang/Common/windows-include.h" +#include <direct.h> +#define getcwd _getcwd +#define PATH_MAX MAX_PATH // On Windows GetCurrentProcessId returns a DWORD aka uint32_t #include <processthreadsapi.h> inline pid_t getpid() { return GetCurrentProcessId(); } #else #include <unistd.h> //getpid() + +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif #endif namespace Fortran::runtime { @@ -239,4 +246,23 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name, return StatOk; } +std::int32_t RTNAME(GetCwd)( + const Descriptor &cwd, const char *sourceFile, int line) { + Terminator terminator{sourceFile, line}; + + RUNTIME_CHECK(terminator, IsValidCharDescriptor(&cwd)); + + char *buf{(char *)AllocateMemoryOrCrash(terminator, PATH_MAX)}; + + if (!getcwd(buf, PATH_MAX)) { + return StatMissingCurrentWorkDirectory; + } + + std::int64_t strLen{StringLength(buf)}; + std::int32_t status{CopyCharsToDescriptor(cwd, buf, strLen)}; + + std::free(buf); + return status; +} + } // namespace Fortran::runtime |
