sled

Једноставни уређивач текста
git clone https://git.sr.ht/~strahinja/sled
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување 2ae1874a691fdb5d3f1bd410e5ab46be5d75bbf4
родитељ fed6ef481fe11238a16c4ce171f593eb80521c86
Аутор: Страхиња Радић <sr@strahinja.org>
Датум:   Thu,  7 Nov 2024 17:00:52 +0100

sled.c(load_file): Allow files not ending with EOL

Diffstat:
Msled.c | 19+++++++++++++++----
измењених датотека: 1, додавања: 15(+), брисања: 4(-)

diff --git a/sled.c b/sled.c @@ -1281,6 +1281,7 @@ load_file(struct DrawState* state) char* input_line = NULL; ssize_t input_size = limits[L_LINE_MAX]; ssize_t input_len = 0; + int possible_nulbyte; assert(state != NULL); input_line = calloc(input_size, 1); @@ -1310,6 +1311,7 @@ load_file(struct DrawState* state) state->action = ACT_READING; redraw_status(state); + possible_nulbyte = 0; while (!feof(input)) { char* eol = NULL; @@ -1317,15 +1319,24 @@ load_file(struct DrawState* state) if (!fgets(input_line, input_size, input)) continue; + + if (possible_nulbyte) + { + /* Definitely not EOF, NUL byte confirmed */ + state->error = ERR_BINARY; + return 1; + } + eol = strchr(input_line, '\n'); if (eol) *eol = 0; nulbyte = strchr(input_line, 0); + + /* We don't know if the NUL byte not being equal to + * (possibly NULL) eol is the result of EOF or not + */ if (!open_binary && nulbyte && (nulbyte != eol)) - { - state->error = ERR_BINARY; - return 1; - } + possible_nulbyte = 1; if (state->rows_count + 1 == state->buffer_size) {