This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
MyGameFramework/lib/portable-crt/include/crt/snprintf.h
Gered c5cdddbeaa initial commit
current versions of all of my basic framework sources, build configurations/scripts, and supporting assets
2013-01-31 12:53:05 -05:00

46 lines
1.1 KiB
C

#ifndef PORTABLE_CRT_SNPRINTF_H_INCLUDED__
#define PORTABLE_CRT_SNPRINTF_H_INCLUDED__
#include <stdio.h>
#include <stdarg.h>
#if defined(_MSC_VER) && defined(_WIN32) && !defined(snprintf)
int c99_snprintf(char* str, size_t size, const char* format, ...);
int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap);
// these functions shamelessly copied from:
// http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
// they serve to mimic C99 standard snprintf functionality (like the return
// value) on MSVC (which does it's own non-standard thing)
#define snprintf c99_snprintf
inline int c99_snprintf(char* str, size_t size, const char* format, ...)
{
int count;
va_list ap;
va_start(ap, format);
count = c99_vsnprintf(str, size, format, ap);
va_end(ap);
return count;
}
inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap)
{
int count = -1;
if (size != 0)
count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
if (count == -1)
count = _vscprintf(format, ap);
return count;
}
#endif
#endif