diff options
author | rsc <devnull@localhost> | 2003-11-23 18:12:54 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2003-11-23 18:12:54 +0000 |
commit | fd04aacee17b348da206c13a550dc1029669805f (patch) | |
tree | 9bdd35a25ff6e3d6e9a0171b06240a76723f922c /src/lib9/dirstat.c | |
parent | 74f990ad84deb1591ddb91be4fc8152ec0c46222 (diff) | |
download | plan9port-fd04aacee17b348da206c13a550dc1029669805f.tar.gz plan9port-fd04aacee17b348da206c13a550dc1029669805f.tar.bz2 plan9port-fd04aacee17b348da206c13a550dc1029669805f.zip |
Various additions and fixes.
Diffstat (limited to 'src/lib9/dirstat.c')
-rw-r--r-- | src/lib9/dirstat.c | 99 |
1 files changed, 22 insertions, 77 deletions
diff --git a/src/lib9/dirstat.c b/src/lib9/dirstat.c index fb9cd0ac..253a9056 100644 --- a/src/lib9/dirstat.c +++ b/src/lib9/dirstat.c @@ -1,83 +1,28 @@ -#include "u.h" -#include "libc.h" -#include <sys/types.h> -#include <sys/stat.h> -#include <pwd.h> -#include <grp.h> - -static void -statconv(Dir *dir, struct stat *s) -{ - struct passwd *p; - struct group *g; - ulong q; - - p = getpwuid(s->st_uid); - if (p) - strncpy(dir->uid, p->pw_name, NAMELEN); - g = getgrgid(s->st_gid); - if (g) - strncpy(dir->gid, g->gr_name, NAMELEN); - q = 0; - if(S_ISDIR(s->st_mode)) - q = CHDIR; - q |= s->st_ino & 0x00FFFFFFUL; - dir->qid.path = q; - dir->qid.vers = s->st_mtime; - dir->mode = (dir->qid.path&CHDIR)|(s->st_mode&0777); - dir->atime = s->st_atime; - dir->mtime = s->st_mtime; - dir->length = s->st_size; - dir->dev = s->st_dev; - dir->type = 'M'; - if(S_ISFIFO(s->st_mode)) - dir->type = '|'; -} - -int -dirfstat(int fd, Dir *d) -{ - struct stat sbuf; - - if(fstat(fd, &sbuf) < 0) - return -1; - statconv(d, &sbuf); - return 0; -} +#include <u.h> +#define NOPLAN9DEFINES +#include <libc.h> -static char * -lelem(char *path) -{ - char *pr; - - pr = utfrrune(path, '/'); - if(pr) - pr++; - else - pr = path; - return pr; -} - -int -dirstat(char *f, Dir *d) -{ - struct stat sbuf; +#include <sys/stat.h> - if(stat(f, &sbuf) < 0) - return -1; - statconv(d, &sbuf); - strncpy(d->name, lelem(f), NAMELEN); - return 0; -} +extern int _p9dir(struct stat*, char*, Dir*, char**, char*); -int -dirfwstat(int fd, Dir *d) +Dir* +dirstat(char *file) { - return -1; + struct stat st; + int nstr; + Dir *d; + char *str; + + if(stat(file, &st) < 0) + return nil; + + nstr = _p9dir(&st, file, nil, nil, nil); + d = mallocz(sizeof(Dir)+nstr, 1); + if(d == nil) + return nil; + str = (char*)&d[1]; + _p9dir(&st, file, d, &str, str+nstr); + return d; } -int -dirwstat(char *name, Dir *d) -{ - return -1; -} |