fix undefined path handling

This commit is contained in:
dzaima 2021-08-23 18:37:01 +03:00
parent ca86971df3
commit 0c1d4843ab
3 changed files with 5 additions and 4 deletions

View File

@ -642,7 +642,7 @@ B sys_c1(B t, B x) {
if(!fileNS.u) {
REQ_PATH;
#define F(X) m_nfn(X##Desc, inc(path))
B arg = m_caB(6, (B[]){inc(path), F(fileAt), F(list), F(fBytes), F(fChars), F(fLines)});
B arg = m_caB(6, (B[]){q_N(path)? m_c32(0) : inc(path), F(fileAt), F(list), F(fBytes), F(fChars), F(fLines)});
#undef F
fileNS = c1(file_nsGen,arg);
}

View File

@ -76,9 +76,9 @@ B path_resolve(B base, B rel) { // consumes rel; assumes base is a char vector o
usz ria = a(rel)->ia;
if (rnk(rel)!=1) thrM("Paths must be character vectors");
for (usz i = 0; i < ria; i++) if (!isC32(rgetU(rel, i))) thrM("Paths must be character vectors");
if (ria==0) { dec(rel); return inc(base); }
if (o2cu(rgetU(rel, 0))=='/') return rel;
if (ria>0 && o2cu(rgetU(rel, 0))=='/') return rel;
if (q_N(base)) thrM("Using relative path with no absolute base path known");
if (ria==0) { dec(rel); return inc(base); }
BS2B bgetU = TI(base,getU);
usz bia = a(base)->ia;
bool has = bia && o2cu(bgetU(base, bia-1))=='/';
@ -110,6 +110,7 @@ B path_dir(B path) { // consumes; returns directory part of file path with trail
}
B path_abs(B path) {
if (q_N(path)) return path;
u64 plen = utf8lenB(path);
TALLOC(char, p, plen+1);
toUTF8(path, p);

View File

@ -8,7 +8,7 @@ typedef struct TmpFile { // to be turned into a proper I8Arr
B path_resolve(B base, B rel); // consumes rel; assumes base is a char vector or bi_N
B path_dir(B path); // consumes; returns directory part of file path, with trailing slash
B path_abs(B path); // consumes; returns absolute version of the path
B path_abs(B path); // consumes; returns absolute version of the path; propagates bi_N
FILE* file_open(B path, char* desc, char* mode); // doesn't consume path
TmpFile* file_bytes(B path); // consumes