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.
feature/tap-sh
William Pitcock 2017-09-08 18:44:28 -05:00
parent a6d6b88d14
commit 47ce9765a8
3 changed files with 10 additions and 4 deletions

View File

@ -319,7 +319,7 @@ pkgconf_trace(const pkgconf_client_t *client, const char *filename, size_t linen
size_t len; size_t len;
va_list va; 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); va_start(va, format);
vsnprintf(errbuf + len, sizeof(errbuf) - len, format, va); vsnprintf(errbuf + len, sizeof(errbuf) - len, format, va);

View File

@ -299,7 +299,7 @@ pkgconf_pkg_new_from_file(pkgconf_client_t *client, const char *filename, FILE *
lineno++; lineno++;
PKGCONF_TRACE(client, "%s:%zu > [%s]", filename, lineno, readbuf); PKGCONF_TRACE(client, "%s:" SIZE_FMT_SPECIFIER " > [%s]", filename, lineno, readbuf);
p = readbuf; p = readbuf;
while (*p && (isalpha((unsigned int)*p) || isdigit((unsigned int)*p) || *p == '_' || *p == '.')) 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) 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); pkg->filename, lineno);
warned_key_whitespace = true; 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 == '=') 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); pkg->filename, lineno);
warned_value_whitespace = true; warned_value_whitespace = true;
} }

View File

@ -32,6 +32,11 @@
# include <windows.h> # include <windows.h>
# include <malloc.h> # include <malloc.h>
# define PATH_DEV_NULL "nul" # define PATH_DEV_NULL "nul"
# ifdef _WIN64
# define SIZE_FMT_SPECIFIER "%llu"
# else
# define SIZE_FMT_SPECIFIER "%lu"
# endif
# ifndef ssize_t # ifndef ssize_t
# ifndef __MINGW32__ # ifndef __MINGW32__
# include <BaseTsd.h> # include <BaseTsd.h>
@ -47,6 +52,7 @@
# endif # endif
#else #else
# define PATH_DEV_NULL "/dev/null" # define PATH_DEV_NULL "/dev/null"
# define SIZE_FMT_SPECIFIER "%zu"
# include <dirent.h> # include <dirent.h>
# include <unistd.h> # include <unistd.h>
#endif #endif