Browse Source

Merge branch 'ef/setenv-putenv' into maint

* ef/setenv-putenv:
  compat/setenv.c: error if name contains '='
  compat/setenv.c: update errno when erroring out
maint
Junio C Hamano 13 years ago
parent
commit
e8f6b51a6b
  1. 10
      compat/setenv.c

10
compat/setenv.c

@ -6,7 +6,10 @@ int gitsetenv(const char *name, const char *value, int replace)
size_t namelen, valuelen; size_t namelen, valuelen;
char *envstr; char *envstr;


if (!name || !value) return -1; if (!name || strchr(name, '=') || !value) {
errno = EINVAL;
return -1;
}
if (!replace) { if (!replace) {
char *oldval = NULL; char *oldval = NULL;
oldval = getenv(name); oldval = getenv(name);
@ -16,7 +19,10 @@ int gitsetenv(const char *name, const char *value, int replace)
namelen = strlen(name); namelen = strlen(name);
valuelen = strlen(value); valuelen = strlen(value);
envstr = malloc((namelen + valuelen + 2)); envstr = malloc((namelen + valuelen + 2));
if (!envstr) return -1; if (!envstr) {
errno = ENOMEM;
return -1;
}


memcpy(envstr, name, namelen); memcpy(envstr, name, namelen);
envstr[namelen] = '='; envstr[namelen] = '=';

Loading…
Cancel
Save