Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/module/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,25 @@ void processCwd(WrenVM* vm)
{
wrenEnsureSlots(vm, 1);

char buffer[WREN_PATH_MAX * 4];
size_t length = sizeof(buffer);
if (uv_cwd(buffer, &length) != 0)
char _buffer[WREN_PATH_MAX * 2 + 1];
char* buffer = _buffer;
size_t length = sizeof(_buffer);
int result = uv_cwd(buffer, &length);

if (result == UV_ENOBUFS)
{
buffer = (char*)malloc(length);
result = uv_cwd(buffer, &length);
}

if (result != 0)
{
wrenSetSlotString(vm, 0, "Cannot get current working directory.");
wrenAbortFiber(vm, 0);
return;
}

wrenSetSlotString(vm, 0, buffer);

if (buffer != _buffer) free(buffer);
}
7 changes: 6 additions & 1 deletion src/module/os.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#ifndef process_h
#define process_h

#include "limits.h"
#include "wren.h"

#define WREN_PATH_MAX 4096
#ifdef PATH_MAX
# define WREN_PATH_MAX PATH_MAX
#else
# define WREN_PATH_MAX 4096
#endif

// Stores the command line arguments passed to the CLI.
void osSetArguments(int argc, const char* argv[]);
Expand Down
1 change: 0 additions & 1 deletion test/os/process/cwd.wren
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ import "os" for Process

System.print(Process.cwd is String) // expect: true
System.print(!Process.cwd.isEmpty) // expect: true
System.print(Process.cwd.startsWith("/")) // expect: true
System.print(File.realPath(Process.cwd) == Process.cwd) // expect: true
System.print(Directory.exists(Process.cwd)) // expect: true