Remove UTIL_Format() and UTIL_VarArgs()

This commit is contained in:
Arkshine 2015-10-01 11:06:04 +02:00
parent f22dc769f4
commit 138b9e1510
39 changed files with 112 additions and 173 deletions

View File

@ -24,7 +24,7 @@ CDirectory::CDirectory(const char *path)
#if defined PLATFORM_WINDOWS #if defined PLATFORM_WINDOWS
char newpath[PLATFORM_MAX_PATH]; char newpath[PLATFORM_MAX_PATH];
UTIL_Format(newpath, sizeof(newpath) - 1, "%s\\*.*", path); ke::SafeSprintf(newpath, sizeof(newpath) - 1, "%s\\*.*", path);
m_dir = FindFirstFile(newpath, &m_fd); m_dir = FindFirstFile(newpath, &m_fd);
@ -40,7 +40,7 @@ CDirectory::CDirectory(const char *path)
if (IsValid()) if (IsValid())
{ {
m_ep = readdir(m_dir); // TODO: we need to read past "." and ".."! m_ep = readdir(m_dir); // TODO: we need to read past "." and ".."!
UTIL_Format(m_origpath, sizeof(m_origpath) - 1, "%s", path); ke::SafeSprintf(m_origpath, sizeof(m_origpath) - 1, "%s", path);
} }
else else
{ {
@ -103,7 +103,7 @@ bool CDirectory::IsEntryDirectory()
#elif defined PLATFORM_POSIX #elif defined PLATFORM_POSIX
char temppath[PLATFORM_MAX_PATH]; char temppath[PLATFORM_MAX_PATH];
UTIL_Format(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName()); ke::SafeSprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName());
return ke::file::IsDirectory(temppath); return ke::file::IsDirectory(temppath);
@ -119,7 +119,7 @@ bool CDirectory::IsEntryFile()
#elif defined PLATFORM_POSIX #elif defined PLATFORM_POSIX
char temppath[PLATFORM_MAX_PATH]; char temppath[PLATFORM_MAX_PATH];
UTIL_Format(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName()); ke::SafeSprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName());
return ke::file::IsDirectory(temppath); return ke::file::IsDirectory(temppath);
@ -318,12 +318,12 @@ size_t LibrarySystem::GetFileFromPath(char* buffer, size_t maxlength, const char
#endif #endif
) )
{ {
return UTIL_Format(buffer, maxlength, "%s", &path[i + 1]); return ke::SafeSprintf(buffer, maxlength, "%s", &path[i + 1]);
} }
} }
/* We scanned and found no path separator */ /* We scanned and found no path separator */
return UTIL_Format(buffer, maxlength, "%s", path); return ke::SafeSprintf(buffer, maxlength, "%s", path);
} }
bool LibrarySystem::FileTime(const char* path, FileTimeType type, time_t* pTime) bool LibrarySystem::FileTime(const char* path, FileTimeType type, time_t* pTime)

View File

@ -67,15 +67,9 @@
#define PLATFORM_MAX_PATH 260 #define PLATFORM_MAX_PATH 260
#if defined PLATFORM_WINDOWS #if defined PLATFORM_WINDOWS
typedef HMODULE LibraryHandle;
typedef HANDLE DirHandle; typedef HANDLE DirHandle;
#elif defined PLATFORM_POSIX #elif defined PLATFORM_POSIX
typedef void* LibraryHandle;
typedef DIR* DirHandle; typedef DIR* DirHandle;
#endif #endif
enum FileTimeType enum FileTimeType

View File

@ -137,7 +137,7 @@ SMCError TextParsers::ParseSMCFile(const char *file,
states->col = 0; states->col = 0;
} }
/*libsys->GetPlatformError(error, sizeof(error));*/ /*libsys->GetPlatformError(error, sizeof(error));*/
UTIL_Format(buffer, maxsize, "File could not be opened: %s", error); ke::SafeSprintf(buffer, maxsize, "File could not be opened: %s", error);
return SMCError_StreamOpen; return SMCError_StreamOpen;
} }
@ -146,7 +146,7 @@ SMCError TextParsers::ParseSMCFile(const char *file,
fclose(fp); fclose(fp);
errstr = GetSMCErrorString(result); errstr = GetSMCErrorString(result);
UTIL_Format(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error"); ke::SafeSprintf(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error");
return result; return result;
} }
@ -197,7 +197,7 @@ SMCError TextParsers::ParseSMCStream(const char *stream,
result = ParseStream_SMC(&rs, RawStreamReader, smc_listener, states); result = ParseStream_SMC(&rs, RawStreamReader, smc_listener, states);
const char *errstr = GetSMCErrorString(result); const char *errstr = GetSMCErrorString(result);
UTIL_Format(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error"); ke::SafeSprintf(buffer, maxsize, "%s", errstr != NULL ? errstr : "Unknown error");
return result; return result;
} }

View File

