diff options
author | pommicket <pommicket@gmail.com> | 2022-12-27 15:05:18 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-27 15:05:18 -0500 |
commit | 6f208a42ce93dfac6f16cb16fdc7a4e6d37e4e7d (patch) | |
tree | 19c0c8eafdd31fe6e5f780ae13de52c0f3d44df1 /buffer.c | |
parent | 6912e5c194ef28d3d567ccdf0ee77f30219d9e17 (diff) |
configurable max buffer size + max view-only buffer size
Diffstat (limited to 'buffer.c')
-rw-r--r-- | buffer.c | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -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); } |