Merge branch 'xw/am-empty'
[git/debian.git] / compat / unsetenv.c
blobb9d34af6136746358f496cb407fe195965388ba4
1 #include "../git-compat-util.h"
3 int gitunsetenv(const char *name)
5 #if !defined(__MINGW32__)
6 extern char **environ;
7 #endif
8 int src, dst;
9 size_t nmln;
11 nmln = strlen(name);
13 for (src = dst = 0; environ[src]; ++src) {
14 size_t enln;
15 enln = strlen(environ[src]);
16 if (enln > nmln) {
17 /* might match, and can test for '=' safely */
18 if (0 == strncmp (environ[src], name, nmln)
19 && '=' == environ[src][nmln])
20 /* matches, so skip */
21 continue;
23 environ[dst] = environ[src];
24 ++dst;
26 environ[dst] = NULL;
28 return 0;