Skip to content

Commit 731043f

Browse files
Jason RiedyJunio C Hamano
authored andcommitted
Add compat/unsetenv.c .
Implement a (slow) unsetenv() for older systems. Signed-off-by: Jason Riedy <ejr@cs.berkeley.edu> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 5ea06e2 commit 731043f

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ ifeq ($(uname_S),SunOS)
232232
SHELL_PATH = /bin/bash
233233
NO_STRCASESTR = YesPlease
234234
ifeq ($(uname_R),5.8)
235+
NO_UNSETENV = YesPlease
235236
NO_SETENV = YesPlease
236237
endif
237238
INSTALL = ginstall
@@ -355,6 +356,10 @@ ifdef NO_SETENV
355356
COMPAT_CFLAGS += -DNO_SETENV
356357
COMPAT_OBJS += compat/setenv.o
357358
endif
359+
ifdef NO_SETENV
360+
COMPAT_CFLAGS += -DNO_UNSETENV
361+
COMPAT_OBJS += compat/unsetenv.o
362+
endif
358363
ifdef NO_MMAP
359364
COMPAT_CFLAGS += -DNO_MMAP
360365
COMPAT_OBJS += compat/mmap.o

compat/unsetenv.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdlib.h>
2+
#include <string.h>
3+
4+
void gitunsetenv (const char *name)
5+
{
6+
extern char **environ;
7+
int src, dst;
8+
size_t nmln;
9+
10+
nmln = strlen(name);
11+
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;
21+
}
22+
environ[dst] = environ[src];
23+
++dst;
24+
}
25+
environ[dst] = NULL;
26+
}

connect.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "git-compat-util.h"
12
#include "cache.h"
23
#include "pkt-line.h"
34
#include "quote.h"

git-compat-util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ extern int gitfakemunmap(void *start, size_t length);
6363
extern int gitsetenv(const char *, const char *, int);
6464
#endif
6565

66+
#ifdef NO_UNSETENV
67+
#define unsetenv gitunsetenv
68+
extern void gitunsetenv(const char *);
69+
#endif
70+
6671
#ifdef NO_STRCASESTR
6772
#define strcasestr gitstrcasestr
6873
extern char *gitstrcasestr(const char *haystack, const char *needle);

0 commit comments

Comments
 (0)