Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VC++ 2010 and earlier don't define snprintf #58

Closed
utelle opened this issue Jul 4, 2016 · 2 comments
Closed

VC++ 2010 and earlier don't define snprintf #58

utelle opened this issue Jul 4, 2016 · 2 comments

Comments

@utelle
Copy link

utelle commented Jul 4, 2016

Unfortunately MSVC++ 2010 and earlier don't define the function snprintf ... and what's worse, the function _snprintf provided by MSVC++ 2010 can't be used as a replacement, since it behaves differently than snprintf. One way to solve the problem is to define a function with the proper behaviour in the header file common.h of libxlsxwriter. After line 235 add the following code:

/* VC++ 2010 doesn't define snprintf */
#if defined(_MSC_VER) && _MSC_VER < 1900

#define snprintf c99_snprintf
#define vsnprintf c99_vsnprintf

#include <stdarg.h>

__inline int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap)
{
    int count = -1;

    if (size != 0)
        count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
    if (count == -1)
        count = _vscprintf(format, ap);

    return count;
}

__inline int c99_snprintf(char *outBuf, size_t size, const char *format, ...)
{
    int count;
    va_list ap;

    va_start(ap, format);
    count = c99_vsnprintf(outBuf, size, format, ap);
    va_end(ap);

    return count;
}

#endif 

This makes libxlsxwriter operational with MSVC++ 2010 and earlier.

@jmcnamara
Copy link
Owner

Added to master.

@jmcnamara
Copy link
Owner

Fixed in release 0.4.0. Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants