Mercurial > hg > openttd
changeset 2234:a5e44c6e40dd draft
(svn r2754) Move str_fmt into string.[ch]
author | tron <tron@openttd.org> |
---|---|
date | Fri, 29 Jul 2005 21:52:20 +0000 |
parents | 1631045675f5 |
children | 873288b3fbf3 |
files | functions.h openttd.c string.c string.h |
diffstat | 4 files changed, 20 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/functions.h +++ b/functions.h @@ -275,7 +275,6 @@ int ttd_main(int argc, char* argv[]); void DeterminePaths(void); -char * CDECL str_fmt(const char *str, ...); void bubblesort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); bool CreateOTTDThread(void *func, void *param);
--- a/openttd.c +++ b/openttd.c @@ -93,22 +93,6 @@ ShowInfo(buf); } -char * CDECL str_fmt(const char *str, ...) -{ - char buf[4096]; - va_list va; - int len; - char *p; - - va_start(va, str); - len = vsprintf(buf, str, va); - va_end(va); - p = malloc(len + 1); - if (p) - memcpy(p, buf, len + 1); - return p; -} - void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize) {
--- a/string.c +++ b/string.c @@ -3,6 +3,8 @@ #include "stdafx.h" #include "string.h" +#include <stdarg.h> + void ttd_strlcat(char *dst, const char *src, size_t size) { assert(size > 0); @@ -39,3 +41,19 @@ *dst = '\0'; return dst; } + + +char* CDECL str_fmt(const char* str, ...) +{ + char buf[4096]; + va_list va; + int len; + char* p; + + va_start(va, str); + len = vsprintf(buf, str, va); + va_end(va); + p = malloc(len + 1); + if (p != NULL) memcpy(p, buf, len + 1); + return p; +}