Skip to content

Commit

Permalink
fix unspecific behavior on getcwd
Browse files Browse the repository at this point in the history
  • Loading branch information
JumpMasterJJ committed May 24, 2024
1 parent 4e3afff commit b89a7a5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions flang/runtime/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
#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 {
Expand Down Expand Up @@ -247,8 +252,9 @@ std::int32_t RTNAME(GetCwd)(

RUNTIME_CHECK(terminator, IsValidCharDescriptor(&cwd));

char *buf{getcwd(nullptr, 0)};
if (!buf) {
char *buf{(char *)AllocateMemoryOrCrash(terminator, PATH_MAX)};

if (!getcwd(buf, PATH_MAX)) {
return StatMissingCurrentWorkDirectory;
}

Expand Down

0 comments on commit b89a7a5

Please sign in to comment.