@ -53,8 +53,8 @@ void CoreConfig::ExecuteMainConfig()
char path[PLATFORM_MAX_PATH]; char path[PLATFORM_MAX_PATH];
char command[PLATFORM_MAX_PATH + sizeof(CommandFormat)]; char command[PLATFORM_MAX_PATH + sizeof(CommandFormat)];
UTIL_Format(path, sizeof(path), "%s/%s/%s", g_mod_name.chars(), get_localinfo("amx_configdir", "addons/amxmodx/configs"), MainConfigFile); ke::SafeSprintf(path, sizeof(path), "%s/%s/%s", g_mod_name.chars(), get_localinfo("amx_configdir", "addons/amxmodx/configs"), MainConfigFile);
UTIL_Format(command, sizeof(command), CommandFormat, path); ke::SafeSprintf(command, sizeof(command), CommandFormat, path);
SERVER_COMMAND(command); SERVER_COMMAND(command);
} }
@ -140,11 +140,11 @@ bool CoreConfig::ExecuteAutoConfig(CPluginMngr::CPlugin *plugin, AutoConfig *con
if (config->folder.length()) if (config->folder.length())
{ {
UTIL_Format(file, sizeof(file), "%s/%s%s/%s/%s.cfg", g_mod_name.chars(), configsDir, AutoConfigDir, config->folder.chars(), config->autocfg.chars()); ke::SafeSprintf(file, sizeof(file), "%s/%s%s/%s/%s.cfg", g_mod_name.chars(), configsDir, AutoConfigDir, config->folder.chars(), config->autocfg.chars());
} }
else else
{ {
UTIL_Format(file, sizeof(file), "%s/%s%s/%s.cfg", g_mod_name.chars(), configsDir, AutoConfigDir, config->autocfg.chars()); ke::SafeSprintf(file, sizeof(file), "%s/%s%s/%s.cfg", g_mod_name.chars(), configsDir, AutoConfigDir, config->autocfg.chars());
} }
bool file_exists = g_LibSys.IsPathFile(file); bool file_exists = g_LibSys.IsPathFile(file);
@ -244,7 +244,7 @@ bool CoreConfig::ExecuteAutoConfig(CPluginMngr::CPlugin *plugin, AutoConfig *con
if (file_exists) if (file_exists)
{ {
char command[PLATFORM_MAX_PATH + sizeof(CommandFormat)]; char command[PLATFORM_MAX_PATH + sizeof(CommandFormat)];
UTIL_Format(command, sizeof(command), CommandFormat, file); ke::SafeSprintf(command, sizeof(command), CommandFormat, file);
SERVER_COMMAND(command); SERVER_COMMAND(command);
} }
@ -266,21 +266,21 @@ void CoreConfig::ExecuteMapConfig()
if ((mapPrefix = strtok(mapName, "_"))) if ((mapPrefix = strtok(mapName, "_")))
{ {
UTIL_Format(cfgPath, sizeof(cfgPath), "%s/%s%s/prefix_%s.cfg", g_mod_name.chars(), configsDir, MapConfigDir, mapPrefix); ke::SafeSprintf(cfgPath, sizeof(cfgPath), "%s/%s%s/prefix_%s.cfg", g_mod_name.chars(), configsDir, MapConfigDir, mapPrefix);
if (g_LibSys.IsPathFile(cfgPath)) if (g_LibSys.IsPathFile(cfgPath))
{ {
UTIL_Format(command, sizeof(command), CommandFormat, cfgPath); ke::SafeSprintf(command, sizeof(command), CommandFormat, cfgPath);
SERVER_COMMAND(command); SERVER_COMMAND(command);
} }
} }
strncopy(mapName, STRING(gpGlobals->mapname), sizeof(mapName)); strncopy(mapName, STRING(gpGlobals->mapname), sizeof(mapName));
UTIL_Format(cfgPath, sizeof(cfgPath), "%s/%s%s/%s.cfg", g_mod_name.chars(), configsDir, MapConfigDir, mapName); ke::SafeSprintf(cfgPath, sizeof(cfgPath), "%s/%s%s/%s.cfg", g_mod_name.chars(), configsDir, MapConfigDir, mapName);
if (g_LibSys.IsPathFile(cfgPath)) if (g_LibSys.IsPathFile(cfgPath))
{ {
UTIL_Format(command, sizeof(command), CommandFormat, cfgPath); ke::SafeSprintf(command, sizeof(command), CommandFormat, cfgPath);
SERVER_COMMAND(command); SERVER_COMMAND(command);
} }

View File

@ -4506,7 +4506,7 @@ static cell AMX_NATIVE_CALL AutoExecConfig(AMX *amx, cell *params)
} }
static char newName[PLATFORM_MAX_PATH]; static char newName[PLATFORM_MAX_PATH];
UTIL_Format(newName, sizeof(newName), "plugin-%s", pluginName); ke::SafeSprintf(newName, sizeof(newName), "plugin-%s", pluginName);
name = newName; name = newName;
} }

View File

@ -139,8 +139,6 @@ template <typename D, typename S> unsigned int strncopy(D *dest, const S *src, s
unsigned int UTIL_GetUTF8CharBytes(const char *stream); unsigned int UTIL_GetUTF8CharBytes(const char *stream);
unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search, const char *replace, bool caseSensitive); unsigned int UTIL_ReplaceAll(char *subject, size_t maxlength, const char *search, const char *replace, bool caseSensitive);
char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t searchLen, const char *replace, size_t replaceLen, bool caseSensitive); char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t searchLen, const char *replace, size_t replaceLen, bool caseSensitive);
char *UTIL_VarArgs(const char *fmt, ...);
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
void UTIL_TrimLeft(char *buffer); void UTIL_TrimLeft(char *buffer);
void UTIL_TrimRight(char *buffer); void UTIL_TrimRight(char *buffer);

View File

@ -81,7 +81,7 @@ void CLog::CreateNewFile()
while (true) while (true)
{ {
UTIL_Format(name, sizeof(name), "%s/L%02d%02d%03d.log", g_log_dir.chars(), curTime->tm_mon + 1, curTime->tm_mday, i); ke::SafeSprintf(name, sizeof(name), "%s/L%02d%02d%03d.log", g_log_dir.chars(), curTime->tm_mon + 1, curTime->tm_mday, i);
build_pathname_r(file, sizeof(file)-1, "%s", name); build_pathname_r(file, sizeof(file)-1, "%s", name);
FILE *pTmpFile = fopen(file, "r"); // open for reading to check whether the file exists FILE *pTmpFile = fopen(file, "r"); // open for reading to check whether the file exists
@ -243,7 +243,7 @@ void CLog::LogError(const char *fmt, ...)
va_end(arglst); va_end(arglst);
FILE *pF = NULL; FILE *pF = NULL;
UTIL_Format(name, sizeof(name), "%s/error_%04d%02d%02d.log", g_log_dir.chars(), curTime->tm_year + 1900, curTime->tm_mon + 1, curTime->tm_mday); ke::SafeSprintf(name, sizeof(name), "%s/error_%04d%02d%02d.log", g_log_dir.chars(), curTime->tm_year + 1900, curTime->tm_mon + 1, curTime->tm_mday);
build_pathname_r(file, sizeof(file)-1, "%s", name); build_pathname_r(file, sizeof(file)-1, "%s", name);
pF = fopen(file, "a+"); pF = fopen(file, "a+");

View File

@ -240,7 +240,7 @@ static cell AMX_NATIVE_CALL set_cvar_float(AMX *amx, cell *params)
if (info) if (info)
{ {
UTIL_Format(CVarTempBuffer, sizeof(CVarTempBuffer) - 1, "%f", amx_ctof(params[2])); ke::SafeSprintf(CVarTempBuffer, sizeof(CVarTempBuffer) - 1, "%f", amx_ctof(params[2]));
CVAR_DIRECTSET(info->var, &CVarTempBuffer[0]); CVAR_DIRECTSET(info->var, &CVarTempBuffer[0]);
} }
@ -258,7 +258,7 @@ static cell AMX_NATIVE_CALL set_cvar_num(AMX *amx, cell *params)
if (info) if (info)
{ {
UTIL_Format(CVarTempBuffer, sizeof(CVarTempBuffer) - 1, "%d", value); ke::SafeSprintf(CVarTempBuffer, sizeof(CVarTempBuffer) - 1, "%d", value);
CVAR_DIRECTSET(info->var, &CVarTempBuffer[0]); CVAR_DIRECTSET(info->var, &CVarTempBuffer[0]);
} }
@ -444,7 +444,7 @@ static cell AMX_NATIVE_CALL set_pcvar_float(AMX *amx, cell *params)
return 0; return 0;
} }
UTIL_Format(CVarTempBuffer, sizeof(CVarTempBuffer) - 1, "%f", amx_ctof(params[2])); ke::SafeSprintf(CVarTempBuffer, sizeof(CVarTempBuffer) - 1, "%f", amx_ctof(params[2]));
CVAR_DIRECTSET(ptr, &CVarTempBuffer[0]); CVAR_DIRECTSET(ptr, &CVarTempBuffer[0]);
return 1; return 1;
@ -460,7 +460,7 @@ static cell AMX_NATIVE_CALL set_pcvar_num(AMX *amx, cell *params)
return 0; return 0;
} }
UTIL_Format(CVarTempBuffer, sizeof(CVarTempBuffer) - 1, "%d", params[2]); ke::SafeSprintf(CVarTempBuffer, sizeof(CVarTempBuffer) - 1, "%d", params[2]);
CVAR_DIRECTSET(ptr, &CVarTempBuffer[0]); CVAR_DIRECTSET(ptr, &CVarTempBuffer[0]);
return 1; return 1;

