From 75bc69ba2f2da7ba7433a12ad25362e95d7d9fb9 Mon Sep 17 00:00:00 2001 From: Leaf Date: Tue, 2 Jun 2020 09:05:41 +0000 Subject: [PATCH 1/2] Implement os/realpath on Window with _fullpath This is similar to realpath but differs in that realpath will complain if the path does not exist. We could add our own exists check if we really wanted to match that behaviour. --- src/core/os.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/os.c b/src/core/os.c index 471e6fd6..5b060b4a 100644 --- a/src/core/os.c +++ b/src/core/os.c @@ -1224,17 +1224,16 @@ static Janet os_rename(int32_t argc, Janet *argv) { static Janet os_realpath(int32_t argc, Janet *argv) { janet_fixarity(argc, 1); -#ifdef JANET_NO_REALPATH - (void) argv; - janet_panic("os/realpath not supported on this platform"); -#else const char *src = janet_getcstring(argv, 0); +#ifdef JANET_WINDOWS + char *dest = _fullpath(NULL, src, _MAX_PATH); +#else char *dest = realpath(src, NULL); +#endif if (NULL == dest) janet_panicf("%s: %s", strerror(errno), src); Janet ret = janet_cstringv(dest); free(dest); return ret; -#endif } static Janet os_permission_string(int32_t argc, Janet *argv) { From bed02c2f951a24156aa40037261ea7e368da923b Mon Sep 17 00:00:00 2001 From: Leaf Date: Tue, 2 Jun 2020 09:14:31 +0000 Subject: [PATCH 2/2] Remove unused flags --- src/include/janet.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/include/janet.h b/src/include/janet.h index 94a90a3b..d15d2529 100644 --- a/src/include/janet.h +++ b/src/include/janet.h @@ -138,11 +138,6 @@ extern "C" { #define JANET_NO_UTC_MKTIME #endif -/* Add some windows flags */ -#ifdef JANET_WINDOWS -#define JANET_NO_REALPATH -#endif - /* Define how global janet state is declared */ #ifdef JANET_SINGLE_THREADED #define JANET_THREAD_LOCAL