non-hacky workaround for the empty file bug

See #3328
This commit is contained in:
Andrew Kelley 2020-10-26 16:06:14 -07:00
parent 1ce0994897
commit 435c8ad703
2 changed files with 4 additions and 5 deletions

View File

@ -428,5 +428,7 @@ export fn stage2_fetch_file(
const max_file_size = std.math.maxInt(u32);
const contents = comp.stage1_cache_manifest.addFilePostFetch(file_path, max_file_size) catch return null;
result_len.* = contents.len;
// TODO https://github.com/ziglang/zig/issues/3328#issuecomment-716749475
if (contents.len == 0) return @intToPtr(?[*]const u8, 0x1);
return contents.ptr;
}

View File

@ -8052,13 +8052,10 @@ not_integer:
}
Error file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents_buf) {
size_t len = 0xAA;
size_t len;
const char *contents = stage2_fetch_file(&g->stage1, buf_ptr(resolved_path), buf_len(resolved_path), &len);
if (len == 0) {
// File exists but is empty (otherwise it would be 0xAA)
} else if (contents == nullptr) {
if (contents == nullptr)
return ErrorFileNotFound;
}
buf_init_from_mem(contents_buf, contents, len);
return ErrorNone;
}