View File

@ -367,7 +367,7 @@ int Debugger::FormatError(char *buffer, size_t maxLength)
//cell *p_cip = NULL; //cell *p_cip = NULL;
//int amx_err = AMX_ERR_NONE; //int amx_err = AMX_ERR_NONE;
size += UTIL_Format(buffer, maxLength, "Run time error %d: %s ", error, gen_err); size += ke::SafeSprintf(buffer, maxLength, "Run time error %d: %s ", error, gen_err);
buffer += size; buffer += size;
maxLength -= size; maxLength -= size;
@ -390,7 +390,7 @@ int Debugger::FormatError(char *buffer, size_t maxLength)
else else
amx_err = AMX_ERR_NOTFOUND;*/ amx_err = AMX_ERR_NOTFOUND;*/
//if (!amx_err) //if (!amx_err)
size += UTIL_Format(buffer, maxLength, "(native \"%s\")", native_name); size += ke::SafeSprintf(buffer, maxLength, "(native \"%s\")", native_name);
} }
return size; return size;
@ -623,12 +623,12 @@ void Debugger::FmtGenericMsg(AMX *amx, int error, char buffer[], size_t maxLengt
if (error == AMX_ERR_EXIT) if (error == AMX_ERR_EXIT)
{ {
UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") - %s", error, filename, GenericError(AMX_ERR_EXIT)); ke::SafeSprintf(buffer, maxLength, "Run time error %d (plugin \"%s\") - %s", error, filename, GenericError(AMX_ERR_EXIT));
} else if (error == AMX_ERR_NATIVE) { } else if (error == AMX_ERR_NATIVE) {
amx_GetNative(amx, reinterpret_cast<long>(amx->usertags[UT_NATIVE]), native); amx_GetNative(amx, reinterpret_cast<long>(amx->usertags[UT_NATIVE]), native);
UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") (native \"%s\") - debug not enabled!", error, filename, native); ke::SafeSprintf(buffer, maxLength, "Run time error %d (plugin \"%s\") (native \"%s\") - debug not enabled!", error, filename, native);
} else { } else {
UTIL_Format(buffer, maxLength, "Run time error %d (plugin \"%s\") - debug not enabled!", error, filename); ke::SafeSprintf(buffer, maxLength, "Run time error %d (plugin \"%s\") - debug not enabled!", error, filename);
} }
} }

View File

@ -673,7 +673,7 @@ reswitch:
if (!def) if (!def)
{ {
static char buf[255]; static char buf[255];
UTIL_Format(buf, sizeof(buf) - 1, "ML_NOTFOUND: %s", key); ke::SafeSprintf(buf, sizeof(buf) - 1, "ML_NOTFOUND: %s", key);
def = buf; def = buf;
} }
size_t written = atcprintf(buf_p, llen, def, amx, params, &arg); size_t written = atcprintf(buf_p, llen, def, amx, params, &arg);
@ -708,11 +708,11 @@ reswitch:
} }
int userid = GETPLAYERUSERID(player->pEdict); int userid = GETPLAYERUSERID(player->pEdict);
UTIL_Format(buffer, sizeof(buffer), "%s<%d><%s><%s>", player->name.chars(), userid, auth, player->team.chars()); ke::SafeSprintf(buffer, sizeof(buffer), "%s<%d><%s><%s>", player->name.chars(), userid, auth, player->team.chars());
} }
else else
{ {
UTIL_Format(buffer, sizeof(buffer), "Console<0><Console><Console>"); ke::SafeSprintf(buffer, sizeof(buffer), "Console<0><Console><Console>");
} }
AddString(&buf_p, llen, buffer, width, prec); AddString(&buf_p, llen, buffer, width, prec);

View File

