logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: 3472487833d7fe6e1501c28c0b7677d26143caab
parent 72675c301e1c6ceeece523be4206d6cc31588da2
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 17 Jan 2025 07:57:23 +0100

cmd/shuf: write correct amount of lines

Diffstat:

Mcmd/shuf.c7+++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/cmd/shuf.c b/cmd/shuf.c @@ -72,11 +72,11 @@ shuf(FILE *in, const char *fname) free(lines[p]); lines[p] = NULL; wrote++; + + if(write_limit != 0 && write_limit <= wrote) exit(0); } lines[p] = dup; - - if(write_limit != 0 && write_limit >= wrote) exit(0); } } @@ -190,10 +190,13 @@ main(int argc, char *argv[]) // inserts are random so iterating on it is fine for(int i = 0; i < LINES_LEN; i++) { + if(write_limit != 0 && write_limit <= wrote) break; + if(lines[i] != NULL) { fputs(lines[i], stdout); free(lines[i]); + wrote++; } }