diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-08-04 16:21:37 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2020-08-04 16:21:37 +0200 |
commit | 53800208bd762b1ecf14b60585cb906f22db7de8 (patch) | |
tree | 9e6d280180c845375cb878fe5ec0b402e738a1c8 /sys/src/cmd/rc/plan9.c | |
parent | e9df4c718a902fe6a8f490331092c2f92c194ce4 (diff) |
rc: avoid stat calls for directory globbing
On Plan9, we can count on Readdir() onlydirs argument
to work, which allows us to avoid stating every single
file to see if it is a directory.
Diffstat (limited to 'sys/src/cmd/rc/plan9.c')
-rw-r--r-- | sys/src/cmd/rc/plan9.c | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/sys/src/cmd/rc/plan9.c b/sys/src/cmd/rc/plan9.c index fd12e666c..4ac9a0bf7 100644 --- a/sys/src/cmd/rc/plan9.c +++ b/sys/src/cmd/rc/plan9.c @@ -345,23 +345,15 @@ struct{ int Opendir(char *name) { - Dir *db; int f; - f = open(name, 0); - if(f==-1) - return f; - db = dirfstat(f); - if(db!=nil && (db->mode&DMDIR)){ - if(f<NFD){ - dir[f].i = 0; - dir[f].n = 0; - } - free(db); + + if((f = open(name, 0)) < 0) return f; + if(f<NFD){ + dir[f].i = 0; + dir[f].n = 0; } - free(db); - close(f); - return -1; + return f; } static int @@ -375,13 +367,6 @@ trimdirs(Dir *d, int nd) return w; } -/* - * onlydirs is advisory -- it means you only - * need to return the directories. it's okay to - * return files too (e.g., on unix where you can't - * tell during the readdir), but that just makes - * the globber work harder. - */ int Readdir(int f, void *p, int onlydirs) { |