summaryrefslogtreecommitdiff
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
parenta6e121aaa0ab61965db2dcfe8e2ba5d719fbe1e6 (diff)
downloadopenssh-git-68e2e56ea90d88f514672991a2ac11445df0e4ac.tar.gz
- 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
-rw-r--r--ChangeLog5
-rw-r--r--sftp.c18
2 files changed, 13 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index f6588cca..b9d763a7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -13,6 +13,11 @@
rountrips to fetch per-file stat(2) information.
NB. update openbsd-compat/ glob(3) implementation from OpenBSD libc to
match.
+ - 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
20100924
- (djm) OpenBSD CVS Sync
diff --git a/sftp.c b/sftp.c
index 46bee198..7b4a8523 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.128 2010/09/25 09:30:16 djm Exp $ */
+/* $OpenBSD: sftp.c,v 1.129 2010/09/26 22:26:33 djm Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
*
@@ -758,11 +758,12 @@ static int
do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
int lflag)
{
- glob_t g;
- u_int i, c = 1, colspace = 0, columns = 1;
Attrib *a = NULL;
- int err;
char *fname, *lname;
+ glob_t g;
+ int err;
+ struct winsize ws;
+ u_int i, c = 1, colspace = 0, columns = 1, m = 0, width = 80;
memset(&g, 0, sizeof(g));
@@ -789,17 +790,14 @@ do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path,
return err;
}
- if (!(lflag & LS_SHORT_VIEW)) {
- u_int m = 0, width = 80;
- struct winsize ws;
+ if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
+ width = ws.ws_col;
+ if (!(lflag & LS_SHORT_VIEW)) {
/* Count entries for sort and find longest filename */
for (i = 0; g.gl_pathv[i]; i++)
m = MAX(m, strlen(g.gl_pathv[i]));
- if (ioctl(fileno(stdin), TIOCGWINSZ, &ws) != -1)
- width = ws.ws_col;
-
columns = width / (m + 2);
columns = MAX(columns, 1);
colspace = width / columns;