From eae7501d36b323d126cc5c13c946bb4005c3a0bb Mon Sep 17 00:00:00 2001 From: dzaima Date: Tue, 15 Mar 2022 20:47:01 +0200 Subject: [PATCH] =?UTF-8?q?fix=20=E2=80=A2file.Type=20when=20file=20not=20?= =?UTF-8?q?present?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/sysfn.c | 4 +++- src/utils/file.c | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) 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';