From 47ce9765a817a07dc8169a4deafab6567ac59cca Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 8 Sep 2017 18:44:28 -0500 Subject: [PATCH] libpkgconf: define SIZE_FMT_SPECIFIER on POSIX and Windows platforms and use it in place of %zu The MSVCRT runtime as used on Windows does not support %zu, but instead recommends %Iu. As we want to remain portable to other runtimes, even on Windows, we do not use %Iu, but instead expand it logically to either %lu or %llu depending on if it's _WIN32 or _WIN64 headers. On POSIX, we assume C99 support is available and always use %zu, as pkgconf has never supported anything earlier than C99 officially. Closes #125. --- libpkgconf/client.c | 2 +- libpkgconf/pkg.c | 6 +++--- libpkgconf/stdinc.h | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libpkgconf/client.c b/libpkgconf/client.c index 1203ffe..fc67459 100644 --- a/libpkgconf/client.c +++ b/libpkgconf/client.c @@ -319,7 +319,7 @@ pkgconf_trace(const pkgconf_client_t *client, const char *filename, size_t linen size_t len; va_list va; - len = snprintf(errbuf, sizeof errbuf, "%s:%zu [%s]: ", filename, lineno, funcname); + len = snprintf(errbuf, sizeof errbuf, "%s:" SIZE_FMT_SPECIFIER " [%s]: ", filename, lineno, funcname); va_start(va, format); vsnprintf(errbuf + len, sizeof(errbuf) - len, format, va); diff --git a/libpkgconf/pkg.c b/libpkgconf/pkg.c index 27bc3c7..809c7f5 100644 --- a/libpkgconf/pkg.c +++ b/libpkgconf/pkg.c @@ -299,7 +299,7 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE * lineno++; - PKGCONF_TRACE(client, "%s:%zu > [%s]", filename, lineno, readbuf); + PKGCONF_TRACE(client, "%s:" SIZE_FMT_SPECIFIER " > [%s]", filename, lineno, readbuf); p = readbuf; while (*p && (isalpha((unsigned int)*p) || isdigit((unsigned int)*p) || *p == '_' || *p == '.')) @@ -313,7 +313,7 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE * { if (!warned_key_whitespace) { - pkgconf_warn(client, "%s:%zu: warning: whitespace encountered while parsing key section\n", + pkgconf_warn(client, "%s:" SIZE_FMT_SPECIFIER ": warning: whitespace encountered while parsing key section\n", pkg->filename, lineno); warned_key_whitespace = true; } @@ -336,7 +336,7 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE * { if (!warned_value_whitespace && op == '=') { - pkgconf_warn(client, "%s:%zu: warning: trailing whitespace encountered while parsing value section\n", + pkgconf_warn(client, "%s:" SIZE_FMT_SPECIFIER ": warning: trailing whitespace encountered while parsing value section\n", pkg->filename, lineno); warned_value_whitespace = true; } diff --git a/libpkgconf/stdinc.h b/libpkgconf/stdinc.h index d8efcf5..9809b60 100644 --- a/libpkgconf/stdinc.h +++ b/libpkgconf/stdinc.h @@ -32,6 +32,11 @@ # include # include # define PATH_DEV_NULL "nul" +# ifdef _WIN64 +# define SIZE_FMT_SPECIFIER "%llu" +# else +# define SIZE_FMT_SPECIFIER "%lu" +# endif # ifndef ssize_t # ifndef __MINGW32__ # include @@ -47,6 +52,7 @@ # endif #else # define PATH_DEV_NULL "/dev/null" +# define SIZE_FMT_SPECIFIER "%zu" # include # include #endif