Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!njin!princeton!notecnirp!nfs From: nfs@notecnirp.Princeton.EDU (Norbert Schlenker) Newsgroups: comp.os.minix Subject: Tee bug and fix Keywords: tee create append bug fix Message-ID: <18226@princeton.Princeton.EDU> Date: 18 Jul 89 04:14:54 GMT References: <1951@ast.cs.vu.nl> Sender: news@princeton.Princeton.EDU Reply-To: nfs@notecnirp.UUCP (Norbert Schlenker) Organization: Dept. of Computer Science, Princeton University Lines: 44 The tee command has been broken since Minix was born. Standard distributions up to and including v1.3 have the problem that an invocation without the -a flag will not truncate an existing file, potentially leaving trash at the end. A patch to fix this problem was included in the v1.4a cdiffs from Andy Tanenbaum; unfortunately, that patch has resulted in a tee command which will not create a brand new file when the -a flag IS specified. The following is a (normal) diff from the standard v1.3 tee.c that fixes both problems. ------------------------------ Cut here ------------------------------ 3c3 < #include --- > #include 37,45c37,48 < for (s = 1; s < MAXFD && argc > 0; --argc, argv++) { < if ((fd[s] = open(*argv, 2)) < 0 && < (fd[s] = creat(*argv, 0666)) < 0) { < std_err("Cannot open output file: "); < std_err(*argv); < std_err("\n"); < exit(2); < } < s++; --- > for (s = 1; s < MAXFD && argc > 0; --argc, argv++, s++) { > if (aflag && (fd[s] = open(*argv, 2)) >= 0) { > lseek(fd[s], 0L, 2); > continue; > } else { > if ((fd[s] = creat(*argv, 0666)) >= 0) > continue; > } > std_err("Cannot open output file: "); > std_err(*argv); > std_err("\n"); > exit(2); 50,53d52 < for (i = 1; i < s; i++) { /* Don't lseek stdout. */ < if (aflag) < lseek(fd[i], 0L, 2); < }