sourcepawn/decompiler/platform_util.cpp
author David Anderson <dvander@alliedmods.net>
Tue Sep 23 21:20:40 2008 -0700 (2008-09-23)
changeset 2320 88550c031d23
child 2325 7a24ee5557fb
permissions -rw-r--r--
Initial import/sketch of opcode analyzer (bug 3279).
Uses single static assignment to recover expression trees from straight-line byte code.
     1 #include <stdio.h>
     2 #include "platform_util.h"
     3 
     4 size_t Sp_Format(char *buffer, size_t maxlength, const char *fmt, ...)
     5 {
     6 	size_t len;
     7 
     8 	va_list ap;
     9 	va_start(ap, fmt);
    10 	len = Sp_FormatArgs(buffer, maxlength, fmt, ap);
    11 	va_end(ap);
    12 
    13 	return len;
    14 }
    15 
    16 size_t Sp_FormatArgs(char *buffer, size_t maxlength, const char *fmt, va_list ap)
    17 {
    18 	size_t len;
    19 
    20 	len = vsnprintf(buffer, maxlength, fmt, ap);
    21 
    22 	if (len >= maxlength)
    23 	{
    24 		buffer[maxlength - 1] = '\0';
    25 		return (maxlength - 1);
    26 	}
    27 	else
    28 	{
    29 		return len;
    30 	}
    31 }
    32