@ -97,7 +97,7 @@ size_t AddLibrariesFromString(const char *name, LibType type, LibSource src, voi
char *ptr, *p, s; char *ptr, *p, s;
size_t count = 0; size_t count = 0;
UTIL_Format(buffer, sizeof(buffer)-1, "%s", name); ke::SafeSprintf(buffer, sizeof(buffer)-1, "%s", name);
ptr = buffer; ptr = buffer;
p = buffer; p = buffer;

View File

@ -226,7 +226,7 @@ void LoadExtraPluginsToPCALM(const char *initialdir)
while (!files.empty()) while (!files.empty())
{ {
ke::AString *pString = files.front(); ke::AString *pString = files.front();
UTIL_Format(path, sizeof(path)-1, "%s/%s", ke::SafeSprintf(path, sizeof(path)-1, "%s/%s",
initialdir, initialdir,
pString->chars()); pString->chars());
g_plugins.CALMFromFile(path); g_plugins.CALMFromFile(path);
@ -243,7 +243,7 @@ void LoadExtraPluginsFromDir(const char *initialdir)
while (!files.empty()) while (!files.empty())
{ {
ke::AString *pString = files.front(); ke::AString *pString = files.front();
UTIL_Format(path, sizeof(path)-1, "%s/%s", ke::SafeSprintf(path, sizeof(path)-1, "%s/%s",
initialdir, initialdir,
pString->chars()); pString->chars());
g_plugins.loadPluginsFromFile(path); g_plugins.loadPluginsFromFile(path);
@ -332,7 +332,7 @@ const char* get_localinfo_r(const char *name, const char *def, char buffer[], si
SET_LOCALINFO((char*)name, (char*)(b = def)); SET_LOCALINFO((char*)name, (char*)(b = def));
} }
UTIL_Format(buffer, maxlength, "%s", b); ke::SafeSprintf(buffer, maxlength, "%s", b);
return buffer; return buffer;
} }
@ -425,7 +425,7 @@ int C_Spawn(edict_t *pent)
LoadExtraPluginsToPCALM(configs_dir); LoadExtraPluginsToPCALM(configs_dir);
char temporaryMap[64], *tmap_ptr; char temporaryMap[64], *tmap_ptr;
UTIL_Format(temporaryMap, sizeof(temporaryMap), "%s", STRING(gpGlobals->mapname)); ke::SafeSprintf(temporaryMap, sizeof(temporaryMap), "%s", STRING(gpGlobals->mapname));
prefixed_map_pluginsfile[0] = '\0'; prefixed_map_pluginsfile[0] = '\0';
if ((tmap_ptr = strchr(temporaryMap, '_')) != NULL) if ((tmap_ptr = strchr(temporaryMap, '_')) != NULL)
@ -433,7 +433,7 @@ int C_Spawn(edict_t *pent)
// this map has a prefix // this map has a prefix
*tmap_ptr = '\0'; *tmap_ptr = '\0';
UTIL_Format(prefixed_map_pluginsfile, ke::SafeSprintf(prefixed_map_pluginsfile,
sizeof(prefixed_map_pluginsfile), sizeof(prefixed_map_pluginsfile),
"%s/maps/plugins-%s.ini", "%s/maps/plugins-%s.ini",
configs_dir, configs_dir,
@ -441,7 +441,7 @@ int C_Spawn(edict_t *pent)
g_plugins.CALMFromFile(prefixed_map_pluginsfile); g_plugins.CALMFromFile(prefixed_map_pluginsfile);
} }
UTIL_Format(map_pluginsfile_path, ke::SafeSprintf(map_pluginsfile_path,
sizeof(map_pluginsfile_path), sizeof(map_pluginsfile_path),
"%s/maps/plugins-%s.ini", "%s/maps/plugins-%s.ini",
configs_dir, configs_dir,

View File

@ -670,7 +670,7 @@ char* build_pathname(const char *fmt, ...)
{ {
static char string[256]; static char string[256];
int b; int b;
int a = b = UTIL_Format(string, 255, "%s%c", g_mod_name.chars(), PATH_SEP_CHAR); int a = b = ke::SafeSprintf(string, 255, "%s%c", g_mod_name.chars(), PATH_SEP_CHAR);
va_list argptr; va_list argptr;
va_start(argptr, fmt); va_start(argptr, fmt);
@ -694,7 +694,7 @@ char* build_pathname(const char *fmt, ...)
char *build_pathname_r(char *buffer, size_t maxlen, const char *fmt, ...) char *build_pathname_r(char *buffer, size_t maxlen, const char *fmt, ...)
{ {
UTIL_Format(buffer, maxlen, "%s%c", g_mod_name.chars(), PATH_SEP_CHAR); ke::SafeSprintf(buffer, maxlen, "%s%c", g_mod_name.chars(), PATH_SEP_CHAR);
size_t len = strlen(buffer); size_t len = strlen(buffer);
char *ptr = buffer + len; char *ptr = buffer + len;
@ -817,16 +817,16 @@ bool ConvertModuleName(const char *pathString, char *path)
*ptr = '\0'; *ptr = '\0';
} }
size_t length = UTIL_Format(path, PLATFORM_MAX_PATH, "%s%c%s_amxx", orig_path, PATH_SEP_CHAR, tmpname); size_t length = ke::SafeSprintf(path, PLATFORM_MAX_PATH, "%s%c%s_amxx", orig_path, PATH_SEP_CHAR, tmpname);
#if defined PLATFORM_LINUX #if defined PLATFORM_LINUX
# if defined AMD64 || PAWN_CELL_SIZE == 64 # if defined AMD64 || PAWN_CELL_SIZE == 64
length += strncopy(path + length, "_amd64", PLATFORM_MAX_PATH - length); length += strncopy(path + length, "_amd64", PLATFORM_MAX_PATH - length);
# else # else
length += UTIL_Format(path + length, PLATFORM_MAX_PATH - length, "_i%c86", iDigit); length += ke::SafeSprintf(path + length, PLATFORM_MAX_PATH - length, "_i%c86", iDigit);
# endif # endif
#endif #endif
UTIL_Format(path + length, PLATFORM_MAX_PATH - length, ".%s", PLATFORM_LIB_EXT); ke::SafeSprintf(path + length, PLATFORM_MAX_PATH - length, ".%s", PLATFORM_LIB_EXT);
return true; return true;
} }

View File

@ -180,7 +180,7 @@ static cell AMX_NATIVE_CALL log_error(AMX *amx, cell *params)
int len; int len;
char *err = format_amxstring(amx, params, 2, len); char *err = format_amxstring(amx, params, 2, len);
UTIL_Format(g_errorStr, sizeof(g_errorStr), "%s", err); ke::SafeSprintf(g_errorStr, sizeof(g_errorStr), "%s", err);
g_CurError = params[1]; g_CurError = params[1];
return 1; return 1;

View File

@ -289,7 +289,7 @@ bool Menu::Display(int player, page_t page)
return false; return false;
static char buffer[2048]; static char buffer[2048];
int len = UTIL_Format(buffer, sizeof(buffer)-1, "%s", str); int len = ke::SafeSprintf(buffer, sizeof(buffer)-1, "%s", str);
CPlayer *pPlayer = GET_PLAYER_POINTER_I(player); CPlayer *pPlayer = GET_PLAYER_POINTER_I(player);
@ -342,14 +342,14 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
if (items_per_page && (pages != 1)) if (items_per_page && (pages != 1))
{ {
if (m_AutoColors) if (m_AutoColors)
UTIL_Format(buffer, sizeof(buffer)-1, "\\y%s %d/%d\n\\w\n", m_Title.chars(), page + 1, pages); ke::SafeSprintf(buffer, sizeof(buffer)-1, "\\y%s %d/%d\n\\w\n", m_Title.chars(), page + 1, pages);
else else
UTIL_Format(buffer, sizeof(buffer)-1, "%s %d/%d\n\n", m_Title.chars(), page + 1, pages); ke::SafeSprintf(buffer, sizeof(buffer)-1, "%s %d/%d\n\n", m_Title.chars(), page + 1, pages);
} else { } else {
if (m_AutoColors) if (m_AutoColors)
UTIL_Format(buffer, sizeof(buffer)-1, "\\y%s\n\\w\n", m_Title.chars()); ke::SafeSprintf(buffer, sizeof(buffer)-1, "\\y%s\n\\w\n", m_Title.chars());
else else
UTIL_Format(buffer, sizeof(buffer)-1, "%s\n\n", m_Title.chars()); ke::SafeSprintf(buffer, sizeof(buffer)-1, "%s\n\n", m_Title.chars());
} }
m_Text = m_Text + buffer; m_Text = m_Text + buffer;
@ -446,22 +446,22 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
if (pItem->isBlank) if (pItem->isBlank)
{ {
UTIL_Format(buffer, sizeof(buffer)-1, "%s\n", pItem->name.chars()); ke::SafeSprintf(buffer, sizeof(buffer)-1, "%s\n", pItem->name.chars());
} }
else if (enabled) else if (enabled)
{ {
if (m_AutoColors) if (m_AutoColors)
{ {
UTIL_Format(buffer, sizeof(buffer)-1, "%s%d.\\w %s\n", m_ItemColor.chars(),option_display, pItem->name.chars()); ke::SafeSprintf(buffer, sizeof(buffer)-1, "%s%d.\\w %s\n", m_ItemColor.chars(),option_display, pItem->name.chars());
} else { } else {
UTIL_Format(buffer, sizeof(buffer)-1, "%d. %s\n", option_display, pItem->name.chars()); ke::SafeSprintf(buffer, sizeof(buffer)-1, "%d. %s\n", option_display, pItem->name.chars());
} }
} else { } else {
if (m_AutoColors) if (m_AutoColors)
{ {
UTIL_Format(buffer, sizeof(buffer)-1, "\\d%d. %s\n\\w", option_display, pItem->name.chars()); ke::SafeSprintf(buffer, sizeof(buffer)-1, "\\d%d. %s\n\\w", option_display, pItem->name.chars());
} else { } else {
UTIL_Format(buffer, sizeof(buffer)-1, "#. %s\n", pItem->name.chars()); ke::SafeSprintf(buffer, sizeof(buffer)-1, "#. %s\n", pItem->name.chars());
} }
} }
slots++; slots++;
@ -503,14 +503,14 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
keys |= (1<<option++); keys |= (1<<option++);
if (m_AutoColors) if (m_AutoColors)
{ {
UTIL_Format(buffer, ke::SafeSprintf(buffer,
sizeof(buffer)-1, sizeof(buffer)-1,
"%s%d. \\w%s\n", "%s%d. \\w%s\n",
m_ItemColor.chars(), m_ItemColor.chars(),
option == 10 ? 0 : option, option == 10 ? 0 : option,
m_OptNames[abs(MENU_BACK)].chars()); m_OptNames[abs(MENU_BACK)].chars());
} else { } else {
UTIL_Format(buffer, ke::SafeSprintf(buffer,
sizeof(buffer)-1, sizeof(buffer)-1,
"%d. %s\n", "%d. %s\n",
option == 10 ? 0 : option, option == 10 ? 0 : option,
@ -520,13 +520,13 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
option++; option++;
if (m_AutoColors) if (m_AutoColors)
{ {
UTIL_Format(buffer, ke::SafeSprintf(buffer,
sizeof(buffer)-1, sizeof(buffer)-1,
"\\d%d. %s\n\\w", "\\d%d. %s\n\\w",
option == 10 ? 0 : option, option == 10 ? 0 : option,
m_OptNames[abs(MENU_BACK)].chars()); m_OptNames[abs(MENU_BACK)].chars());
} else { } else {
UTIL_Format(buffer, sizeof(buffer)-1, "#. %s\n", m_OptNames[abs(MENU_BACK)].chars()); ke::SafeSprintf(buffer, sizeof(buffer)-1, "#. %s\n", m_OptNames[abs(MENU_BACK)].chars());
} }
} }
m_Text = m_Text + buffer; m_Text = m_Text + buffer;
@ -536,14 +536,14 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
keys |= (1<<option++); keys |= (1<<option++);
if (m_AutoColors) if (m_AutoColors)
{ {
UTIL_Format(buffer, ke::SafeSprintf(buffer,
sizeof(buffer)-1, sizeof(buffer)-1,
"%s%d. \\w%s\n", "%s%d. \\w%s\n",
m_ItemColor.chars(), m_ItemColor.chars(),
option == 10 ? 0 : option, option == 10 ? 0 : option,
m_OptNames[abs(MENU_MORE)].chars()); m_OptNames[abs(MENU_MORE)].chars());
} else { } else {
UTIL_Format(buffer, ke::SafeSprintf(buffer,
sizeof(buffer)-1, sizeof(buffer)-1,
"%d. %s\n", "%d. %s\n",
option == 10 ? 0 : option, option == 10 ? 0 : option,
@ -553,13 +553,13 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
option++; option++;
if (m_AutoColors) if (m_AutoColors)
{ {
UTIL_Format(buffer, ke::SafeSprintf(buffer,
sizeof(buffer)-1, sizeof(buffer)-1,
"\\d%d. %s\n\\w", "\\d%d. %s\n\\w",
option == 10 ? 0 : option, option == 10 ? 0 : option,
m_OptNames[abs(MENU_MORE)].chars()); m_OptNames[abs(MENU_MORE)].chars());
} else { } else {
UTIL_Format(buffer, sizeof(buffer)-1, "#. %s\n", m_OptNames[abs(MENU_MORE)].chars()); ke::SafeSprintf(buffer, sizeof(buffer)-1, "#. %s\n", m_OptNames[abs(MENU_MORE)].chars());
} }
} }
m_Text = m_Text + buffer; m_Text = m_Text + buffer;
@ -578,14 +578,14 @@ const char *Menu::GetTextString(int player, page_t page, int &keys)
keys |= (1<<option++); keys |= (1<<option++);
if (m_AutoColors) if (m_AutoColors)
{ {
UTIL_Format(buffer, ke::SafeSprintf(buffer,
sizeof(buffer)-1, sizeof(buffer)-1,
"%s%d. \\w%s\n", "%s%d. \\w%s\n",
m_ItemColor.chars(), m_ItemColor.chars(),
option == 10 ? 0 : option, option == 10 ? 0 : option,
m_OptNames[abs(MENU_EXIT)].chars()); m_OptNames[abs(MENU_EXIT)].chars());
} else { } else {
UTIL_Format(buffer, ke::SafeSprintf(buffer,
sizeof(buffer)-1, sizeof(buffer)-1,
"%d. %s\n", "%d. %s\n",
option == 10 ? 0 : option, option == 10 ? 0 : option,

View File

@ -10,22 +10,6 @@
#include <time.h> #include <time.h>
#include "amxmodx.h" #include "amxmodx.h"
#if ( defined(__linux__) || defined(__APPLE__) ) && !defined _vsnprintf
#define _vsnprintf vsnprintf
#endif
char *UTIL_VarArgs(const char *fmt, ...)
{
va_list ap;
static char string[4096];
va_start(ap, fmt);
ke::SafeVsprintf(string, sizeof(string), fmt, ap);
va_end(ap);
return string;
}
int UTIL_ReadFlags(const char* c) int UTIL_ReadFlags(const char* c)
{ {
int flags = 0; int flags = 0;
@ -351,8 +335,8 @@ void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1,
g_fakecmd.argv[1] = arg1; g_fakecmd.argv[1] = arg1;
g_fakecmd.argv[2] = arg2; g_fakecmd.argv[2] = arg2;
// build argument line // build argument line
UTIL_Format(g_fakecmd.args, 255, "%s %s", arg1, arg2); ke::SafeSprintf(g_fakecmd.args, 255, "%s %s", arg1, arg2);
// if UTIL_Format reached 255 chars limit, this will make sure there will be no access violation // if ke::SafeSprintf reached 255 chars limit, this will make sure there will be no access violation
g_fakecmd.args[255] = 0; g_fakecmd.args[255] = 0;
} }
else if (arg1) else if (arg1)
@ -361,8 +345,8 @@ void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1,
// store argument // store argument
g_fakecmd.argv[1] = arg1; g_fakecmd.argv[1] = arg1;
// build argument line // build argument line
UTIL_Format(g_fakecmd.args, 255, "%s", arg1); ke::SafeSprintf(g_fakecmd.args, 255, "%s", arg1);
// if UTIL_Format reached 255 chars limit, this will make sure there will be no access violation // if ke::SafeSprintf reached 255 chars limit, this will make sure there will be no access violation
g_fakecmd.args[255] = 0; g_fakecmd.args[255] = 0;
} }
else else
@ -694,16 +678,6 @@ char *UTIL_ReplaceEx(char *subject, size_t maxLen, const char *search, size_t se
return NULL; return NULL;
} }
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
size_t len = ke::SafeVsprintf(buffer, maxlength, fmt, ap);
va_end(ap);
return len;
}
// From Metamod:Source // From Metamod:Source
void UTIL_TrimLeft(char *buffer) void UTIL_TrimLeft(char *buffer)
{ {

View File

@ -19,6 +19,7 @@
#include "CstrikeHLTypeConversion.h" #include "CstrikeHLTypeConversion.h"
#include <CDetour/detours.h> #include <CDetour/detours.h>
#include <amtl/am-vector.h> #include <amtl/am-vector.h>
#include <amtl/am-string.h>
bool NoKifesMode = false; bool NoKifesMode = false;
@ -898,7 +899,7 @@ static cell AMX_NATIVE_CALL cs_set_user_model(AMX *amx, cell *params)
GET_OFFSET("CBasePlayer", m_modelIndexPlayer); GET_OFFSET("CBasePlayer", m_modelIndexPlayer);
char model[260]; char model[260];
UTIL_Format(model, sizeof(model), "models/player/%s/%s.mdl", newModel, newModel); ke::SafeSprintf(model, sizeof(model), "models/player/%s/%s.mdl", newModel, newModel);
for (size_t i = 0; i < HL_MODEL_MAX; ++i) for (size_t i = 0; i < HL_MODEL_MAX; ++i)
{ {

View File

@ -6,7 +6,7 @@ binary = AMXX.Program(builder, 'WinCSX')
binary.compiler.includes += [ binary.compiler.includes += [
os.path.join(builder.currentSourcePath, 'resources'), os.path.join(builder.currentSourcePath, 'resources'),
] ]
binary.compiler.defines += ['_MBCS'] binary.compiler.defines += ['_MBCS', 'HAVE_STDINT_H']
binary.compiler.linkflags += [ binary.compiler.linkflags += [
'comctl32.lib', 'comctl32.lib',
] ]

View File

@ -11,24 +11,7 @@
#include "WinCSX.h" #include "WinCSX.h"
#include <stdio.h> #include <stdio.h>
#include "commctrl.h" #include "commctrl.h"
#include <amtl/am-string.h>
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
size_t len = vsnprintf(buffer, maxlength, fmt, ap);
va_end(ap);
if (len >= maxlength)
{
buffer[maxlength - 1] = '\0';
return (maxlength - 1);
}
else
{
return len;
}
}
int APIENTRY _tWinMain(HINSTANCE hInstance, int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, HINSTANCE hPrevInstance,
@ -196,7 +179,7 @@ void UpdateListBox(HWND hDlg) {
//if ((*b).getPosition() < 1) // umm... naaah! //if ((*b).getPosition() < 1) // umm... naaah!
//continue; //continue;
UTIL_Format(tempbuffer, sizeof(tempbuffer)-1, "%s", (*b).getName()); ke::SafeSprintf(tempbuffer, sizeof(tempbuffer)-1, "%s", (*b).getName());
SendMessage( // returns LRESULT in lResult SendMessage( // returns LRESULT in lResult
listbox, // handle to destination control listbox, // handle to destination control
@ -343,7 +326,7 @@ void SaveChanges(HWND hDlg) {
UpdateListBox(hDlg); UpdateListBox(hDlg);
char buffer[256]; char buffer[256];
UTIL_Format(buffer, sizeof(buffer)-1, "New rank of %s: %d", name, newPosition); ke::SafeSprintf(buffer, sizeof(buffer)-1, "New rank of %s: %d", name, newPosition);
MessageBox(hDlg, buffer, "Update succeeded", MB_OK); MessageBox(hDlg, buffer, "Update succeeded", MB_OK);
// In the listbox, we need to reselect the item we just updated. Use the new name. // In the listbox, we need to reselect the item we just updated. Use the new name.

View File

@ -945,7 +945,7 @@ static cell AMX_NATIVE_CALL traceresult(AMX *amx, cell *params)
// (jghg) // (jghg)
static cell AMX_NATIVE_CALL get_string(AMX *amx, cell *params) // (string, returnstring[], length) static cell AMX_NATIVE_CALL get_string(AMX *amx, cell *params) // (string, returnstring[], length)
{ {
UTIL_Format(g_buffer, sizeof(g_buffer)-1, "%s", STRING(params[1])); ke::SafeSprintf(g_buffer, sizeof(g_buffer)-1, "%s", STRING(params[1]));
return MF_SetAmxString(amx, params[2], g_buffer, params[3]); return MF_SetAmxString(amx, params[2], g_buffer, params[3]);
} }

View File

@ -299,23 +299,23 @@ static cell AMX_NATIVE_CALL amx_pev(AMX *amx,cell *params)
return num; return num;
} else if (ValType & Ret_Int) { } else if (ValType & Ret_Int) {
char temp[32]; char temp[32];
UTIL_Format(temp, sizeof(temp)-1, "%d", rets.i); ke::SafeSprintf(temp, sizeof(temp)-1, "%d", rets.i);
return MF_SetAmxString(amx, params[3], temp, size); return MF_SetAmxString(amx, params[3], temp, size);
} else if (ValType == Ret_Float) { } else if (ValType == Ret_Float) {
char temp[32]; char temp[32];
UTIL_Format(temp, sizeof(temp)-1, "%f", rets.f); ke::SafeSprintf(temp, sizeof(temp)-1, "%f", rets.f);
return MF_SetAmxString(amx, params[3], temp, size); return MF_SetAmxString(amx, params[3], temp, size);
} else if (ValType == Ret_Vec) { } else if (ValType == Ret_Vec) {
char temp[32]; char temp[32];
UTIL_Format(temp, sizeof(temp)-1, "%f %f %f", vr.x, vr.y, vr.z); ke::SafeSprintf(temp, sizeof(temp)-1, "%f %f %f", vr.x, vr.y, vr.z);
return MF_SetAmxString(amx, params[3], temp, size); return MF_SetAmxString(amx, params[3], temp, size);
} else if (ValType == Ret_Bytes2) { } else if (ValType == Ret_Bytes2) {
char temp[32]; char temp[32];
UTIL_Format(temp, sizeof(temp)-1, "%d %d", rets.ba[0], rets.ba[1]); ke::SafeSprintf(temp, sizeof(temp)-1, "%d %d", rets.ba[0], rets.ba[1]);
return MF_SetAmxString(amx, params[3], temp, size); return MF_SetAmxString(amx, params[3], temp, size);
} else if (ValType == Ret_Bytes4) { } else if (ValType == Ret_Bytes4) {
char temp[32]; char temp[32];
UTIL_Format(temp, sizeof(temp)-1, "%d %d %d %d", rets.ba[0], rets.ba[1], rets.ba[2], rets.ba[3]); ke::SafeSprintf(temp, sizeof(temp)-1, "%d %d %d %d", rets.ba[0], rets.ba[1], rets.ba[2], rets.ba[3]);
return MF_SetAmxString(amx, params[3], temp, size); return MF_SetAmxString(amx, params[3], temp, size);
} }

View File

@ -192,7 +192,7 @@ bool loadDatabase()
// MF_BuildPathname not used because backslash // MF_BuildPathname not used because backslash
// makes CreateFileMapping failing under windows. // makes CreateFileMapping failing under windows.
UTIL_Format(file, sizeof(file) - 1, "%s/%s/GeoLite2-%s.mmdb", modName, dataDir, databases[i]); ke::SafeSprintf(file, sizeof(file) - 1, "%s/%s/GeoLite2-%s.mmdb", modName, dataDir, databases[i]);
status = MMDB_open(file, MMDB_MODE_MMAP, &HandleDB); status = MMDB_open(file, MMDB_MODE_MMAP, &HandleDB);

View File

@ -157,7 +157,7 @@ static cell AMX_NATIVE_CALL amx_geoip_region_code(AMX *amx, cell *params)
if (countryCode) if (countryCode)
{ {
finalLength = length + 1; // + 1 for dash. finalLength = length + 1; // + 1 for dash.
UTIL_Format(code, finalLength + 1, "%s-", countryCode); // + EOS. ke::SafeSprintf(code, finalLength + 1, "%s-", countryCode); // + EOS.
const char *pathRegion[] = { "subdivisions", "0", "iso_code", NULL }; // First result. const char *pathRegion[] = { "subdivisions", "0", "iso_code", NULL }; // First result.
const char *regionCode = lookupString(ip, pathRegion, &length); const char *regionCode = lookupString(ip, pathRegion, &length);

View File

@ -16,6 +16,7 @@
#include "ham_const.h" #include "ham_const.h"
#include "hooklist.h" #include "hooklist.h"
#include "offsets.h" #include "offsets.h"
#include <amtl/am-string.h>
extern hook_t hooklist[]; extern hook_t hooklist[];
@ -108,7 +109,7 @@ static void read_mirror(char *input)
*data='\0'; *data='\0';
// mark down the source // mark down the source
UTIL_Format(source, sizeof(source)-1, "%s", input); ke::SafeSprintf(source, sizeof(source)-1, "%s", input);
*data=old; *data=old;
@ -128,13 +129,13 @@ static void read_mirror(char *input)
old=*data; old=*data;
*data='\0'; *data='\0';
UTIL_Format(dest, sizeof(dest)-1, "%s", data2); ke::SafeSprintf(dest, sizeof(dest)-1, "%s", data2);
*data=old; *data=old;
if (strcmp(dest, CurrentModName)==0) if (strcmp(dest, CurrentModName)==0)
{ {
UTIL_Format(CurrentModName, sizeof(CurrentModName)-1, "%s", source); ke::SafeSprintf(CurrentModName, sizeof(CurrentModName)-1, "%s", source);
} }
} }
@ -313,7 +314,7 @@ int ReadConfig(void)
FILE *fp=fopen(FileName,"r"); FILE *fp=fopen(FileName,"r");
UTIL_Format(CurrentModName, sizeof(CurrentModName)-1, "%s", MF_GetModname()); ke::SafeSprintf(CurrentModName, sizeof(CurrentModName)-1, "%s", MF_GetModname());
if (!fp) if (!fp)
{ {

View File

@ -17,16 +17,17 @@
#include "amxxmodule.h" #include "amxxmodule.h"
#include "offsets.h" #include "offsets.h"
#include "NEW_Util.h" #include "NEW_Util.h"
#include <amtl/am-string.h>
#define CHECK_FUNCTION(x) \ #define CHECK_FUNCTION(x) \
if (x < 0 || x >= HAM_LAST_ENTRY_DONT_USE_ME_LOL) { \ if (x < 0 || x >= HAM_LAST_ENTRY_DONT_USE_ME_LOL) { \
char msg[1024]; \ char msg[1024]; \
UTIL_Format(msg, sizeof(msg)-1, "Function out of bounds. Got: %d Max: %d", x, HAM_LAST_ENTRY_DONT_USE_ME_LOL - 1); \ ke::SafeSprintf(msg, sizeof(msg)-1, "Function out of bounds. Got: %d Max: %d", x, HAM_LAST_ENTRY_DONT_USE_ME_LOL - 1); \
FailPlugin(amx, x, HAM_INVALID_FUNC, msg); \ FailPlugin(amx, x, HAM_INVALID_FUNC, msg); \
return 0; \ return 0; \
} else if (hooklist[x].isset == 0) { \ } else if (hooklist[x].isset == 0) { \
char msg[1024]; \ char msg[1024]; \
UTIL_Format(msg, sizeof(msg)-1, "Function %s is not configured in hamdata.ini.", hooklist[x].name); \ ke::SafeSprintf(msg, sizeof(msg)-1, "Function %s is not configured in hamdata.ini.", hooklist[x].name); \
FailPlugin(amx, x, HAM_FUNC_NOT_CONFIGURED, msg); \ FailPlugin(amx, x, HAM_FUNC_NOT_CONFIGURED, msg); \
return 0; \ return 0; \
} }

View File

@ -17,6 +17,7 @@
#include "forward.h" #include "forward.h"
#include "Trampolines.h" #include "Trampolines.h"
#include <amtl/am-vector.h> #include <amtl/am-vector.h>
#include <amtl/am-string.h>
#define ALIGN(ar) ((intptr_t)ar & ~(sysconf(_SC_PAGESIZE)-1)) #define ALIGN(ar) ((intptr_t)ar & ~(sysconf(_SC_PAGESIZE)-1))
@ -62,7 +63,7 @@ public:
size_t len=strlen(name); size_t len=strlen(name);
ent=new char[len+1]; ent=new char[len+1];
UTIL_Format(ent, len + 1, "%s", name); ke::SafeSprintf(ent, len + 1, "%s", name);
}; };
~Hook() ~Hook()

View File

@ -707,7 +707,7 @@ static cell AMX_NATIVE_CALL RegisterHamFromEntity(AMX *amx, cell *params)
// It may very well be wrong (such as lots of TS weapons have the same classname) // It may very well be wrong (such as lots of TS weapons have the same classname)
// but it's the best we can do, and better than nothing. // but it's the best we can do, and better than nothing.
// (only used for display) // (only used for display)
UTIL_Format(classname, sizeof(classname) - 1, "%s", STRING(Entity->v.classname)); ke::SafeSprintf(classname, sizeof(classname) - 1, "%s", STRING(Entity->v.classname));
// If we got here, the function is not hooked // If we got here, the function is not hooked
Hook *hook = new Hook(vtable, hooklist[func].vtid, hooklist[func].targetfunc, hooklist[func].isvoid, hooklist[func].needsretbuf, hooklist[func].paramcount, classname); Hook *hook = new Hook(vtable, hooklist[func].vtid, hooklist[func].targetfunc, hooklist[func].isvoid, hooklist[func].needsretbuf, hooklist[func].paramcount, classname);

View File

@ -14,6 +14,7 @@
#include "amxxmodule.h" #include "amxxmodule.h"
#include "MysqlDriver.h" #include "MysqlDriver.h"
#include "MysqlDatabase.h" #include "MysqlDatabase.h"
#include <amtl/am-string.h>
using namespace SourceMod; using namespace SourceMod;
@ -47,7 +48,7 @@ IDatabase *MysqlDriver::_Connect(DatabaseInfo *info, int *errcode, char *error,
*errcode = -1; *errcode = -1;
if (error && maxlength) if (error && maxlength)
{ {
UTIL_Format(error, maxlength, "Initialization failed"); ke::SafeSprintf(error, maxlength, "Initialization failed");
} }
return NULL; return NULL;
} }
@ -89,7 +90,7 @@ IDatabase *MysqlDriver::_Connect(DatabaseInfo *info, int *errcode, char *error,
} }
if (error && maxlength) if (error && maxlength)
{ {
UTIL_Format(error, maxlength, "%s", mysql_error(mysql)); ke::SafeSprintf(error, maxlength, "%s", mysql_error(mysql));
} }
return NULL; return NULL;
} }

View File

@ -15,6 +15,7 @@
#include "MysqlQuery.h" #include "MysqlQuery.h"
#include "MysqlDatabase.h" #include "MysqlDatabase.h"
#include "MysqlResultSet.h" #include "MysqlResultSet.h"
#include <amtl/am-string.h>
using namespace SourceMod; using namespace SourceMod;
@ -90,7 +91,7 @@ bool MysqlQuery::ExecuteR(QueryInfo *info, char *error, size_t maxlength)
info->rs = NULL; info->rs = NULL;
if (error && maxlength) if (error && maxlength)
{ {
UTIL_Format(error, maxlength, "%s", mysql_error(m_pDatabase->m_pMysql)); ke::SafeSprintf(error, maxlength, "%s", mysql_error(m_pDatabase->m_pMysql));
} }
} }
else else

View File

@ -26,7 +26,7 @@ void ParticleManager::ReadFile(void)
char FileName[256]; char FileName[256];
UTIL_Format(FileName, sizeof(FileName)-1, "%s/ns.ps", MF_GetModname()); ke::SafeSprintf(FileName, sizeof(FileName)-1, "%s/ns.ps", MF_GetModname());
FILE *fp=fopen(FileName,"r"); FILE *fp=fopen(FileName,"r");
if (!fp) if (!fp)

View File

@ -27,7 +27,7 @@ void TitleManager::LoadTitles(void)
char FileName[128]; char FileName[128];
UTIL_Format(FileName, sizeof(FileName)-1, "%s/titles.txt", MF_GetModname()); ke::SafeSprintf(FileName, sizeof(FileName)-1, "%s/titles.txt", MF_GetModname());
FILE *fp=fopen(FileName,"r"); FILE *fp=fopen(FileName,"r");

View File

@ -23,6 +23,7 @@
#include "ParticleManager.h" #include "ParticleManager.h"
#include "AllocString.h" #include "AllocString.h"
#include <amtl/am-string.h>
extern int gmsgHudText2; extern int gmsgHudText2;
extern BOOL iscombat; extern BOOL iscombat;
@ -91,9 +92,9 @@ void OnAmxxAttach()
char FileName[256]; char FileName[256];
DLHANDLE DLLBase; DLHANDLE DLLBase;
#ifdef __linux__ #ifdef __linux__
UTIL_Format(FileName, sizeof(FileName), "%s/dlls/ns_i386.so", MF_GetModname()); ke::SafeSprintf(FileName, sizeof(FileName), "%s/dlls/ns_i386.so", MF_GetModname());
#else #else
UTIL_Format(FileName, sizeof(FileName), "%s\\dlls\\ns.dll", MF_GetModname()); ke::SafeSprintf(FileName, sizeof(FileName), "%s\\dlls\\ns.dll", MF_GetModname());
#endif #endif
DLLBase = DLOPEN(FileName); DLLBase = DLOPEN(FileName);

View File

@ -48,7 +48,7 @@ cell PSKeyValueI(const char *name, AMX *amx, cell *params)
char StrData[1024]; char StrData[1024];
UTIL_Format(StrData, sizeof(StrData)-1, "%d", params[2]); ke::SafeSprintf(StrData, sizeof(StrData)-1, "%d", params[2]);
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname)); kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
kvd.szKeyName=name; kvd.szKeyName=name;
@ -71,7 +71,7 @@ cell PSKeyValueF(const char *name, AMX *amx, cell *params)
char StrData[1024]; char StrData[1024];
UTIL_Format(StrData, sizeof(StrData)-1, "%f", amx_ctof2(params[2])); ke::SafeSprintf(StrData, sizeof(StrData)-1, "%f", amx_ctof2(params[2]));
kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname)); kvd.szClassName=const_cast<char *>(STRING(reinterpret_cast<edict_t *>(params[1])->v.classname));
kvd.szKeyName=name; kvd.szKeyName=name;

View File

@ -367,7 +367,7 @@ bool NVault::GetValue(const char *key, time_t &stamp, char buffer[], size_t len)
} }
stamp = result.stamp; stamp = result.stamp;
UTIL_Format(buffer, len, "%s", result.value.chars()); ke::SafeSprintf(buffer, len, "%s", result.value.chars());
return true; return true;
} }

