Add tee builtin#1
Open
owen499 wants to merge 1 commit into
Open
Conversation
Implements POSIX-subset tee (`tee [-a] [file...]`) as a builtin so pipelines can fan out stdin to stdout and one or more files without forking an external binary. Supports -a for append mode and reports per-file open errors via stderr while still writing successfully opened files.
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="srcs/builtin/tee.c">
<violation number="1" location="srcs/builtin/tee.c:63">
P2: Return values of `write()` are ignored, which can silently lose data on partial writes or I/O errors. At minimum, a failed `write(1, …)` (broken stdout pipe) should stop the loop, and failed file writes should set `g_status = 1` — consistent with the error reporting you already do for `open()` failures.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
| r = read(0, buf, sizeof(buf)); | ||
| while (r > 0) | ||
| { | ||
| write(1, buf, r); |
There was a problem hiding this comment.
P2: Return values of write() are ignored, which can silently lose data on partial writes or I/O errors. At minimum, a failed write(1, …) (broken stdout pipe) should stop the loop, and failed file writes should set g_status = 1 — consistent with the error reporting you already do for open() failures.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At srcs/builtin/tee.c, line 63:
<comment>Return values of `write()` are ignored, which can silently lose data on partial writes or I/O errors. At minimum, a failed `write(1, …)` (broken stdout pipe) should stop the loop, and failed file writes should set `g_status = 1` — consistent with the error reporting you already do for `open()` failures.</comment>
<file context>
@@ -0,0 +1,101 @@
+ r = read(0, buf, sizeof(buf));
+ while (r > 0)
+ {
+ write(1, buf, r);
+ i = -1;
+ while (++i < n)
</file context>
Owner
Author
|
@cubic-dev-ai plz review this PR |
@owen499 I have started the AI code review. It will take a few minutes to complete. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
teebuiltin:tee [-a] [file...]— fan stdin out to stdout and any number of files (default 256 cap)check_builtin()dispatch so it runs in-process without forking an external binarysrcs/builtin/tee.cto the MakefileBehavior
-aswitchesO_TRUNC→O_APPEND; default mode is0644minishell: tee: <path>: <strerror>to stderr and setg_status = 1, but do not abort the remaining writers42 Norm compliance
ft_strequ,ft_putstr_fd,ft_putendl_fd) andg_statusTest plan
makebuilds clean on Linux (macOS clang has unrelated -Wunused-but-set-variable noise in pre-existing files)echo hi | ./minishell -c 'tee out.txt'writeshito both stdout andout.txtprintf 'a\nb\n' | ./minishell -c 'tee -a log.txt'appends without truncating prior contentecho x | ./minishell -c 'tee /root/no'prints permission-denied error and continues; exit status reflects failureSummary by cubic
Adds a POSIX-style
teebuiltin to fan stdin to stdout and files, with append support. Runs in-process to avoid spawning an externaltee, improving pipeline performance.tee [-a] [file...]; reads in 4096-byte chunks; writes to stdout and up to 256 files (0644 default mode).-aappends instead of truncating; per-file open errors print to stderr, continue, and setg_status=1.check_builtin()to run in-process and avoid forking.Written for commit 5c1a554. Summary will update on new commits. Review in cubic