Fix windows issue with (file/read file :all)
When file was created with file/popen, the current optimization
of using fseek on windows fails due to windows not properly returning
and error code and just returning 0. Windows :(.
@@ -221,27 +221,11 @@ static Janet cfun_io_fread(int32_t argc, Janet *argv) {
if (janet_checktype(argv[1], JANET_KEYWORD)) {
const uint8_t *sym = janet_unwrap_keyword(argv[1]);
if (!janet_cstrcmp(sym, "all")) {
- /* Read whole file */
- int status = fseek(iof->file, 0, SEEK_SET);
- if (status) {
- /* backwards fseek did not work (stream like popen) */
int32_t sizeBefore;
do {
sizeBefore = buffer->count;
- read_chunk(iof, buffer, 1024);
+ read_chunk(iof, buffer, 4096);
} while (sizeBefore < buffer->count);
- } else {
- fseek(iof->file, 0, SEEK_END);
- long fsize = ftell(iof->file);
- if (fsize < 0) {
- janet_panicf("could not get file size of %v", argv[0]);
- }
- if (fsize > (INT32_MAX)) {
- janet_panic("file to large to read into buffer");
- }
- fseek(iof->file, 0, SEEK_SET);
- read_chunk(iof, buffer, (int32_t) fsize);
- }
/* Never return nil for :all */
return janet_wrap_buffer(buffer);
} else if (!janet_cstrcmp(sym, "line")) {
