summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorJason Riedy <ejr@EECS.Berkeley.EDU>2005-12-02 23:08:28 (GMT)
committerJunio C Hamano <junkio@cox.net>2005-12-04 06:25:25 (GMT)
commite40b61fb6bd2e0ed2dc4799096fcf4c828c28d6d (patch)
treeca541b1dfabc72d7ded00cdf15fbe6ad627e3ac8 /compat
parent7057463463ad01266db264acf7e7b5e95e7b4ecf (diff)
downloadgit-e40b61fb6bd2e0ed2dc4799096fcf4c828c28d6d.zip
git-e40b61fb6bd2e0ed2dc4799096fcf4c828c28d6d.tar.gz
git-e40b61fb6bd2e0ed2dc4799096fcf4c828c28d6d.tar.bz2
Add compat/setenv.c, use in git.c.
There is no setenv() in Solaris 5.8. The trivial calls to setenv() were replaced by putenv() in a much earlier patch, but setenv() was used again in git.c. This patch just adds a compat/setenv.c. The rule for building git$(X) also needs to include compat. objects and compiler flags. Those are now in makefile vars COMPAT_OBJS and COMPAT_CFLAGS. Signed-off-by: E. Jason Riedy <ejr@cs.berkeley.edu> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'compat')
-rw-r--r--compat/setenv.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/compat/setenv.c b/compat/setenv.c
new file mode 100644
index 0000000..94acd2d
--- /dev/null
+++ b/compat/setenv.c
@@ -0,0 +1,31 @@
+#include <stdlib.h>
+#include <string.h>
+
+int gitsetenv(const char *name, const char *value, int replace)
+{
+ int out;
+ size_t namelen, valuelen;
+ char *envstr;
+
+ if (!name || !value) return -1;
+ if (!replace) {
+ char *oldval = NULL;
+ oldval = getenv(name);
+ if (oldval) return 0;
+ }
+
+ namelen = strlen(name);
+ valuelen = strlen(value);
+ envstr = malloc((namelen + valuelen + 2) * sizeof(char));
+ if (!envstr) return -1;
+
+ memcpy(envstr, name, namelen);
+ envstr[namelen] = '=';
+ memcpy(envstr + namelen + 1, value, valuelen);
+ envstr[namelen + valuelen + 1] = 0;
+
+ out = putenv(envstr);
+
+ free(envstr);
+ return out;
+}