summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@centraldogma>2011-09-16 07:39:59 +0200
committercinap_lenrek <cinap_lenrek@centraldogma>2011-09-16 07:39:59 +0200
commiteec5314f911db5b02898f7cf74256e9018e38071 (patch)
tree9509638cc79c0e78c0fdbcf58526fe99e67262cb
parentafd843c6914d85dced3bd133193ceca2232331af (diff)
page: sort pages in directories/archives by name
-rw-r--r--sys/src/cmd/page.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/sys/src/cmd/page.c b/sys/src/cmd/page.c
index 4a3842b94..a25c54e29 100644
--- a/sys/src/cmd/page.c
+++ b/sys/src/cmd/page.c
@@ -241,8 +241,9 @@ popenconv(Page *p)
int
popentape(Page *p)
{
- char mnt[32], cmd[NPATH], *argv[4];
+ char mnt[32], cmd[64], *argv[4];
+ seek(p->fd, 0, 0);
snprint(mnt, sizeof(mnt), "/n/tapefs.%.12d%.8lux", getpid(), (ulong)p);
switch(rfork(RFREND|RFPROC|RFFDG)){
case -1:
@@ -251,6 +252,7 @@ popentape(Page *p)
return -1;
case 0:
dup(p->fd, 0);
+ close(p->fd);
argv[0] = "rc";
argv[1] = "-c";
snprint(cmd, sizeof(cmd), "%s -m %s /fd/0", p->data, mnt);
@@ -259,11 +261,11 @@ popentape(Page *p)
exec("/bin/rc", argv);
sysfatal("exec: %r");
}
- waitpid();
close(p->fd);
+ waitpid();
p->fd = -1;
- p->open = popenfile;
p->data = strdup(mnt);
+ p->open = popenfile;
return p->open(p);
}
@@ -494,6 +496,17 @@ Out:
}
int
+dircmp(void *p1, void *p2)
+{
+ Dir *d1, *d2;
+
+ d1 = p1;
+ d2 = p2;
+
+ return strcmp(d1->name, d2->name);
+}
+
+int
popenfile(Page *p)
{
char buf[NBUF], *file;
@@ -522,6 +535,7 @@ popenfile(Page *p)
d = nil;
if((n = dirreadall(fd, &d)) < 0)
goto Err1;
+ qsort(d, n, sizeof d[0], dircmp);
for(i = 0; i<n; i++)
addpage(p, d[i].name, popenfile, smprint("%s/%s", file, d[i].name), -1);
free(d);