mirror of
https://github.com/ioquake/jedi-academy.git
synced 2024-11-24 21:21:33 +00:00
Q_vsnprintf from ioquake3
This commit is contained in:
parent
832b4342a8
commit
5ae4da05a7
2 changed files with 41 additions and 0 deletions
|
@ -850,6 +850,39 @@ char* Q_strrchr( const char* string, int c )
|
|||
return sp;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/*
|
||||
=============
|
||||
Q_vsnprintf
|
||||
|
||||
Special wrapper function for Microsoft's broken _vsnprintf() function.
|
||||
MinGW comes with its own snprintf() which is not broken.
|
||||
=============
|
||||
*/
|
||||
|
||||
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
|
||||
{
|
||||
int retval;
|
||||
|
||||
retval = _vsnprintf(str, size, format, ap);
|
||||
|
||||
if(retval < 0 || retval == size)
|
||||
{
|
||||
// Microsoft doesn't adhere to the C99 standard of vsnprintf,
|
||||
// which states that the return value must be the number of
|
||||
// bytes written if the output string had sufficient length.
|
||||
//
|
||||
// Obviously we cannot determine that value from Microsoft's
|
||||
// implementation, so we have no choice but to return size.
|
||||
|
||||
str[size - 1] = '\0';
|
||||
return size;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
=============
|
||||
Q_strncpyz
|
||||
|
|
|
@ -88,6 +88,14 @@ extern int g_G2AllocServer;
|
|||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// vsnprintf is ISO/IEC 9899:1999
|
||||
// abstracting this to make it portable
|
||||
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap);
|
||||
#else
|
||||
#define Q_vsnprintf vsnprintf
|
||||
#endif
|
||||
|
||||
// Special min treatment for Xbox C++ version
|
||||
|
||||
#ifdef _XBOX
|
||||
|
|
Loading…
Reference in a new issue