shithub: npe

Download patch

ref: 63fe8a7a0105321c24a1fa79c6fef01c943a54ad
parent: a6aae696352131bc5f41bb104b7df9401aae7d2a
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Feb 7 07:09:18 EST 2023

add realpath() and ENAMETOOLONG

--- a/include/npe/errno.h
+++ b/include/npe/errno.h
@@ -7,6 +7,7 @@
 	ENOENT = 2,
 	EINVAL = 22,
 	ERANGE = 34,
+	ENAMETOOLONG = 36,
 };
 
 extern int errno;
--- a/include/npe/stdlib.h
+++ b/include/npe/stdlib.h
@@ -8,5 +8,6 @@
 #define EXIT_FAILURE 1
 
 int setenv(char *name, char *value, int overwrite);
+char *realpath(char *path, char *buffer);
 
 #endif
--- a/libnpe/mkfile
+++ b/libnpe/mkfile
@@ -37,6 +37,7 @@
 	mktime.$O\
 	opendir.$O\
 	readdir.$O\
+	realpath.$O\
 	rename.$O\
 	round.$O\
 	setenv.$O\
--- /dev/null
+++ b/libnpe/realpath.c
@@ -1,0 +1,19 @@
+#include <u.h>
+#include <libc.h>
+#include "limits.h"
+
+char *
+realpath(char *path, char *buffer)
+{
+	char *s, p[PATH_MAX];
+	int f;
+
+	s = nil;
+	if((f = open(path, OREAD)) < 0){
+		if(fd2path(f, p, sizeof(p)) == 0)
+			s = buffer == nil ? strdup(p) : strcpy(buffer, p);
+		close(f);
+	}
+
+	return s;
+}