diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2010-09-26 22:26:34 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2010-09-26 22:26:34 +0000 |
commit | 7c443c70a190dd7de73b27d5d84eb2363f9192de (patch) | |
tree | d9ac785ca5cfb433f5f9876feb6af24b2ea4f7d7 /usr.bin/ssh/sftp.c | |
parent | b3a37071e2f5a49de4e7fd471b4ac4c1ce0f4111 (diff) |
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 'usr.bin/ssh/sftp.c')
-rw-r--r-- | usr.bin/ssh/sftp.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/usr.bin/ssh/sftp.c b/usr.bin/ssh/sftp.c index 549f4a6a5a4..c4a5d9e87ff 100644 --- a/usr.bin/ssh/sftp.c +++ b/usr.bin/ssh/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> * @@ -735,11 +735,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)); @@ -766,17 +767,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; |