always have a termwidth, even if not to a tty
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 27 Jun 1989 07:32:47 +0000 (23:32 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Tue, 27 Jun 1989 07:32:47 +0000 (23:32 -0800)
SCCS-vsn: bin/ls/ls.c 5.23

usr/src/bin/ls/ls.c

index 4043ad5..5b8bf9a 100644 (file)
@@ -25,7 +25,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)ls.c       5.22 (Berkeley) %G%";
+static char sccsid[] = "@(#)ls.c       5.23 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -42,6 +42,8 @@ char *emalloc();
 
 int    qflg, Aflg, Cflg, Fflg, Lflg, Rflg, Sflg;
 
 
 int    qflg, Aflg, Cflg, Fflg, Lflg, Rflg, Sflg;
 
+int termwidth = 80;            /* default terminal width */
+
 /* flags */
 int f_accesstime;              /* use time of last access */
 int f_group;                   /* show group ownership of a file */
 /* flags */
 int f_accesstime;              /* use time of last access */
 int f_group;                   /* show group ownership of a file */
@@ -81,8 +83,10 @@ main(argc, argv)
        if (isatty(1)) {
                f_nonprint = 1;
                (void)ioctl(1, TIOCGETP, &sgbuf);
        if (isatty(1)) {
                f_nonprint = 1;
                (void)ioctl(1, TIOCGETP, &sgbuf);
-               if (ioctl(1, TIOCGWINSZ, &win) == -1 || !win.ws_col)
-                       termwidth = (p = getenv("COLUMNS")) ? atoi(p) : 80;
+               if (ioctl(1, TIOCGWINSZ, &win) == -1 || !win.ws_col) {
+                       if (p = getenv("COLUMNS"))
+                               termwidth = atoi(p);
+               }
                else
                        termwidth = win.ws_col;
        } else
                else
                        termwidth = win.ws_col;
        } else