~sircmpwn/ctools

tee: Fix missing output file truncation v1 PROPOSED

Gabor Koszegi
Gabor Koszegi: 1
 tee: Fix missing output file truncation

 2 files changed, 7 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/ctools/patches/9237/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] tee: Fix missing output file truncation Export this patch

Gabor Koszegi
---
Overwritten files shall be truncated to zero length. This feature was
missing from the original version.

 src/tee.c | 2 +-
 test/tee  | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/tee.c b/src/tee.c
index 4749382..f4fa895 100644
--- a/src/tee.c
+++ b/src/tee.c
@@ -74,7 +74,7 @@ cleanup:
int
main(int argc, char *argv[])
{
	int aflag = 0;
	int aflag = O_TRUNC;

	char opt;
	while ((opt = getopt(argc, argv, "ai")) != -1) {
diff --git a/test/tee b/test/tee
index dbab3d6..656f1e0 100755
--- a/test/tee
+++ b/test/tee
@@ -10,7 +10,12 @@ should_handle_zero_file() (
should_handle_one_file() (
	stdout="$(echo "tesT 1ine" | tee "$TMPDIR"/one-file)"
	res="$(cat "$TMPDIR"/one-file)"
	[ "$res" = "tesT 1ine" ] && [ "$res" = "$stdout" ]
	[ "$res" = "tesT 1ine" ] && [ "$res" = "$stdout" ] || return 1

	echo "a really long line for test" >"$TMPDIR"/one-file
	stdout="$(echo "shorter line" | tee "$TMPDIR"/one-file)"
	res="$(cat "$TMPDIR"/one-file)"
	[ "$res" = "shorter line" ] && [ "$res" = "$stdout" ]
)

should_handle_two_files() (
-- 
2.22.0
Thanks!

To git.sr.ht:~sircmpwn/ctools
   f2d5838..fbf17d9  master -> master