chiark / gitweb /
Portability and doc fixes, including my own portability patches and some suggestions...
[userv.git] / lib.c
diff --git a/lib.c b/lib.c
index 7a22d19eae1e96a29dd9214447f33e1024b8418b..bd40ee08ab77376f74b1ce5715b9740a16c82e71 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -25,6 +25,7 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
+#include <assert.h>
 #include <sys/types.h>
 
 #include "config.h"
@@ -112,3 +113,19 @@ void snytprintfcat(char *buffer, size_t size, const char *fmt, ...) {
   vsnytprintfcat(buffer,size,fmt,al);
   va_end(al);
 }
+
+#ifndef HAVE_SETENV
+int setenv(const char *name, const char *value, int overwrite) {
+  static char *buffer= 0;
+  static int avail= 0;
+
+  int r;
+  
+  assert(overwrite==1);
+  r= makeroom(&buffer,&avail,strlen(name)+strlen(value)+2);
+  if (r) { errno= EINVAL; return -1; }
+
+  sprintf(buffer,"%s=%s",name,value);
+  return putenv(buffer);
+}
+#endif /* HAVE_SETENV */