Merge branch 'development' of github.com:libgit2/libgit2 into development
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
diff --git a/src/unix/posix.h b/src/unix/posix.h
index 5c74f07..881e651 100644
--- a/src/unix/posix.h
+++ b/src/unix/posix.h
@@ -20,5 +20,6 @@
#define p_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a)
#define p_snprintf(b, c, f, ...) snprintf(b, c, f, __VA_ARGS__)
#define p_mkstemp(p) mkstemp(p)
+#define p_setenv(n,v,o) setenv(n,v,o)
#endif
diff --git a/src/win32/posix.c b/src/win32/posix.c
index 38e505e..8038fde 100644
--- a/src/win32/posix.c
+++ b/src/win32/posix.c
@@ -252,3 +252,11 @@ int p_mkstemp(char *tmp_path)
return p_creat(tmp_path, 0744);
}
+
+int p_setenv(const char* name, const char* value, int overwrite)
+{
+ if (overwrite != 1)
+ return EINVAL;
+
+ return (SetEnvironmentVariableA(name, value) == 0 ? GIT_EOSERR : GIT_SUCCESS);
+}
diff --git a/src/win32/posix.h b/src/win32/posix.h
index db4ec19..58fd050 100644
--- a/src/win32/posix.h
+++ b/src/win32/posix.h
@@ -32,5 +32,6 @@ extern char *p_realpath(const char *orig_path, char *buffer);
extern int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr);
extern int p_snprintf(char *buffer, size_t count, const char *format, ...) GIT_FORMAT_PRINTF(3, 4);
extern int p_mkstemp(char *tmp_path);
+extern int p_setenv(const char* name, const char* value, int overwrite);
#endif
diff --git a/tests/t15-config.c b/tests/t15-config.c
index fdfa092..d912abb 100644
--- a/tests/t15-config.c
+++ b/tests/t15-config.c
@@ -26,6 +26,7 @@
#include "test_helpers.h"
#include <git2.h>
+#include <posix.h>
#include "filebuf.h"
#define CONFIG_BASE TEST_RESOURCES "/config"
@@ -217,7 +218,7 @@ BEGIN_TEST(config10, "a repo's config overrides the global config")
char *old_home;
old_home = git__strdup(getenv("HOME"));
- setenv("HOME", CONFIG_BASE, 1);
+ p_setenv("HOME", CONFIG_BASE, 1);
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_config(&cfg, repo, NULL));
@@ -226,7 +227,7 @@ BEGIN_TEST(config10, "a repo's config overrides the global config")
git_config_free(cfg);
git_repository_free(repo);
- setenv("HOME", old_home, 1);
+ p_setenv("HOME", old_home, 1);
free(old_home);
END_TEST
@@ -237,7 +238,7 @@ BEGIN_TEST(config11, "fall back to the global config")
char *old_home;
old_home = git__strdup(getenv("HOME"));
- setenv("HOME", CONFIG_BASE, 1);
+ p_setenv("HOME", CONFIG_BASE, 1);
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_config(&cfg, repo, NULL));
@@ -246,7 +247,7 @@ BEGIN_TEST(config11, "fall back to the global config")
git_config_free(cfg);
git_repository_free(repo);
- setenv("HOME", old_home, 1);
+ p_setenv("HOME", old_home, 1);
free(old_home);
END_TEST
diff --git a/tests/t16-remotes.c b/tests/t16-remotes.c
index 6529f0e..af54f29 100644
--- a/tests/t16-remotes.c
+++ b/tests/t16-remotes.c
@@ -26,6 +26,7 @@
#include "test_helpers.h"
#include <git2.h>
+#include <posix.h>
BEGIN_TEST(remotes0, "remote parsing works")
git_remote *remote;
@@ -34,7 +35,7 @@ BEGIN_TEST(remotes0, "remote parsing works")
char *old_home;
old_home = git__strdup(getenv("HOME"));
- setenv("HOME", "/dev/null", 1);
+ p_setenv("HOME", "/dev/null", 1);
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_config(&cfg, repo, NULL));
@@ -46,7 +47,7 @@ BEGIN_TEST(remotes0, "remote parsing works")
git_config_free(cfg);
git_repository_free(repo);
- setenv("HOME", old_home, 1);
+ p_setenv("HOME", old_home, 1);
free(old_home);
END_TEST
@@ -58,7 +59,7 @@ BEGIN_TEST(refspec0, "remote with refspec works")
char *old_home;
old_home = git__strdup(getenv("HOME"));
- setenv("HOME", "/dev/null", 1);
+ p_setenv("HOME", "/dev/null", 1);
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_config(&cfg, repo, NULL));
@@ -71,7 +72,7 @@ BEGIN_TEST(refspec0, "remote with refspec works")
git_config_free(cfg);
git_repository_free(repo);
- setenv("HOME", old_home, 1);
+ p_setenv("HOME", old_home, 1);
free(old_home);
END_TEST
@@ -83,7 +84,7 @@ BEGIN_TEST(refspec1, "remote fnmatch works as expected")
char *old_home;
old_home = git__strdup(getenv("HOME"));
- setenv("HOME", "/dev/null", 1);
+ p_setenv("HOME", "/dev/null", 1);
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_config(&cfg, repo, NULL));
@@ -96,7 +97,7 @@ BEGIN_TEST(refspec1, "remote fnmatch works as expected")
git_config_free(cfg);
git_repository_free(repo);
- setenv("HOME", old_home, 1);
+ p_setenv("HOME", old_home, 1);
free(old_home);
END_TEST
@@ -109,7 +110,7 @@ BEGIN_TEST(refspec2, "refspec transform")
char *old_home;
old_home = git__strdup(getenv("HOME"));
- setenv("HOME", "/dev/null", 1);
+ p_setenv("HOME", "/dev/null", 1);
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_config(&cfg, repo, NULL));
@@ -122,7 +123,7 @@ BEGIN_TEST(refspec2, "refspec transform")
git_config_free(cfg);
git_repository_free(repo);
- setenv("HOME", old_home, 1);
+ p_setenv("HOME", old_home, 1);
free(old_home);
END_TEST