summaryrefslogtreecommitdiff
path: root/sftp.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2010-10-07 21:39:55 +1100
committerDamien Miller <djm@mindrot.org>2010-10-07 21:39:55 +1100
commit68e2e56ea90d88f514672991a2ac11445df0e4ac (patch)
tree04509a22c56d07cc7dcc45cf601a0a0fe2a81655 /sftp.c
parenta6e121aaa0ab61965db2dcfe8e2ba5d719fbe1e6 (diff)
- djm@cvs.openbsd.org 2010/09/26 22:26:33
[sftp.c] when performing an "ls" in columnated (short) mode, only call ioctl(TIOCGWINSZ) once to get the window width instead of per- filename
Diffstat (limited to 'sftp.c')
-rw-r--r--sftp.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/sftp.c b/sftp.c
index 46bee1982..7b4a85235 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp.c,v 1.128 2010/09/25 09:30:16 djm Exp $ */ 1/* $OpenBSD: sftp.c,v 1.129 2010/09/26 22:26:33 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -758,11 +758,12 @@ static int
758do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, 758do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
759 int lflag) 759 int lflag)
760{ 760{
761 glob_t g;
762 u_int i, c = 1, colspace = 0, columns = 1;
763 Attrib *a = NULL; 761 Attrib *a = NULL;
764 int err;
765 char *fname, *lname; 762 char *fname, *lname;
763 glob_t g;
764 int err;
765 struct winsize ws;
766 u_int i, c = 1, colspace = 0, columns = 1, m = 0, width = 80;
766 767
767 memset(&g, 0, sizeof(g)); 768 memset(&g, 0, sizeof(g));
768 769
@@ -789,17 +790,14 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
789 return err; 790 return err;
790 } 791 }
791 792
792 if (!(lflag & LS_SHORT_VIEW)) { 793 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
793 u_int m = 0, width = 80; 794 width = ws.ws_col;
794 struct winsize ws;
795 795
796 if (!(lflag & LS_SHORT_VIEW)) {
796 /* Count entries for sort and find longest filename */ 797 /* Count entries for sort and find longest filename */
797 for (i = 0; g.gl_pathv[i]; i++) 798 for (i = 0; g.gl_pathv[i]; i++)
798 m = MAX(m, strlen(g.gl_pathv[i])); 799 m = MAX(m, strlen(g.gl_pathv[i]));
799 800
800 if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
801 width = ws.ws_col;
802
803 columns = width / (m + 2); 801 columns = width / (m + 2);
804 columns = MAX(columns, 1); 802 columns = MAX(columns, 1);
805 colspace = width / columns; 803 colspace = width / columns;