mirror of
https://github.com/git/git.git
synced 2024-11-24 18:33:43 +08:00
e40b61fb6b
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>
32 lines
619 B
C
32 lines
619 B
C
#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;
|
|
}
|