1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 02:59:54 +00:00

Fix os/dir on windows.

This commit is contained in:
Calvin Rose 2019-03-30 13:46:52 -04:00
parent 61c0a4bc87
commit d6ba2de888
2 changed files with 12 additions and 6 deletions

3
.gitignore vendored
View File

@ -13,6 +13,9 @@ janet
janet-*.tar.gz janet-*.tar.gz
dist dist
# VSCode
.vscode
# Eclipse # Eclipse
.project .project
.cproject .cproject

View File

@ -395,8 +395,9 @@ static const uint8_t *janet_decode_permissions(unsigned short m) {
static const uint8_t *janet_decode_mode(unsigned short m) { static const uint8_t *janet_decode_mode(unsigned short m) {
const char *str = "other"; const char *str = "other";
if (m & _S_IFREG(m)) str = "file"; if (m & _S_IFREG) str = "file";
else if (m & _S_IFDIR(m)) str = "directory"; else if (m & _S_IFDIR) str = "directory";
else if (m & _S_IFCHR) str = "character";
return janet_ckeyword(str); return janet_ckeyword(str);
} }
#else #else
@ -478,10 +479,12 @@ static Janet os_dir(int32_t argc, Janet *argv) {
janet_panicf("path too long: %s", dir); janet_panicf("path too long: %s", dir);
sprintf(pattern, "%s/*", dir); sprintf(pattern, "%s/*", dir);
intptr_t res = _findfirst(pattern, &afile); intptr_t res = _findfirst(pattern, &afile);
while (res != -1) { if (-1 == res) janet_panicv(janet_cstringv(strerror(errno)));
do {
if (strcmp(".", afile.name) && strcmp("..", afile.name)) {
janet_array_push(paths, janet_cstringv(afile.name)); janet_array_push(paths, janet_cstringv(afile.name));
res = _findnext(res, &afile);
} }
} while (_findnext(res, &afile) != -1);
_findclose(res); _findclose(res);
#else #else
/* Read directory items with opendir / readdir / closedir */ /* Read directory items with opendir / readdir / closedir */