diff options
author | Damien Miller <djm@mindrot.org> | 2010-10-07 21:39:55 +1100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2010-10-07 21:39:55 +1100 |
commit | 68e2e56ea90d88f514672991a2ac11445df0e4ac (patch) | |
tree | 04509a22c56d07cc7dcc45cf601a0a0fe2a81655 | |
parent | a6e121aaa0ab61965db2dcfe8e2ba5d719fbe1e6 (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
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | sftp.c | 18 |
2 files changed, 13 insertions, 10 deletions
@@ -13,6 +13,11 @@ | |||
13 | rountrips to fetch per-file stat(2) information. | 13 | rountrips to fetch per-file stat(2) information. |
14 | NB. update openbsd-compat/ glob(3) implementation from OpenBSD libc to | 14 | NB. update openbsd-compat/ glob(3) implementation from OpenBSD libc to |
15 | match. | 15 | match. |
16 | - djm@cvs.openbsd.org 2010/09/26 22:26:33 | ||
17 | [sftp.c] | ||
18 | when performing an "ls" in columnated (short) mode, only call | ||
19 | ioctl(TIOCGWINSZ) once to get the window width instead of per- | ||
20 | filename | ||
16 | 21 | ||
17 | 20100924 | 22 | 20100924 |
18 | - (djm) OpenBSD CVS Sync | 23 | - (djm) OpenBSD CVS Sync |
@@ -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 | |||
758 | do_globbed_ls(struct sftp_conn *conn, char *path, char *strip_path, | 758 | do_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; |