From 608640b87dc47233940664632e3ab8f13972be2b Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Thu, 17 Oct 2019 19:11:52 +0100 Subject: Fix Win32 build since c4ed2e06 "Add some unit testing utilities" Provide Win32 replacements for realpath() and err.h --- configure.ac | 5 ++++- src/util/realpath.c | 29 +++++++++++++++++++++++++++++ src/util/replace.h | 16 ++++++++++++++++ test/utils/font-test-utils.c | 3 +++ test/utils/lsfontdir.c | 3 +++ 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/util/realpath.c diff --git a/configure.ac b/configure.ac index f507c28..e497325 100644 --- a/configure.ac +++ b/configure.ac @@ -54,7 +54,10 @@ AC_CHECK_HEADERS([endian.h poll.h sys/poll.h]) AC_CHECK_FUNCS([poll readlink]) AC_SEARCH_LIBS([strlcat], [bsd]) AC_CONFIG_LIBOBJ_DIR([src/util]) -AC_REPLACE_FUNCS([reallocarray strlcat strlcpy]) +AC_REPLACE_FUNCS([reallocarray realpath strlcat strlcpy]) + +# Check for BSDish err.h +AC_CHECK_HEADERS([err.h]) # If the first PKG_CHECK_MODULES appears inside a conditional, pkg-config # must first be located explicitly. diff --git a/src/util/realpath.c b/src/util/realpath.c new file mode 100644 index 0000000..abeebaa --- /dev/null +++ b/src/util/realpath.c @@ -0,0 +1,29 @@ +/* + * Copyright © 2019 Jon Turney. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE + * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "src/util/replace.h" + +#ifdef WIN32 +char * +realpath(const char *path, char *resolved_path) +{ + return _fullpath(resolved_path, path, _MAX_PATH); +} +#endif diff --git a/src/util/replace.h b/src/util/replace.h index 1a24820..53a81a2 100644 --- a/src/util/replace.h +++ b/src/util/replace.h @@ -57,5 +57,21 @@ extern _X_HIDDEN size_t strlcat(char *dst, const char *src, size_t siz); #endif +#ifndef HAVE_ERR_H +#define err(eval, ...) do { \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); \ + exit(eval); \ + } while (0) +#define vwarn(...) do { \ + fprintf(stderr, __VA_ARGS__); \ + fprintf(stderr, "\n"); \ + } while (0) +#endif + +#ifndef HAVE_REALPATH +extern _X_HIDDEN char * +realpath(const char *path, char *resolved_path); +#endif #endif /* XFONT_REPLACE_H */ diff --git a/test/utils/font-test-utils.c b/test/utils/font-test-utils.c index ff05061..da32e08 100644 --- a/test/utils/font-test-utils.c +++ b/test/utils/font-test-utils.c @@ -58,7 +58,10 @@ SOFTWARE. #include #include #include +#ifdef HAVE_ERR_H #include +#endif +#include "src/util/replace.h" #include static unsigned long server_generation; diff --git a/test/utils/lsfontdir.c b/test/utils/lsfontdir.c index 1f46599..23826cf 100644 --- a/test/utils/lsfontdir.c +++ b/test/utils/lsfontdir.c @@ -30,7 +30,10 @@ #include "font-test-utils.h" #include #include +#ifdef HAVE_ERR_H #include +#endif +#include "src/util/replace.h" int main(int argc, char **argv) -- cgit v1.2.3