Fix Clay compilation under Win32
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
diff --git a/tests-clay/clay_main.c b/tests-clay/clay_main.c
index 4296956..90c33bd 100644
--- a/tests-clay/clay_main.c
+++ b/tests-clay/clay_main.c
@@ -23,19 +23,25 @@
#ifdef _WIN32
# include <windows.h>
# include <io.h>
-# include <Shellapi.h>
+# include <shellapi.h>
+# include <direct.h>
# pragma comment(lib, "shell32")
+# define _CC __cdecl
+
# define stat(path, st) _stat(path, st)
# define mkdir(path, mode) _mkdir(path)
+# define chdir(path) _chdir(path)
# define access(path, mode) _access(path, mode)
-# define mktemp(path) _mktemp(path)
+# define strdup(str) _strdup(str)
+# define strncpy(to, from, to_size) strncpy_s(to, to_size, from, _TRUNCATE)
# define W_OK 02
-# define S_ISDIR(x) (x & _S_IFDIR) != 0
+# define S_ISDIR(x) ((x & _S_IFDIR) != 0)
typedef struct _stat STAT_T;
#else
# include <unistd.h>
+# define _CC
typedef struct stat STAT_T;
#endif
@@ -373,12 +379,11 @@ find_tmp_path(char *buffer, size_t length)
"TMPDIR", "TMP", "TEMP", "USERPROFILE"
};
- size_t i;
-
#ifdef _WIN32
if (GetTempPath((DWORD)length, buffer))
return 0;
-#endif
+#else
+ size_t i;
for (i = 0; i < var_count; ++i) {
const char *env = getenv(env_vars[i]);
@@ -396,6 +401,7 @@ find_tmp_path(char *buffer, size_t length)
strncpy(buffer, "/tmp", length);
return 0;
}
+#endif
/* This system doesn't like us, try to use the current directory */
if (is_valid_tmp_path(".")) {
@@ -442,10 +448,15 @@ static int build_sandbox_path(void)
_clay_path[len++] = '/';
}
- strcpy(_clay_path + len, path_tail);
+ strncpy(_clay_path + len, path_tail, sizeof(_clay_path) - len);
+#ifdef _WIN32
+ if (_mktemp_s(_clay_path, sizeof(_clay_path)) != 0)
+ return -1;
+#else
if (mktemp(_clay_path) == NULL)
return -1;
+#endif
return 0;
}
@@ -673,9 +684,9 @@ extern void test_core_string__1(void);
extern void test_core_vector__0(void);
extern void test_core_vector__1(void);
extern void test_core_vector__2(void);
-extern void test_status_single__hash_single_file();
+extern void test_status_single__hash_single_file(void);
extern void test_status_worktree__initialize(void);
-extern void test_status_worktree__cleanup();
+extern void test_status_worktree__cleanup(void);
extern void test_status_worktree__whole_repository(void);
extern void test_status_worktree__empty_repository(void);
@@ -758,7 +769,7 @@ static const struct clay_suite _all_suites[] = {
static const char _suites_str[] = "core::dirent, core::filebuf, core::path, core::rmdir, core::string, core::vector, status::single, status::worktree";
-int main(int argc, char *argv[])
+int _CC main(int argc, char *argv[])
{
return clay_test(
argc, argv, _suites_str,
diff --git a/tests-clay/status/single.c b/tests-clay/status/single.c
index 7800eef..ea1c77f 100644
--- a/tests-clay/status/single.c
+++ b/tests-clay/status/single.c
@@ -17,7 +17,7 @@ file_create(const char *filename, const char *content)
}
/* test retrieving OID from a file apart from the ODB */
-void test_status_single__hash_single_file()
+void test_status_single__hash_single_file(void)
{
static const char file_name[] = "new_file";
static const char file_contents[] = "new_file\n";
diff --git a/tests-clay/status/worktree.c b/tests-clay/status/worktree.c
index c42c607..f8fc3d2 100644
--- a/tests-clay/status/worktree.c
+++ b/tests-clay/status/worktree.c
@@ -86,7 +86,7 @@ void test_status_worktree__initialize(void)
* This will be called once after each test finishes, even
* if the test failed
*/
-void test_status_worktree__cleanup()
+void test_status_worktree__cleanup(void)
{
git_repository_free(_repository);
_repository = NULL;