logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: 950209f1a77e7bcdb063f9c56c0502517085fa9b
parent 69cbb114a926327ac256e2007d4208ba734e1fad
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Thu,  5 Feb 2026 11:51:28 +0100

cmd/cut: Add support for -u option

Another method is to flush stdout after each read(), but switching
from FILE* + getdelim() to something else would be a bit of a
hassle right now.

Diffstat:

Mcmd/cut.112+++++++++---
Mcmd/cut.c7+++++--
2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/cmd/cut.1 b/cmd/cut.1 @@ -10,16 +10,16 @@ .Sh SYNOPSIS .Nm .Fl b Ar list -.Op Fl nz +.Op Fl nuz .Op Ar file... .Nm .Fl c Ar list -.Op Fl z +.Op Fl uz .Op Ar file... .Nm .Fl f Ar list .Op Fl d Ar delim -.Op Fl sz +.Op Fl suz .Op Ar file... .Sh DESCRIPTION .Nm @@ -79,6 +79,8 @@ If the last byte of a codepoint is part of the selection, it gets printed, other .It Fl s Suppress lines with no delimiter characters, otherwise whole delimiter-less lines are printed as-is. +.It Fl u +Switch to line-buffering, instead of full-buffering when non-interactive. .It Fl z Use NULL as line separator instead of newline. .El @@ -89,5 +91,9 @@ Use NULL as line separator instead of newline. should be compliant with the IEEE Std 1003.1-2024 (“POSIX.1”) specification. +.Pp +The +.Fl u +option is an utils-std extension. .Sh AUTHORS .An Haelwenn (lanodan) Monnier Aq Mt contact+utils@hacktivis.me diff --git a/cmd/cut.c b/cmd/cut.c @@ -458,9 +458,9 @@ main(int argc, char *argv[]) // clang-format on // Need + as first character to get POSIX-style option parsing - for(int c = -1; (c = getopt_long(argc, argv, "+:b:c:d:f:nsz", opts, NULL)) != -1;) + for(int c = -1; (c = getopt_long(argc, argv, "+:b:c:d:f:nsuz", opts, NULL)) != -1;) #else - for(int c = -1; (c = getopt_nolong(argc, argv, ":b:c:d:f:nsz")) != -1;) + for(int c = -1; (c = getopt_nolong(argc, argv, ":b:c:d:f:nsuz")) != -1;) #endif { switch(c) @@ -509,6 +509,9 @@ main(int argc, char *argv[]) case 's': opt_s = true; break; + case 'u': + setvbuf(stdout, NULL, _IOLBF, 0); + break; case 'z': line_delim = '\0'; line_delim_w = L'\0';