summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-27 15:05:18 -0500
committerpommicket <pommicket@gmail.com>2022-12-27 15:05:18 -0500
commit6f208a42ce93dfac6f16cb16fdc7a4e6d37e4e7d (patch)
tree19c0c8eafdd31fe6e5f780ae13de52c0f3d44df1 /buffer.c
parent6912e5c194ef28d3d567ccdf0ee77f30219d9e17 (diff)
configurable max buffer size + max view-only buffer size
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/buffer.c b/buffer.c
index 49d63a4..7b569bd 100644
--- a/buffer.c
+++ b/buffer.c
@@ -2176,10 +2176,14 @@ Status buffer_load_file(TextBuffer *buffer, char const *filename) {
long file_pos = ftell(fp);
size_t file_size = (size_t)file_pos;
fseek(fp, 0, SEEK_SET);
+ const Settings *default_settings = buffer->ted->default_settings;
+ u32 max_file_size_editable = default_settings->max_file_size;
+ u32 max_file_size_view_only = default_settings->max_file_size_view_only;
+
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) {
+ } else if (file_size > max_file_size_editable && file_size > max_file_size_view_only) {
buffer_seterr(buffer, "File too big (size: %zu).", file_size);
success = false;
} else {
@@ -2254,6 +2258,11 @@ Status buffer_load_file(TextBuffer *buffer, char const *filename) {
buffer->view_only = true;
}
+ if (file_size > max_file_size_editable) {
+ // file very large; open in view-only mode.
+ buffer->view_only = true;
+ }
+
// this will send a didOpen request if needed
buffer_lsp(buffer);
}