git: cacedfd1dfef - stable/13 - sort: simplify the code to handle -z flag
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 19 Oct 2022 08:01:30 UTC
The branch stable/13 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=cacedfd1dfef096322e6f9d4473bca8066db994f commit cacedfd1dfef096322e6f9d4473bca8066db994f Author: Baptiste Daroussin <bapt@FreeBSD.org> AuthorDate: 2022-10-13 08:21:48 +0000 Commit: Baptiste Daroussin <bapt@FreeBSD.org> CommitDate: 2022-10-19 07:59:29 +0000 sort: simplify the code to handle -z flag (cherry picked from commit f079ef8aa428ebffad28f5c62cce52c2bf70fb49) --- 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 3e5754442ac1..b48948e1edee 100644 --- a/usr.bin/sort/file.c +++ b/usr.bin/sort/file.c @@ -617,10 +617,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) { @@ -785,14 +782,15 @@ file_reader_readline(struct file_reader *fr) fr->strbeg = (strend - fr->buffer) + 1; } 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); }