View File

@ -15,6 +15,7 @@
#include "SqliteHeaders.h" #include "SqliteHeaders.h"
#include "SqliteDriver.h" #include "SqliteDriver.h"
#include "SqliteDatabase.h" #include "SqliteDatabase.h"
#include <amtl/am-string.h>
#if defined WIN32 #if defined WIN32
#define WINDOWS_LEAN_AND_MEAN #define WINDOWS_LEAN_AND_MEAN
@ -62,7 +63,7 @@ IDatabase *SqliteDriver::Connect(DatabaseInfo *info, int *errcode, char *error,
} }
if (error) if (error)
{ {
UTIL_Format(error, maxlength, "%s", sqlite3_errmsg(pSql)); ke::SafeSprintf(error, maxlength, "%s", sqlite3_errmsg(pSql));
} }
sqlite3_close(pSql); sqlite3_close(pSql);
return NULL; return NULL;

View File

@ -15,6 +15,7 @@
#include "SqliteQuery.h" #include "SqliteQuery.h"
#include "SqliteDatabase.h" #include "SqliteDatabase.h"
#include "SqliteResultSet.h" #include "SqliteResultSet.h"
#include <amtl/am-string.h>
using namespace SourceMod; using namespace SourceMod;
@ -92,7 +93,7 @@ bool SqliteQuery::ExecuteR(QueryInfo *info, char *error, size_t maxlength)
{ {
if (error && maxlength && errmsg) if (error && maxlength && errmsg)
{ {
UTIL_Format(error, maxlength, "%s", errmsg); ke::SafeSprintf(error, maxlength, "%s", errmsg);
} }
info->affected_rows = 0; info->affected_rows = 0;
info->errorcode = err; info->errorcode = err;

View File

@ -3134,24 +3134,6 @@ unsigned short FixedUnsigned16( float value, float scale )
} }
#endif // USE_METAMOD #endif // USE_METAMOD
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
size_t len = vsnprintf(buffer, maxlength, fmt, ap);
va_end(ap);
if (len >= maxlength)
{
buffer[maxlength - 1] = '\0';
return (maxlength - 1);
}
else
{
return len;
}
}
template unsigned int strncopy<char, char>(char *, const char *src, size_t count); template unsigned int strncopy<char, char>(char *, const char *src, size_t count);
template unsigned int strncopy<cell, char>(cell *, const char *src, size_t count); template unsigned int strncopy<cell, char>(cell *, const char *src, size_t count);
template unsigned int strncopy<cell, cell>(cell *, const cell *src, size_t count); template unsigned int strncopy<cell, cell>(cell *, const cell *src, size_t count);

View File

@ -2508,7 +2508,6 @@ void Mem_Deallocator(const char *sourceFile, const unsigned int sourceLine, cons
#endif //MEMORY_TEST #endif //MEMORY_TEST
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...);
template <typename D, typename S> unsigned int strncopy(D *dest, const S *src, size_t count); template <typename D, typename S> unsigned int strncopy(D *dest, const S *src, size_t count);
#endif // #ifndef __AMXXMODULE_H__ #endif // #ifndef __AMXXMODULE_H__