directly copy data from typed array for file_wBytes
This commit is contained in:
parent
d28454206d
commit
2c2ed7920b
@ -181,23 +181,36 @@ void path_wChars(B path, B x) { // consumes path
|
|||||||
}
|
}
|
||||||
void file_wBytes(FILE* f, B name, B x) {
|
void file_wBytes(FILE* f, B name, B x) {
|
||||||
u64 len = a(x)->ia;
|
u64 len = a(x)->ia;
|
||||||
TALLOC(char, val, len);
|
|
||||||
SGetU(x)
|
bool newBuf = false;
|
||||||
for (u64 i = 0; i < len; i++) {
|
char* buf;
|
||||||
B c = GetU(x,i);
|
|
||||||
val[i] = isNum(c)? o2iu(c) : o2c(c);
|
u8 el = TI(x,elType);
|
||||||
|
if (el==el_i8 || el==el_c8) {
|
||||||
|
buf = tyany_ptr(x);
|
||||||
|
} else {
|
||||||
|
TALLOC(char, val, len);
|
||||||
|
buf = val;
|
||||||
|
newBuf = true;
|
||||||
|
SGetU(x)
|
||||||
|
for (u64 i = 0; i < len; i++) {
|
||||||
|
B c = GetU(x,i);
|
||||||
|
buf[i] = isNum(c)? o2iu(c) : o2c(c);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fwrite(val, 1, len, f) != len) {
|
if (fwrite(buf, 1, len, f) != len) {
|
||||||
if (q_N(name)) thrM("Error writing to file");
|
if (q_N(name)) thrM("Error writing to file");
|
||||||
else thrF("Error writing to file \"%R\"", name);
|
else thrF("Error writing to file \"%R\"", name);
|
||||||
}
|
}
|
||||||
TFREE(val);
|
|
||||||
|
if (newBuf) TFREE(buf);
|
||||||
}
|
}
|
||||||
void path_wBytes(B path, B x) { // consumes path
|
void path_wBytes(B path, B x) { // consumes path
|
||||||
FILE* f = file_open(path, "write to", "w");
|
FILE* f = file_open(path, "write to", "w");
|
||||||
file_wBytes(f, path, x);
|
file_wBytes(f, path, x);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
dec(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
B path_list(B path) {
|
B path_list(B path) {
|
||||||
|
|||||||
@ -17,7 +17,7 @@ B mmap_file(B path); // consumes
|
|||||||
|
|
||||||
void path_wChars(B path, B x); // consumes path
|
void path_wChars(B path, B x); // consumes path
|
||||||
void path_wBytes(B path, B x); // consumes path
|
void path_wBytes(B path, B x); // consumes path
|
||||||
void file_wBytes(FILE* file, B name, B x); // consumes x
|
void file_wBytes(FILE* file, B name, B x); // doesn't consume
|
||||||
|
|
||||||
B path_list(B path); // consumes
|
B path_list(B path); // consumes
|
||||||
char path_type(B path); // consumes
|
char path_type(B path); // consumes
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user