/* * Copyright 2001-2003, Meiosys (www.meiosys.com). All rights reserved. * * See the COPYING file for the terms of usage and distribution. */ #include #include #include #include #include #include "sd/sprintf.h" #include "sd/malloc.h" #include "sd/sd_xplatform.h" static const TCHAR version[] = _T("$Id$"); /******************************************************************************/ extern TCHAR* sd_sprintf(const TCHAR* a_fmt, ...) { TCHAR* buffer; va_list args; va_start(args, a_fmt); buffer = sd_vsprintf(a_fmt, args); va_end(args); return buffer; } /******************************************************************************/ extern TCHAR* sd_vsprintf(const TCHAR* a_fmt, va_list a_args) { int size = 10240; TCHAR* buffer = (TCHAR*)sd_calloc(size, sizeof(TCHAR)); while (1) { int n = _vsntprintf_s(buffer, size, size, a_fmt, a_args); /* If that worked, return */ if (n > -1 && n < size) { return buffer; } /* Else try again with more space. */ if (n > -1) /* ISO/IEC 9899:1999 */ size = n + 1; else /* twice the old size */ size *= 2; buffer = (TCHAR*)sd_realloc(buffer, size); } return buffer; } #if defined(__osf__) # ifndef snprintf # include "sprintf.osf.c" # endif #endif