shithub: npe

Download patch

ref: 4cf6f39af2db7e9c5985ff80cc20a8b7b8567a31
parent: 6884d431e470eb75796fc408565ac0ecfba783e7
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Aug 15 21:57:33 EDT 2023

npe: add fstat

--- a/include/npe/unistd.h
+++ b/include/npe/unistd.h
@@ -41,6 +41,7 @@
 
 #define getcwd getwd
 #define stat npe_stat
+#define fstat npe_fstat
 
 struct stat {
 	uvlong st_size;
@@ -49,6 +50,7 @@
 };
 
 int npe_stat(char *filename, struct stat *buf);
+int npe_fstat(int fd, struct stat *buf);
 int fstatat(int dirfd, char *path, struct stat *buf, int flags);
 int unlink(char *path);
 int access(char *name, int mode);
--- /dev/null
+++ b/libnpe/fstat.c
@@ -1,0 +1,27 @@
+#include <unistd.h>
+#include <errno.h>
+
+#undef fstat
+
+int
+npe_fstat(int fd, struct npe_stat *buf)
+{
+	Dir *d;
+
+	if((d = dirfstat(fd)) == 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;
+}
--- a/libnpe/mkfile
+++ b/libnpe/mkfile
@@ -15,6 +15,7 @@
 	closedir.$O\
 	dirfd.$O\
 	dirname.$O\
+	fstat.$O\
 	exp2.$O\
 	fstatat.$O\
 	fts_children.$O\