shithub: npe

ref: 13c0e712ae7d999f8df7f335cb6eaf7e48a3feb9
dir: /libnpe/stat.c/

View raw version
#include <unistd.h>
#include <errno.h>

#undef stat

int
npe_stat(char *filename, struct npe_stat *buf)
{
	Dir *d;

	if((d = dirstat(filename)) == nil){
		errno = ENOENT;
		return -1;
	}

	buf->st_size = d->length;
	buf->st_mtime = d->mtime;
	buf->st_mode = d->mode & 0777;
	if(d->mode & DMDIR)
		buf->st_mode |= S_IFDIR;
	else
		buf->st_mode |= S_IFREG;

	free(d);

	return 0;
}