9base

revived minimalist port of Plan 9 userland to Unix
git clone git://git.suckless.org/9base
Log | Files | Refs | README | LICENSE

dirfstat.c (511B)


      1 #include <u.h>
      2 #define NOPLAN9DEFINES
      3 #include <libc.h>
      4 
      5 #include <sys/stat.h>
      6 
      7 extern int _p9dir(struct stat*, struct stat*, char*, Dir*, char**, char*);
      8 
      9 Dir*
     10 dirfstat(int fd)
     11 {
     12 	struct stat st;
     13 	int nstr;
     14 	Dir *d;
     15 	char *str, tmp[100];
     16 
     17 	if(fstat(fd, &st) < 0)
     18 		return nil;
     19 
     20 	snprint(tmp, sizeof tmp, "/dev/fd/%d", fd);
     21 	nstr = _p9dir(&st, &st, tmp, nil, nil, nil);
     22 	d = mallocz(sizeof(Dir)+nstr, 1);
     23 	if(d == nil)
     24 		return nil;
     25 	str = (char*)&d[1];
     26 	_p9dir(&st, &st, tmp, d, &str, str+nstr);
     27 	return d;
     28 }
     29