check fread/fwrite result
and otherwise make gcc builds happy
This commit is contained in:
parent
81cdfa9cab
commit
882280e6bd
1
build
1
build
@ -1,2 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
clang -std=gnu11 -O3 -Wall -Wno-microsoft-anon-tag -fms-extensions $@ -o BQN src/main.c -lm
|
||||
# gcc -std=gnu11 -O3 -Wall -Wno-parentheses -Wno-misleading-indentation -fms-extensions $@ -o BQN src/main.c -lm
|
||||
|
||||
3
buildg
3
buildg
@ -1,2 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
clang -std=gnu11 -O3 -g -Wall -Wno-microsoft-anon-tag -fms-extensions $@ -fno-omit-frame-pointer -o BQN src/main.c -lm
|
||||
clang -std=gnu11 -O3 -g -Wall -Wno-microsoft-anon-tag -fms-extensions -fno-omit-frame-pointer $@ -o BQN src/main.c -lm
|
||||
# gcc -std=gnu11 -O3 -g -Wall -Wno-parentheses -Wno-misleading-indentation -fms-extensions -fno-omit-frame-pointer $@ -o BQN src/main.c -lm
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
clang -DDEBUG -std=gnu11 -g -Wall -Wno-microsoft-anon-tag -fms-extensions $@ -o BQN src/main.c -lm
|
||||
# clang -DDEBUG -std=gnu11 -g -Wall -Wno-microsoft-anon-tag -fms-extensions -o BQN -lm src/main.c
|
||||
# gcc -DDEBUG -std=gnu11 -g -Wall -Wno-parentheses -Wno-misleading-indentation -fms-extensions $@ -o BQN src/main.c -lm
|
||||
|
||||
@ -3,7 +3,7 @@ typedef struct TmpFile { // to be turned into a proper I8Arr
|
||||
i8 a[];
|
||||
} TmpFile;
|
||||
|
||||
FILE* file_open(B path, char* desc, char* mode) { // consumes path; can error
|
||||
FILE* file_open(B path, char* desc, char* mode) { // doesn't consume; can error
|
||||
u64 plen = utf8lenB(path);
|
||||
TALLOC(char, p, plen+1);
|
||||
toUTF8(path, p);
|
||||
@ -11,7 +11,6 @@ FILE* file_open(B path, char* desc, char* mode) { // consumes path; can error
|
||||
FILE* f = fopen(p, mode);
|
||||
TFREE(p);
|
||||
if (f==NULL) thrF("Couldn't %S file \"%R\"", desc, path);
|
||||
dec(path);
|
||||
return f;
|
||||
}
|
||||
|
||||
@ -22,7 +21,8 @@ TmpFile* file_bytes(B path) { // consumes; may throw
|
||||
fseek(f, 0, SEEK_SET);
|
||||
TmpFile* src = mm_allocN(fsizeof(TmpFile,a,u8,len), t_i8arr);
|
||||
arr_shVec(tag(src,ARR_TAG), len);
|
||||
fread((char*)src->a, 1, len, f);
|
||||
if (fread((char*)src->a, 1, len, f)!=len) thrF("Error reading file \"%R\"", path);
|
||||
dec(path);
|
||||
fclose(f);
|
||||
return src;
|
||||
}
|
||||
@ -81,7 +81,8 @@ void file_write(B path, B x) { // consumes path
|
||||
TALLOC(char, val, len);
|
||||
toUTF8(x, val);
|
||||
|
||||
fwrite(val, 1, len, f);
|
||||
if (fwrite(val, 1, len, f) != len) thrF("Error writing to file \"%R\"", path);
|
||||
TFREE(val);
|
||||
dec(path);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
2
src/h.h
2
src/h.h
@ -31,7 +31,7 @@
|
||||
#define f64 double
|
||||
#define I32_MAX ((i32)((1LL<<31)-1))
|
||||
#define I32_MIN ((i32)(-(1LL<<31)))
|
||||
#define I64_MIN ((i64)(-(1LL<<63)))
|
||||
#define I64_MIN ((i64)(1ULL<<63))
|
||||
#define CHR_MAX 1114111
|
||||
#define U16_MAX ((u16)~(u16)0)
|
||||
#define U32_MAX ((u32)~(u32)0)
|
||||
|
||||
@ -20,7 +20,7 @@ void mut_to(Mut* m, u8 n) {
|
||||
case el_i32: m->val = a(m_i32arrp(&m->ai32, m->ia)); return;
|
||||
case el_f64: m->val = a(m_f64arrp(&m->af64, m->ia)); return;
|
||||
case el_c32: m->val = a(m_c32arrp(&m->ac32, m->ia)); return;
|
||||
case el_B : HArr_p t = m_harrUp( m->ia); m->val = (Arr*)t.c; m->aB = t.c->a; return;
|
||||
case el_B :; HArr_p t = m_harrUp( m->ia); m->val = (Arr*)t.c; m->aB = t.c->a; return;
|
||||
}
|
||||
} else {
|
||||
sprnk(m->val, 1);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user