Skip to content

Commit

Permalink
Use C99 printf statements in mingw
Browse files Browse the repository at this point in the history
Otherwise, format specifiers such as %llu will not work on XP or
earlier.
This bug was introduced with 51ed9ec.
http://sourceforge.net/apps/trac/mingw-w64/wiki/gnu%20printf
  • Loading branch information
laanwj committed Nov 13, 2013
1 parent b3e5797 commit d6f690f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -221,7 +221,7 @@ case $host in
AC_MSG_ERROR("windres not found")
fi

CPPFLAGS="$CPPFLAGS -D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB"
CPPFLAGS="$CPPFLAGS -D_MT -DWIN32 -D_WINDOWS -DBOOST_THREAD_USE_LIB -D__USE_MINGW_ANSI_STDIO"
LEVELDB_TARGET_FLAGS="TARGET_OS=OS_WINDOWS_CROSSCOMPILE"
CXXFLAGS="$CXXFLAGS -w"
;;
Expand Down
4 changes: 0 additions & 4 deletions src/util.cpp
Expand Up @@ -336,11 +336,7 @@ string vstrprintf(const char *format, va_list ap)
{
va_list arg_ptr;
va_copy(arg_ptr, ap);
#ifdef WIN32
ret = _vsnprintf(p, limit, format, arg_ptr);
#else
ret = vsnprintf(p, limit, format, arg_ptr);
#endif
va_end(arg_ptr);
if (ret >= 0 && ret < limit)
break;
Expand Down
29 changes: 8 additions & 21 deletions src/util.h
Expand Up @@ -44,26 +44,13 @@ static const int64_t CENT = 1000000;
#define UEND(a) ((unsigned char*)&((&(a))[1]))
#define ARRAYLEN(array) (sizeof(array)/sizeof((array)[0]))

/* Format characters for (s)size_t and ptrdiff_t */
#if defined(_MSC_VER) || defined(__MSVCRT__)
/* (s)size_t and ptrdiff_t have the same size specifier in MSVC:
http://msdn.microsoft.com/en-us/library/tcxf1dw6%28v=vs.100%29.aspx
*/
#define PRIszx "Ix"
#define PRIszu "Iu"
#define PRIszd "Id"
#define PRIpdx "Ix"
#define PRIpdu "Iu"
#define PRIpdd "Id"
#else /* C99 standard */
#define PRIszx "zx"
#define PRIszu "zu"
#define PRIszd "zd"
#define PRIpdx "tx"
#define PRIpdu "tu"
#define PRIpdd "td"
#endif

/* Format characters for (s)size_t and ptrdiff_t (C99 standard) */
#define PRIszx "zx"
#define PRIszu "zu"
#define PRIszd "zd"
#define PRIpdx "tx"
#define PRIpdu "tu"
#define PRIpdd "td"

// This is needed because the foreach macro can't get over the comma in pair<t1, t2>
#define PAIRTYPE(t1, t2) std::pair<t1, t2>
Expand Down Expand Up @@ -117,7 +104,7 @@ inline void MilliSleep(int64_t n)
* Parameters count from 1.
*/
#ifdef __GNUC__
#define ATTR_WARN_PRINTF(X,Y) __attribute__((format(printf,X,Y)))
#define ATTR_WARN_PRINTF(X,Y) __attribute__((format(gnu_printf,X,Y)))
#else
#define ATTR_WARN_PRINTF(X,Y)
#endif
Expand Down

0 comments on commit d6f690f

Please sign in to comment.