nfs@notecnirp.Princeton.EDU (Norbert Schlenker) (07/18/89)
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 <minix/blocksize.h> --- > #include <minix/const.h> 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); < }