summaryrefslogtreecommitdiff
path: root/compat/setenv.c
diff options
context:
space:
mode:
authorErik Faye-Lund <kusmabite@gmail.com>2011-12-14 14:07:08 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-12-15 03:30:41 (GMT)
commit57590c72b4d3b02e32732c7d79514c0281d6c2b5 (patch)
treec2defaec51ac733b75adfed58d91b3072863c2c4 /compat/setenv.c
parent10dd3b2bf1444695416c0dac951297acf7d4e5e4 (diff)
downloadgit-57590c72b4d3b02e32732c7d79514c0281d6c2b5.zip
git-57590c72b4d3b02e32732c7d79514c0281d6c2b5.tar.gz
git-57590c72b4d3b02e32732c7d79514c0281d6c2b5.tar.bz2
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>
Diffstat (limited to 'compat/setenv.c')
-rw-r--r--compat/setenv.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/compat/setenv.c b/compat/setenv.c
index 3a22ea7..89947b7 100644
--- a/compat/setenv.c
+++ b/compat/setenv.c
@@ -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] = '=';