diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 1776be65..309bc43b 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -676,7 +676,9 @@ B list_c1(B d, B x) { } B ftype_c1(B d, B x) { - return m_c32(path_type(path_rel(nfn_objU(d), x))); + char ty = path_type(path_rel(nfn_objU(d), x)); + if (ty==0) thrM("•file.Type: Error while accessing file"); + return m_c32(ty); } B fName_c1(B t, B x) { diff --git a/src/utils/file.c b/src/utils/file.c index 48b699ef..27a195fa 100644 --- a/src/utils/file.c +++ b/src/utils/file.c @@ -224,8 +224,11 @@ B path_list(B path) { char path_type(B path) { char* p = toCStr(path); struct stat path_stat; - stat(p, &path_stat); + int r = stat(p, &path_stat); freeCStr(p); + dec(path); + + if (r==-1) return 0; i64 mode = path_stat.st_mode; if (S_ISREG (mode)) return 'f'; if (S_ISDIR (mode)) return 'd';