shithub: npe

Download patch

ref: c42b535e5f0a337ac0d2cc34b18b718cd1e64875
parent: 36181b1c3b573d4b15eed6b66591a246875d5657
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Nov 6 20:47:44 EDT 2021

add dirfd, fstatat, unlink

--- a/include/npe/dirent.h
+++ b/include/npe/dirent.h
@@ -29,5 +29,6 @@
 DIR *opendir(char *name);
 int closedir(DIR *dirp);
 struct dirent *readdir(DIR *dirp);
+int dirfd(DIR *d);
 
 #endif
--- a/include/npe/unistd.h
+++ b/include/npe/unistd.h
@@ -49,6 +49,8 @@
 };
 
 int npe_stat(char *filename, struct stat *buf);
+int fstatat(int dirfd, char *path, struct stat *buf, int flags);
+int unlink(char *path);
 int access(char *name, int mode);
 void usleep(useconds_t us);
 int isatty(int fd);
--- /dev/null
+++ b/libnpe/dirfd.c
@@ -1,0 +1,9 @@
+#include <dirent.h>
+#include <errno.h>
+#include "_dirent.h"
+
+int
+dirfd(DIR *d)
+{
+	return d->fd;
+}
--- /dev/null
+++ b/libnpe/fstatat.c
@@ -1,0 +1,22 @@
+#include <unistd.h>
+#include <errno.h>
+
+#undef stat
+
+int
+fstatat(int dirfd, char *path, struct npe_stat *buf, int flags)
+{
+	char *s, p[8192];
+	int r;
+
+	USED(flags);
+
+	if(fd2path(dirfd, p, sizeof(p)-1) != 0)
+		return -1;
+	if((s = smprint("%s/%s", p, path)) == nil)
+		return -1;
+	r = npe_stat(s, buf);
+	free(s);
+
+	return r;
+}
--- a/libnpe/mkfile
+++ b/libnpe/mkfile
@@ -12,7 +12,9 @@
 	_main.$O\
 	_npe.$O\
 	closedir.$O\
+	dirfd.$O\
 	exp2.$O\
+	fstatat.$O\
 	fts_children.$O\
 	fts_close.$O\
 	fts_open.$O\
@@ -43,6 +45,7 @@
 	strerror.$O\
 	strftime.$O\
 	trunc.$O\
+	unlink.$O\
 	usleep.$O\
 
 UPDATE=\
--- /dev/null
+++ b/libnpe/unlink.c
@@ -1,0 +1,7 @@
+#include <unistd.h>
+
+int
+unlink(char *path)
+{
+	return remove(path);
+}