summaryrefslogtreecommitdiff
path: root/sftp-common.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2010-01-13 22:44:06 +1100
committerDarren Tucker <dtucker@zip.com.au>2010-01-13 22:44:06 +1100
commit2901e2daebe3a0890209f31d05d5bb9338cbed5b (patch)
tree8165aef201520ede26777b48b3c9e777245e2616 /sftp-common.c
parentdaaa4500519627abee7c6d1969bc33df6572c1e8 (diff)
- djm@cvs.openbsd.org 2010/01/13 01:40:16
[sftp.c sftp-server.c sftp.1 sftp-common.c sftp-common.h] support '-h' (human-readable units) for sftp's ls command, just like ls(1); ok dtucker@
Diffstat (limited to 'sftp-common.c')
-rw-r--r--sftp-common.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/sftp-common.c b/sftp-common.c
index 7ebadcc53..7393fc6a9 100644
--- a/sftp-common.c
+++ b/sftp-common.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-common.c,v 1.20 2006/08/03 03:34:42 deraadt Exp $ */ 1/* $OpenBSD: sftp-common.c,v 1.21 2010/01/13 01:40:16 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2001 Damien Miller. All rights reserved. 4 * Copyright (c) 2001 Damien Miller. All rights reserved.
@@ -36,6 +36,7 @@
36#include <string.h> 36#include <string.h>
37#include <time.h> 37#include <time.h>
38#include <stdarg.h> 38#include <stdarg.h>
39#include <util.h>
39 40
40#include "xmalloc.h" 41#include "xmalloc.h"
41#include "buffer.h" 42#include "buffer.h"
@@ -184,7 +185,7 @@ fx2txt(int status)
184 * drwxr-xr-x 5 markus markus 1024 Jan 13 18:39 .ssh 185 * drwxr-xr-x 5 markus markus 1024 Jan 13 18:39 .ssh
185 */ 186 */
186char * 187char *
187ls_file(const char *name, const struct stat *st, int remote) 188ls_file(const char *name, const struct stat *st, int remote, int si_units)
188{ 189{
189 int ulen, glen, sz = 0; 190 int ulen, glen, sz = 0;
190 struct passwd *pw; 191 struct passwd *pw;
@@ -192,6 +193,7 @@ ls_file(const char *name, const struct stat *st, int remote)
192 struct tm *ltime = localtime(&st->st_mtime); 193 struct tm *ltime = localtime(&st->st_mtime);
193 char *user, *group; 194 char *user, *group;
194 char buf[1024], mode[11+1], tbuf[12+1], ubuf[11+1], gbuf[11+1]; 195 char buf[1024], mode[11+1], tbuf[12+1], ubuf[11+1], gbuf[11+1];
196 char sbuf[FMT_SCALED_STRSIZE];
195 197
196 strmode(st->st_mode, mode); 198 strmode(st->st_mode, mode);
197 if (!remote && (pw = getpwuid(st->st_uid)) != NULL) { 199 if (!remote && (pw = getpwuid(st->st_uid)) != NULL) {
@@ -216,8 +218,15 @@ ls_file(const char *name, const struct stat *st, int remote)
216 tbuf[0] = '\0'; 218 tbuf[0] = '\0';
217 ulen = MAX(strlen(user), 8); 219 ulen = MAX(strlen(user), 8);
218 glen = MAX(strlen(group), 8); 220 glen = MAX(strlen(group), 8);
219 snprintf(buf, sizeof buf, "%s %3u %-*s %-*s %8llu %s %s", mode, 221 if (si_units) {
220 (u_int)st->st_nlink, ulen, user, glen, group, 222 fmt_scaled((long long)st->st_size, sbuf);
221 (unsigned long long)st->st_size, tbuf, name); 223 snprintf(buf, sizeof buf, "%s %3u %-*s %-*s %8s %s %s", mode,
224 (u_int)st->st_nlink, ulen, user, glen, group,
225 sbuf, tbuf, name);
226 } else {
227 snprintf(buf, sizeof buf, "%s %3u %-*s %-*s %8llu %s %s", mode,
228 (u_int)st->st_nlink, ulen, user, glen, group,
229 (unsigned long long)st->st_size, tbuf, name);
230 }
222 return xstrdup(buf); 231 return xstrdup(buf);
223} 232}