diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-21 13:35:18 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2021-01-21 13:36:36 -0500 |
commit | 8fca7beaf35cfc438d5d29f352f80dd18efe7d2e (patch) | |
tree | 1fee5e822db6292be2d1629edf20d6239524f365 /buffer.c | |
parent | dd91d6c72625cc7ed2ec5954a5cbca35fd7655d4 (diff) |
file selector now actually working
also made stristr work with UTF-8
Diffstat (limited to 'buffer.c')
-rw-r--r-- | buffer.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -483,9 +483,13 @@ Status buffer_load_file(TextBuffer *buffer, char const *filename) { bool success = true; if (fp) { fseek(fp, 0, SEEK_END); - size_t file_size = (size_t)ftell(fp); + long file_pos = ftell(fp); + size_t file_size = (size_t)file_pos; fseek(fp, 0, SEEK_SET); - if (file_size > 10L<<20) { + if (file_pos == -1 || file_pos == LONG_MAX) { + buffer_seterr(buffer, "Couldn't get file position. There is something wrong with the file '%s'.", filename); + success = false; + } else if (file_size > 10L<<20) { buffer_seterr(buffer, "File too big (size: %zu).", file_size); success = false; } else { |