git: f079ef8aa428 - main - sort: simplify the code to handle -z flag
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 13 Oct 2022 08:24:24 UTC
The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=f079ef8aa428ebffad28f5c62cce52c2bf70fb49 commit f079ef8aa428ebffad28f5c62cce52c2bf70fb49 Author: Baptiste Daroussin <bapt@FreeBSD.org> AuthorDate: 2022-10-13 08:21:48 +0000 Commit: Baptiste Daroussin <bapt@FreeBSD.org> CommitDate: 2022-10-13 08:24:11 +0000 sort: simplify the code to handle -z flag --- usr.bin/sort/file.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/usr.bin/sort/file.c b/usr.bin/sort/file.c index bfe5e5c29b86..2e3b4e0a4350 100644 --- a/usr.bin/sort/file.c +++ b/usr.bin/sort/file.c @@ -605,10 +605,7 @@ file_reader_init(const char *fsrc) ret = sort_calloc(1, sizeof(struct file_reader)); - ret->elsymb = '\n'; - if (sort_opts_vals.zflag) - ret->elsymb = 0; - + ret->elsymb = sort_opts_vals.zflag ? '\0' : '\n'; ret->fname = sort_strdup(fsrc); if (strcmp(fsrc, "-") && (compress_program == NULL) && use_mmap) { @@ -687,14 +684,15 @@ file_reader_readline(struct file_reader *fr) } } } else { - int delim = sort_opts_vals.zflag ? '\0' : '\n'; - ssize_t len = getdelim(&fr->buffer, &fr->bsz, delim, fr->file); + ssize_t len; + + len = getdelim(&fr->buffer, &fr->bsz, fr->elsymb, fr->file); if (len < 0) { if (!feof(fr->file)) err(2, NULL); return (NULL); } - if (len > 0 && fr->buffer[len - 1] == delim) + if (len > 0 && fr->buffer[len - 1] == fr->elsymb) len--; ret = bwscsbdup(fr->buffer, len); }