4 int gitsetenv(const char *name
, const char *value
, int replace
)
7 size_t namelen
, valuelen
;
10 if (!name
|| !value
) return -1;
13 oldval
= getenv(name
);
17 namelen
= strlen(name
);
18 valuelen
= strlen(value
);
19 envstr
= malloc((namelen
+ valuelen
+ 2));
20 if (!envstr
) return -1;
22 memcpy(envstr
, name
, namelen
);
23 envstr
[namelen
] = '=';
24 memcpy(envstr
+ namelen
+ 1, value
, valuelen
);
25 envstr
[namelen
+ valuelen
+ 1] = 0;
28 /* putenv(3) makes the argument string part of the environment,
29 * and changing that string modifies the environment --- which
30 * means we do not own that storage anymore. Do not free