Skip to content

stdbuf: implement it - #257

Open
metif12 wants to merge 1 commit into
vlang:mainfrom
metif12:stdbuf-implementation
Open

metif12 wants to merge 1 commit into
vlang:mainfrom
metif12:stdbuf-implementation

Conversation

@metif12

@metif12 metif12 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

stdbuf runs a command with modified buffering for its standard streams. Options are -i, -o and -e, each taking L for line buffering, 0 for unbuffered, or a byte count with an optional k/m/g suffix.

The modes are collected and validated but not applied, and that gap is stated rather than hidden: applying them means preloading a compiled shared library that overrides setvbuf in the child, and building that library at run time is not something this port does. The command still runs, with its default buffering — the same tradeoff nice makes for niceness.

Exit codes are GNU's and were measured: 125 for anything stdbuf itself could not do, 127 for a command that could not be found, and the command's own status otherwise.

This also lands common.die and common.fail_with_help in common.common.v, because the exit status differs by failure kind and the existing common.exit_with_error_message always exited 1. Those two helpers were introduced by the nix-utils PR, which now only needs to drop its copy — moving them here first keeps this PR from depending on that one.

Verification comes in two parts, and the second is the reason this is safe to merge. Nine unit tests pin the option parsing. But common.common.v is imported by 143 files, so before committing I cross-compiled 29 tools that import it (26 across the main tree plus 3 more), and all 29 build. The diff to that file is 22 insertions and 0 deletions, so it is purely additive — no existing behaviour changes.

Runs a command with modified buffering for its standard streams. Options are -i, -o and -e, each taking L for line buffering, 0 for unbuffered, or a byte count with an optional k/m/g suffix. The modes are collected and validated but not applied, and that gap is stated rather than hidden: applying them means preloading a compiled shared library that overrides setvbuf in the child, and building that library at run time is not something this port does. The command still runs, with its default buffering, which is the same tradeoff nice makes for niceness. Exit codes are GNU's and were measured: 125 for anything stdbuf itself could not do, 127 for a command that could not be found, and the command's own status otherwise. This also lands common.die and common.fail_with_help in common.v, because the exit status differs by failure kind and the existing common.exit_with_error_message always exited 1. Those two helpers were introduced by the nix-utils branch, which now only needs to drop its copy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant