Merge branch 'master' into next
[git/trast.git] / compat / unsetenv.c
blob3a5e4ec04ae4a523823e633031b85559bf5dc973
1 #include <stdlib.h>
2 #include <string.h>
4 void gitunsetenv (const char *name)
6 extern char **environ;
7 int src, dst;
8 size_t nmln;
10 nmln = strlen(name);
12 for (src = dst = 0; environ[src]; ++src) {
13 size_t enln;
14 enln = strlen(environ[src]);
15 if (enln > nmln) {
16 /* might match, and can test for '=' safely */
17 if (0 == strncmp (environ[src], name, nmln)
18 && '=' == environ[src][nmln])
19 /* matches, so skip */
20 continue;
22 environ[dst] = environ[src];
23 ++dst;
25 environ[dst] = NULL;