X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=ftepp.c;h=5f414f358bb868df23815d875d0579ad9067ac41;hb=904c45060bd688abf909fe3a679778fb3f3d346b;hp=a28bbec862720fa75dacdbb0e0dd9c4a1212a3bb;hpb=a622d5163b9852c66d8399e05e5731d3a538d43b;p=xonotic%2Fgmqcc.git diff --git a/ftepp.c b/ftepp.c index a28bbec..5f414f3 100644 --- a/ftepp.c +++ b/ftepp.c @@ -183,6 +183,9 @@ static char *ftepp_predef_timestamp(lex_file *context) { char *find; char *value; size_t size; +#ifdef _MSC_VER + char buffer[64]; +#endif if (stat(context->name, &finfo)) return util_strdup("\"\""); @@ -190,7 +193,14 @@ static char *ftepp_predef_timestamp(lex_file *context) { * ctime and its fucking annoying newline char, no worries, we're * professionals here. */ + +#ifndef _MSC_VER find = ctime(&finfo.st_mtime); +#else + ctime_s(buffer, sizeof(buffer), &finfo.st_mtime); + find = buffer; +#endif + value = (char*)mem_a(strlen(find) + 1); memcpy(&value[1], find, (size = strlen(find)) - 1); @@ -217,24 +227,24 @@ static const ftepp_predef_t ftepp_predefs[] = { { "__TIME_STAMP__", &ftepp_predef_timestamp } }; -static GMQCC_INLINE int ftepp_predef_index(const char *name) { +static GMQCC_INLINE size_t ftepp_predef_index(const char *name) { /* no hashtable here, we simply check for one to exist the naive way */ - int i; - for(i = 0; i < (int)(sizeof(ftepp_predefs)/sizeof(*ftepp_predefs)); i++) - if (!strcmp(ftepp_predefs[i].name, name)) + size_t i; + for(i = 1; i < GMQCC_ARRAY_COUNT(ftepp_predefs) + 1; i++) + if (!strcmp(ftepp_predefs[i-1].name, name)) return i; - return -1; + return 0; } bool ftepp_predef_exists(const char *name); bool ftepp_predef_exists(const char *name) { - return ftepp_predef_index(name) != -1; + return ftepp_predef_index(name) != 0; } /* singleton because we're allowed */ static GMQCC_INLINE char *(*ftepp_predef(const char *name))(lex_file *context) { - int i = ftepp_predef_index(name); - return (i != -1) ? ftepp_predefs[i].func : NULL; + size_t i = ftepp_predef_index(name); + return (i != 0) ? ftepp_predefs[i-1].func : NULL; } #define ftepp_tokval(f) ((f)->lex->tok.value)