From bb526954f24b2be5c574810a72395461cadd2d0c Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 4 Dec 2021 21:12:06 +0100 Subject: Fix: unit test and sample program Windows build Now that there is a wrapper for main() on Windows, all executable programs must use a common, cannonical signature for main(). Furthermore, the Windows version of the epoch test needs wrappers for setenv/unsetenv. Signed-off-by: David Oberhollenzer --- tests/libfstree/Makemodule.am | 1 + tests/libfstree/epoch.c | 21 ++++++++++++++++++++- tests/libfstree/sort_file.c | 3 ++- 3 files changed, 23 insertions(+), 2 deletions(-) (limited to 'tests/libfstree') diff --git a/tests/libfstree/Makemodule.am b/tests/libfstree/Makemodule.am index c7ecdd5..594ef7e 100644 --- a/tests/libfstree/Makemodule.am +++ b/tests/libfstree/Makemodule.am @@ -60,6 +60,7 @@ test_filename_sane_w32_LDADD = libcompat.a test_fstree_epoch_SOURCES = tests/libfstree/epoch.c test_fstree_epoch_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/lib/fstree test_fstree_epoch_SOURCES += lib/fstree/source_date_epoch.c +test_fstree_epoch_LDADD = libcompat.a test_sort_file_SOURCES = tests/libfstree/sort_file.c test_sort_file_LDADD = libfstree.a libfstream.a libcompat.a diff --git a/tests/libfstree/epoch.c b/tests/libfstree/epoch.c index e36cd5b..354a33f 100644 --- a/tests/libfstree/epoch.c +++ b/tests/libfstree/epoch.c @@ -8,9 +8,28 @@ #include "internal.h" #include "../test.h" -int main(void) +#if defined(_WIN32) || defined(__WINDOWS__) +static void setenv(const char *key, const char *value, int overwrite) +{ + char buffer[128]; + (void)overwrite; + + snprintf(buffer, sizeof(buffer) - 1, "%s=%s", key, value); + buffer[sizeof(buffer) - 1] = '\0'; + + _putenv(buffer); +} + +static void unsetenv(const char *key) +{ + setenv(key, "", 0); +} +#endif + +int main(int argc, char **argv) { sqfs_u32 ts; + (void)argc; (void)argv; unsetenv("SOURCE_DATE_EPOCH"); ts = get_source_date_epoch(); diff --git a/tests/libfstree/sort_file.c b/tests/libfstree/sort_file.c index 39e4f23..686ee68 100644 --- a/tests/libfstree/sort_file.c +++ b/tests/libfstree/sort_file.c @@ -147,11 +147,12 @@ static istream_t memstream = { /*****************************************************************************/ -int main(void) +int main(int argc, char **argv) { file_info_t *fi; fstree_t fs; size_t i; + (void)argc; (void)argv; input_file = listing; memstream.buffer_used = 0; -- cgit v1.2.3