added q_snprintf and q_vsnprintf from uhexen2. always use our wrapper

versions to ensure consistent behavior accross platforms.


git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@319 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Ozkan Sezer 2010-08-31 14:09:00 +00:00
parent 54dcec831b
commit 20c394edea
2 changed files with 41 additions and 8 deletions

View file

@ -149,6 +149,33 @@ void InsertLinkAfter (link_t *l, link_t *after)
============================================================================
*/
int q_vsnprintf(char *str, size_t size, const char *format, va_list args)
{
int ret;
ret = vsnprintf_func (str, size, format, args);
if (ret < 0)
ret = (int)size;
if ((size_t)ret >= size)
str[size - 1] = '\0';
return ret;
}
int q_snprintf (char *str, size_t size, const char *format, ...)
{
int ret;
va_list argptr;
va_start (argptr, format);
ret = q_vsnprintf (str, size, format, argptr);
va_end (argptr);
return ret;
}
void Q_memset (void *dest, int fill, size_t count)
{
size_t i;

View file

@ -25,8 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// comndef.h -- general definitions
#if defined(_WIN32)
#define q_snprintf _snprintf
#define q_vsnprintf _vsnprintf
#ifdef _MSC_VER
# pragma warning(disable:4244)
/* 'argument' : conversion from 'type1' to 'type2',
@ -41,12 +39,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define fmax max
#define fmin min
#endif /* _MSC_VER */
#else /* _WIN32 */
#define q_snprintf snprintf
#define q_vsnprintf vsnprintf
#endif /* _WIN32 */
typedef struct sizebuf_s
@ -138,6 +130,20 @@ int Q_strncasecmp (const char *s1, const char *s2, int n);
int Q_atoi (const char *str);
float Q_atof (const char *str);
/* snprintf, vsnprintf : always use our versions. */
/* platform dependant (v)snprintf function names: */
#if defined(_WIN32)
#define snprintf_func _snprintf
#define vsnprintf_func _vsnprintf
#else
#define snprintf_func snprintf
#define vsnprintf_func vsnprintf
#endif
extern int q_snprintf (char *str, size_t size, const char *format, ...) __attribute__((__format__(__printf__,3,4)));
extern int q_vsnprintf(char *str, size_t size, const char *format, va_list args)
__attribute__((__format__(__printf__,3,0)));
//============================================================================
extern char com_token[1024];