aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/9p.c
diff options
context:
space:
mode:
authorAnthony Martin <ality@pbrane.org>2010-06-28 14:33:30 -0700
committerRuss Cox <rsc@swtch.com>2010-06-28 14:33:30 -0700
commit0efbfd36f554a534750bbebb1e68a76aada3faa6 (patch)
tree611712a338c6ff96ff88e750209de65ad986a406 /src/cmd/9p.c
parentc988c8adf1d997d87ab792f68be0932fed74e9cd (diff)
downloadplan9port-0efbfd36f554a534750bbebb1e68a76aada3faa6.tar.gz
plan9port-0efbfd36f554a534750bbebb1e68a76aada3faa6.tar.bz2
plan9port-0efbfd36f554a534750bbebb1e68a76aada3faa6.zip
9p: tflag sorts by mtime
R=rsc CC=codebot http://codereview.appspot.com/1265043
Diffstat (limited to 'src/cmd/9p.c')
-rw-r--r--src/cmd/9p.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/cmd/9p.c b/src/cmd/9p.c
index ed80f5a6..6d329d6d 100644
--- a/src/cmd/9p.c
+++ b/src/cmd/9p.c
@@ -476,6 +476,21 @@ dircmp(const void *va, const void *vb)
return strcmp(a->name, b->name);
}
+static int
+timecmp(const void *va, const void *vb)
+{
+ Dir *a, *b;
+
+ a = (Dir*)va;
+ b = (Dir*)vb;
+ if(a->mtime < b->mtime)
+ return -1;
+ else if(a->mtime > b->mtime)
+ return 1;
+ else
+ return 0;
+}
+
char *dot[] = { "." };
void
@@ -483,14 +498,14 @@ xls(int argc, char **argv)
{
char *err, *name, *xname, *f[4], buf[4096];
int nf, i, j, l, sort;
- int lflag, dflag, n, len[4];
+ int lflag, dflag, tflag, n, len[4];
Dir *d;
CFid *fid;
CFsys *fs;
err = nil;
- sort = 0;
- lflag = dflag = 0;
+ sort = 1;
+ lflag = dflag = tflag = 0;
ARGBEGIN{
case 'n':
sort = 0;
@@ -501,6 +516,9 @@ xls(int argc, char **argv)
case 'd':
dflag = 1;
break;
+ case 't':
+ tflag = 1;
+ break;
}ARGEND
fmtinstall('D', dirfmt);
@@ -538,8 +556,12 @@ xls(int argc, char **argv)
err = "errors";
continue;
}
- if(sort)
- qsort(d, n, sizeof d[0], dircmp);
+ if(sort){
+ if(tflag)
+ qsort(d, n, sizeof d[0], timecmp);
+ else
+ qsort(d, n, sizeof d[0], dircmp);
+ }
for(j=0; j<4; j++)
len[j] = 0;
for(i=0; i<n; i++){