summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-01-21 13:35:18 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-01-21 13:36:36 -0500
commit8fca7beaf35cfc438d5d29f352f80dd18efe7d2e (patch)
tree1fee5e822db6292be2d1629edf20d6239524f365 /buffer.c
parentdd91d6c72625cc7ed2ec5954a5cbca35fd7655d4 (diff)
file selector now actually working
also made stristr work with UTF-8
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/buffer.c b/buffer.c
index 162547a..520d7d2 100644
--- a/buffer.c
+++ b/buffer.c
@@ -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 {