On Sat, Oct 10, 2026 at 3:12 PM Pádraig Brady <[email protected]> wrote:
>
> * src/tr.c (main): Accept -u to set stdout to unbuffered.
> * NEWS: Mention the new feature.
>
> Link: https://github.com/coreutils/coreutils/issues/374
> ---
>  NEWS     | 3 +++
>  src/tr.c | 7 ++++++-
>  2 files changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/NEWS b/NEWS
> index 2d7d9b3c9..780452af6 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -48,6 +48,9 @@ GNU coreutils NEWS                                    -*- 
> outline -*-
>    'env' and 'printenv' now support the --quoting-style option
>    to control the format of printed environment variables.
>
> +  'tr' accepts the undocumented -u option to operate in unbuffered mode,
> +  for compatibility with FreeBSD and macOS tr(1).
> +
>  ** Changes in behavior
>
>    'env' and 'printenv' now quote printed environment variables only when
> diff --git a/src/tr.c b/src/tr.c
> index 7d32257d6..3a1a3b42f 100644
> --- a/src/tr.c
> +++ b/src/tr.c
> @@ -1694,7 +1694,7 @@ main (int argc, char **argv)
>
>    atexit (close_stdout);
>
> -  while ((c = getopt_long (argc, argv, "+AcCdst", long_options, NULL)) != -1)
> +  while ((c = getopt_long (argc, argv, "+AcCdstu", long_options, NULL)) != 
> -1)
>      {
>        switch (c)
>          {
> @@ -1721,6 +1721,11 @@ main (int argc, char **argv)
>            truncate_set1 = true;
>            break;
>
> +        case 'u':
> +          /* Undocumented option, for compatibility with FreeBSD/macOS.  */
> +          setvbuf (stdout, NULL, _IONBF, 0);
> +          break;
> +
>          case_GETOPT_HELP_CHAR;
>
>          case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
> --
> 2.55.0

Should you do the same for stderr?  I _think_ C does not require
stderr to be unbuffered.  Rather, C requires stderr to be not fully
buffered, which is a bit different than unbuffered.  For example,
stderr could be in a line-buffered state while not being fully
buffered based on a block size.

Jeff

Reply via email to