#include <sys/types.h>
#include <dirent.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <sys/socket.h>
#define NODEFINE
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include "fd.h"
int
pm_fstat(int fd, uchar *dat, int ndat)
{
int n;
File *f;
struct stat s;
if((f = pm_lockfile(fd, 0)) == nil){
/* pm_fprint(2, "fstat: lockfile: %r\n"); */
return -1;
}
if(fstat(f->ufd, &s) < 0){
pm_oserror();
/* pm_fprint(2, "fstat: oserror: %r\n"); */
pm_qunlock(&f->lk);
return -1;
}
n = pm_stat2buf(&s, f->path, dat, ndat);
pm_qunlock(&f->lk);
/* pm_fprint(2, "fstat: ret %d\n", n); */
return n;
}
syntax highlighted by Code2HTML, v. 0.9.1