mirror of
https://github.com/git/git
synced 2024-08-24 18:26:02 +00:00
compat/setenv.c: update errno when erroring out
Previously, gitsetenv didn't update errno as it should when erroring out. Fix this. Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
10dd3b2bf1
commit
57590c72b4
|
@ -6,7 +6,10 @@ int gitsetenv(const char *name, const char *value, int replace)
|
|||
size_t namelen, valuelen;
|
||||
char *envstr;
|
||||
|
||||
if (!name || !value) return -1;
|
||||
if (!name || !value) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
if (!replace) {
|
||||
char *oldval = NULL;
|
||||
oldval = getenv(name);
|
||||
|
@ -16,7 +19,10 @@ int gitsetenv(const char *name, const char *value, int replace)
|
|||
namelen = strlen(name);
|
||||
valuelen = strlen(value);
|
||||
envstr = malloc((namelen + valuelen + 2));
|
||||
if (!envstr) return -1;
|
||||
if (!envstr) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(envstr, name, namelen);
|
||||
envstr[namelen] = '=';
|
||||
|
|
Loading…
Reference in a new issue