Create cross-platform setenv
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
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