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
|| strchr(name
, '=') || !value
) {
15 oldval
= getenv(name
);
19 namelen
= strlen(name
);
20 valuelen
= strlen(value
);
21 envstr
= malloc((namelen
+ valuelen
+ 2));
27 memcpy(envstr
, name
, namelen
);
28 envstr
[namelen
] = '=';
29 memcpy(envstr
+ namelen
+ 1, value
, valuelen
);
30 envstr
[namelen
+ valuelen
+ 1] = 0;
33 /* putenv(3) makes the argument string part of the environment,
34 * and changing that string modifies the environment --- which
35 * means we do not own that storage anymore. Do not free