use O_APPEND instead of extra system call
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 11 Aug 1989 06:42:44 +0000 (22:42 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Fri, 11 Aug 1989 06:42:44 +0000 (22:42 -0800)
SCCS-vsn: usr.bin/tee/tee.c 5.7

usr/src/usr.bin/tee/tee.c

index 0fc0d8a..a4ef98a 100644 (file)
@@ -22,7 +22,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)tee.c      5.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)tee.c      5.7 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -71,15 +71,12 @@ main(argc, argv)
        }
        add(1, "stdout");
        for (; *argv; ++argv)
        }
        add(1, "stdout");
        for (; *argv; ++argv)
-               if ((fd = open(*argv, append ? O_WRONLY|O_CREAT :
+               if ((fd = open(*argv, append ? O_WRONLY|O_CREAT|O_APPEND :
                    O_WRONLY|O_CREAT|O_TRUNC, 0600)) < 0)
                        (void)fprintf(stderr, "tee: %s: %s.\n",
                            *argv, strerror(errno));
                    O_WRONLY|O_CREAT|O_TRUNC, 0600)) < 0)
                        (void)fprintf(stderr, "tee: %s: %s.\n",
                            *argv, strerror(errno));
-               else {
-                       if (append)
-                               (void)lseek(fd, 0L, L_XTND);
+               else
                        add(fd, *argv);
                        add(fd, *argv);
-               }
        exitval = 0;
        while ((n = read(0, buf, sizeof(buf))) > 0)
                for (p = head; p; p = p->next)
        exitval = 0;
        while ((n = read(0, buf, sizeof(buf))) > 0)
                for (p = head; p; p = p->next)