mirror of
https://github.com/janet-lang/janet
synced 2024-12-26 00:10:27 +00:00
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.
This commit is contained in:
parent
eb9f74a273
commit
75bc69ba2f
@ -1224,17 +1224,16 @@ static Janet os_rename(int32_t argc, Janet *argv) {
|
|||||||
|
|
||||||
static Janet os_realpath(int32_t argc, Janet *argv) {
|
static Janet os_realpath(int32_t argc, Janet *argv) {
|
||||||
janet_fixarity(argc, 1);
|
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);
|
const char *src = janet_getcstring(argv, 0);
|
||||||
|
#ifdef JANET_WINDOWS
|
||||||
|
char *dest = _fullpath(NULL, src, _MAX_PATH);
|
||||||
|
#else
|
||||||
char *dest = realpath(src, NULL);
|
char *dest = realpath(src, NULL);
|
||||||
|
#endif
|
||||||
if (NULL == dest) janet_panicf("%s: %s", strerror(errno), src);
|
if (NULL == dest) janet_panicf("%s: %s", strerror(errno), src);
|
||||||
Janet ret = janet_cstringv(dest);
|
Janet ret = janet_cstringv(dest);
|
||||||
free(dest);
|
free(dest);
|
||||||
return ret;
|
return ret;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Janet os_permission_string(int32_t argc, Janet *argv) {
|
static Janet os_permission_string(int32_t argc, Janet *argv) {
|
||||||
|
Loading…
Reference in New Issue
Block a user