fixed amb800 - FormatTime() being microsofty

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401339
This commit is contained in:
David Anderson 2007-08-15 16:17:54 +00:00
parent fd9ffeaf79
commit 54a8126648

View File

@ -31,6 +31,7 @@
#include <time.h> #include <time.h>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "sm_stringutil.h" #include "sm_stringutil.h"
#include "sm_globals.h" #include "sm_globals.h"
#include "sourcemod.h" #include "sourcemod.h"
@ -100,14 +101,43 @@ static cell_t GetTime(IPluginContext *pContext, const cell_t *params)
return static_cast<cell_t>(t); return static_cast<cell_t>(t);
} }
#if defined SUBPLATFORM_SECURECRT
void _ignore_invalid_parameter(
const wchar_t * expression,
const wchar_t * function,
const wchar_t * file,
unsigned int line,
uintptr_t pReserved
)
{
/* Wow we don't care, thanks Microsoft. */
}
#endif
#include "sm_srvcmds.h"
static cell_t FormatTime(IPluginContext *pContext, const cell_t *params) static cell_t FormatTime(IPluginContext *pContext, const cell_t *params)
{ {
char *format, *buffer; char *format, *buffer;
pContext->LocalToString(params[1], &buffer); pContext->LocalToString(params[1], &buffer);
pContext->LocalToString(params[3], &format); pContext->LocalToString(params[3], &format);
#if defined SUBPLATFORM_SECURECRT
_invalid_parameter_handler handler = _set_invalid_parameter_handler(_ignore_invalid_parameter);
#endif
time_t t = (params[4] == -1) ? time(NULL) : (time_t)params[4]; time_t t = (params[4] == -1) ? time(NULL) : (time_t)params[4];
strftime(buffer, params[2], format, localtime(&t)); size_t written = strftime(buffer, params[2], format, localtime(&t));
#if defined SUBPLATFORM_SECURECRT
_set_invalid_parameter_handler(handler);
#endif
if (params[2] && format[0] != '\0' && !written)
{
pContext->ThrowNativeError("Invalid time format or buffer too small");
return 0;
}
return 1; return 1;
} }