1 #include "../git-compat-util.h"
3 int gitsetenv(const char *name
, const char *value
, int replace
)
6 size_t namelen
, valuelen
;
9 if (!name
|| !value
) return -1;
12 oldval
= getenv(name
);
16 namelen
= strlen(name
);
17 valuelen
= strlen(value
);
18 envstr
= malloc((namelen
+ valuelen
+ 2));
19 if (!envstr
) return -1;
21 memcpy(envstr
, name
, namelen
);
22 envstr
[namelen
] = '=';
23 memcpy(envstr
+ namelen
+ 1, value
, valuelen
);
24 envstr
[namelen
+ valuelen
+ 1] = 0;
27 /* putenv(3) makes the argument string part of the environment,
28 * and changing that string modifies the environment --- which
29 * means we do not own that storage anymore. Do not free