shithub: npe

Download patch

ref: b9dcbb8b9ff5526f470d5825043752f28533217b
parent: bd64760ce92e4da423a9330021e8f09b0de5fc73
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun Jun 20 07:42:05 EDT 2021

stdlib: add setenv

--- a/include/npe/stdlib.h
+++ b/include/npe/stdlib.h
@@ -7,4 +7,6 @@
 #define EXIT_SUCCESS 0
 #define EXIT_FAILURE 1
 
+int setenv(char *name, char *value, int overwrite);
+
 #endif
--- a/libnpe/mkfile
+++ b/libnpe/mkfile
@@ -34,6 +34,7 @@
 	readdir.$O\
 	rename.$O\
 	round.$O\
+	setenv.$O\
 	sigaction.$O\
 	stat.$O\
 	strerror.$O\
--- /dev/null
+++ b/libnpe/setenv.c
@@ -1,0 +1,15 @@
+#include <u.h>
+#include <libc.h>
+
+int
+setenv(char *name, char *value, int overwrite)
+{
+	char *s;
+
+	if(overwrite == 0 && (s = getenv(name)) != nil){
+		free(s);
+		return 0;
+	}
+
+	return putenv(name, value);
+}