From 9fc926864ee7737161d450c56012055334cfcad4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 15 Mar 2014 12:35:20 -0700 Subject: [PATCH] Fixes for Visual C++ snprintf and strncasecmp are not that. _access needs to be fixed on gcc, next. --- CMakeLists.txt | 4 +++ autoconf.h.in | 1 + src/bind_monsters.c | 2 +- src/bind_storage.c | 2 +- src/kernel/curse.c | 2 +- src/kernel/reports.c | 24 ++++++------- src/laws.c | 18 +++++----- src/platform.h | 4 +++ src/report.c | 86 ++++++++++++++++++++++---------------------- src/spells/spells.c | 2 +- src/util/bsdstring.c | 2 +- src/util/log.c | 6 ++-- src/util/xml.c | 2 +- src/xmlreport.c | 16 ++++----- 14 files changed, 90 insertions(+), 81 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5578a3889..4e85a2781 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,12 @@ INCLUDE (CheckIncludeFiles) INCLUDE (CheckSymbolExists) CHECK_INCLUDE_FILES (stdbool.h HAVE_STDBOOL_H) CHECK_INCLUDE_FILES (windows.h HAVE_WINDOWS_H) +CHECK_INCLUDE_FILES (io.h HAVE_IO_H) CHECK_INCLUDE_FILES (strings.h HAVE_STRINGS_H) CHECK_INCLUDE_FILES (unistd.h HAVE_UNISTD_H) +IF (HAVE_IO_H) +CHECK_SYMBOL_EXISTS (_access "io.h" HAVE__ACCESS) +ENDIF (HAVE_IO_H) IF (HAVE_WINDOWS_H) CHECK_SYMBOL_EXISTS (_sleep "windows.h" HAVE__SLEEP) ENDIF(HAVE_WINDOWS_H) diff --git a/autoconf.h.in b/autoconf.h.in index 4a098fcc7..477f8b4d8 100644 --- a/autoconf.h.in +++ b/autoconf.h.in @@ -4,6 +4,7 @@ #cmakedefine HAVE_STDBOOL_H 1 #cmakedefine HAVE_STRINGS_H 1 #cmakedefine HAVE_WINDOWS_H 1 +#cmakedefine HAVE_IO_H 1 #cmakedefine HAVE_UNISTD_H 1 #cmakedefine HAVE__BOOL 1 #cmakedefine HAVE_STRCASECMP 1 diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 9749e7e08..8d2b42700 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -68,7 +68,7 @@ static int fix_familiars(struct lua_State *L) free(mage->spellbook); mage->spellbook = 0; - snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name[0]); + _snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name[0]); eq = get_equipment(buffer); if (eq) { equip_unit_mask(u, eq, EQUIP_SPELLS); diff --git a/src/bind_storage.c b/src/bind_storage.c index 22e12d117..05f735929 100644 --- a/src/bind_storage.c +++ b/src/bind_storage.c @@ -107,7 +107,7 @@ static int tolua_storage_tostring(lua_State * L) { gamedata *data = (gamedata *)tolua_tousertype(L, 1, 0); char name[64]; - snprintf(name, sizeof(name), "", data->encoding, + _snprintf(name, sizeof(name), "", data->encoding, data->version); lua_pushstring(L, name); return 1; diff --git a/src/kernel/curse.c b/src/kernel/curse.c index a804fa289..46d7aad43 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -316,7 +316,7 @@ const curse_type *ct_find(const char *c) return type; } else { size_t k = MIN(strlen(c), strlen(type->cname)); - if (!strncasecmp(c, type->cname, k)) { + if (!_memicmp(c, type->cname, k)) { return type; } } diff --git a/src/kernel/reports.c b/src/kernel/reports.c index 1980a8c28..0cef0e6af 100644 --- a/src/kernel/reports.c +++ b/src/kernel/reports.c @@ -526,7 +526,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf, if (a_otherfaction && alliedunit(u, f, HELP_FSTEALTH)) { faction *f = get_otherfaction(a_otherfaction); bytes = - snprintf(bufp, size, ", %s (%s)", factionname(f), + _snprintf(bufp, size, ", %s (%s)", factionname(f), factionname(u->faction)); if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -550,7 +550,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf, && effskill(u, SK_STEALTH) >= 6) { bytes = (int)strlcpy(bufp, "? ", size); } else { - bytes = snprintf(bufp, size, "%d ", u->number); + bytes = _snprintf(bufp, size, "%d ", u->number); } if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -687,7 +687,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf, WARN_STATIC_BUFFER(); if (!dh) { - bytes = snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_inventory")); + bytes = _snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_inventory")); if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); dh = 1; @@ -695,7 +695,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf, if (in == 1) { bytes = (int)strlcpy(bufp, ic, size); } else { - bytes = snprintf(bufp, size, "%d %s", in, ic); + bytes = _snprintf(bufp, size, "%d %s", in, ic); } if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -707,7 +707,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf, if (book) { quicklist *ql = book->spells; int qi, header, maxlevel = effskill(u, SK_MAGIC); - int bytes = snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u)); + int bytes = _snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region, u)); if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0) { WARN_STATIC_BUFFER(); } @@ -716,7 +716,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf, spellbook_entry * sbe = (spellbook_entry *) ql_get(ql, qi); if (sbe->level <= maxlevel) { if (!header) { - bytes = snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells")); + bytes = _snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells")); header = 1; } else { bytes = (int)strlcpy(bufp, ", ", size); @@ -737,7 +737,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf, } if (i != MAXCOMBATSPELLS) { bytes = - snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_combatspells")); + _snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_combatspells")); if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -762,7 +762,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf, } if (sl > 0) { - bytes = snprintf(bufp, size, " (%d)", sl); + bytes = _snprintf(bufp, size, " (%d)", sl); if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -1870,7 +1870,7 @@ f_regionid(const region * r, const faction * f, char *buffer, size_t size) pnormalize(&nx, &ny, pl); adjust_coordinates(f, &nx, &ny, pl, r); len = strlcpy(buffer, rname(r, f?f->locale:0), size); - snprintf(buffer + len, size-len, " (%d,%d%s%s)", nx, ny, named ? "," : "", (named) ? name : ""); + _snprintf(buffer + len, size-len, " (%d,%d%s%s)", nx, ny, named ? "," : "", (named) ? name : ""); buffer[size-1] = 0; len=strlen(buffer); } @@ -2149,7 +2149,7 @@ static void eval_resources(struct opstack **stack, const void *userdata) while (res != NULL && size > 4) { const char *rname = resourcename(res->type, (res->number != 1) ? NMF_PLURAL : 0); - int bytes = snprintf(bufp, size, "%d %s", res->number, LOC(lang, rname)); + int bytes = _snprintf(bufp, size, "%d %s", res->number, LOC(lang, rname)); if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0 || size < sizeof(buf) / 2) { WARN_STATIC_BUFFER(); break; @@ -2214,7 +2214,7 @@ static void eval_trail(struct opstack **stack, const void *userdata) variant var; char *bufp = buf; #ifdef _SECURECRT_ERRCODE_VALUES_DEFINED - /* stupid MS broke snprintf */ + /* stupid MS broke _snprintf */ int eold = errno; #endif @@ -2224,7 +2224,7 @@ static void eval_trail(struct opstack **stack, const void *userdata) region *r = regions->regions[i]; const char *trail = trailinto(r, lang); const char *rn = f_regionid_s(r, report); - int bytes = snprintf(bufp, size, trail, rn); + int bytes = _snprintf(bufp, size, trail, rn); if (bytes < 0 || wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); diff --git a/src/laws.c b/src/laws.c index 429e6a73b..e237d983e 100755 --- a/src/laws.c +++ b/src/laws.c @@ -2568,28 +2568,28 @@ static bool display_race(faction * f, unit * u, const race * rc) } } if (rc->battle_flags & BF_EQUIPMENT) { - bytes = snprintf(bufp, size, " %s", LOC(f->locale, "stat_equipment")); + bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "stat_equipment")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } if (rc->battle_flags & BF_RES_PIERCE) { - bytes = snprintf(bufp, size, " %s", LOC(f->locale, "stat_pierce")); + bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "stat_pierce")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } if (rc->battle_flags & BF_RES_CUT) { - bytes = snprintf(bufp, size, " %s", LOC(f->locale, "stat_cut")); + bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "stat_cut")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } if (rc->battle_flags & BF_RES_BASH) { - bytes = snprintf(bufp, size, " %s", LOC(f->locale, "stat_bash")); + bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "stat_bash")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } bytes = - snprintf(bufp, size, " %d %s", at_count, LOC(f->locale, + _snprintf(bufp, size, " %d %s", at_count, LOC(f->locale, (at_count == 1) ? "stat_attack" : "stat_attacks")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -2606,12 +2606,12 @@ static bool display_race(faction * f, unit * u, const race * rc) switch (rc->attack[a].type) { case AT_STANDARD: bytes = - snprintf(bufp, size, "%s (%s)", + _snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_standard"), rc->def_damage); break; case AT_NATURAL: bytes = - snprintf(bufp, size, "%s (%s)", + _snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_natural"), rc->attack[a].data.dice); break; case AT_SPELL: @@ -2619,11 +2619,11 @@ static bool display_race(faction * f, unit * u, const race * rc) case AT_DRAIN_ST: case AT_DRAIN_EXP: case AT_DAZZLE: - bytes = snprintf(bufp, size, "%s", LOC(f->locale, "attack_magical")); + bytes = _snprintf(bufp, size, "%s", LOC(f->locale, "attack_magical")); break; case AT_STRUCTURAL: bytes = - snprintf(bufp, size, "%s (%s)", + _snprintf(bufp, size, "%s (%s)", LOC(f->locale, "attack_structural"), rc->attack[a].data.dice); break; default: diff --git a/src/platform.h b/src/platform.h index 4a941b2dd..15b74ac1b 100644 --- a/src/platform.h +++ b/src/platform.h @@ -139,4 +139,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #endif +#ifdef HAVE_IO_H +#include +#endif + #endif diff --git a/src/report.c b/src/report.c index 2af1441ae..73927cf77 100644 --- a/src/report.c +++ b/src/report.c @@ -285,17 +285,17 @@ static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) bufp = buf; if (sp->sptyp & SPELLLEVEL) { bytes = - snprintf(bufp, size, " %d %s", itemanz, LOC(lang, resourcename(rtype, + _snprintf(bufp, size, " %d %s", itemanz, LOC(lang, resourcename(rtype, itemanz != 1))); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); if (costtyp == SPC_LEVEL || costtyp == SPC_LINEAR) { - bytes = snprintf(bufp, size, " * %s", LOC(lang, "nr_level")); + bytes = _snprintf(bufp, size, " * %s", LOC(lang, "nr_level")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } } else { - bytes = snprintf(bufp, size, "%d %s", itemanz, LOC(lang, resourcename(rtype, itemanz != 1))); + bytes = _snprintf(bufp, size, "%d %s", itemanz, LOC(lang, resourcename(rtype, itemanz != 1))); if (wrptr(&bufp, &size, bytes) != 0) { WARN_STATIC_BUFFER(); } @@ -352,17 +352,17 @@ static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) /* Reihenfolge beachten: Erst REGION, dann STUFE! */ if (sp->sptyp & FARCASTING) { - bytes = snprintf(bufp, size, " [%s x y]", LOC(lang, parameters[P_REGION])); + bytes = _snprintf(bufp, size, " [%s x y]", LOC(lang, parameters[P_REGION])); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } if (sp->sptyp & SPELLLEVEL) { - bytes = snprintf(bufp, size, " [%s n]", LOC(lang, parameters[P_LEVEL])); + bytes = _snprintf(bufp, size, " [%s n]", LOC(lang, parameters[P_LEVEL])); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } - bytes = (int)snprintf(bufp, size, " \"%s\"", spell_name(sp, lang)); + bytes = (int)_snprintf(bufp, size, " \"%s\"", spell_name(sp, lang)); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -388,24 +388,24 @@ static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) if (cp == 'u') { targetp = targets + 1; locp = LOC(lang, targetp->vars); - bytes = (int)snprintf(bufp, size, " <%s>", locp); + bytes = (int)_snprintf(bufp, size, " <%s>", locp); if (*params == '+') { ++params; if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp); + bytes = (int)_snprintf(bufp, size, " [<%s> ...]", locp); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } else if (cp == 's') { targetp = targets + 2; locp = LOC(lang, targetp->vars); - bytes = (int)snprintf(bufp, size, " <%s>", locp); + bytes = (int)_snprintf(bufp, size, " <%s>", locp); if (*params == '+') { ++params; if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp); + bytes = (int)_snprintf(bufp, size, " [<%s> ...]", locp); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -422,12 +422,12 @@ static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) } else if (cp == 'b') { targetp = targets + 3; locp = LOC(lang, targetp->vars); - bytes = (int)snprintf(bufp, size, " <%s>", locp); + bytes = (int)_snprintf(bufp, size, " <%s>", locp); if (*params == '+') { ++params; if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp); + bytes = (int)_snprintf(bufp, size, " [<%s> ...]", locp); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -456,17 +456,17 @@ static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) if (targetp->param) { locp = LOC(lang, targetp->vars); bytes = - (int)snprintf(bufp, size, " %s <%s>", parameters[targetp->param], + (int)_snprintf(bufp, size, " %s <%s>", parameters[targetp->param], locp); if (*params == '+') { ++params; if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); - bytes = (int)snprintf(bufp, size, " [<%s> ...]", locp); + bytes = (int)_snprintf(bufp, size, " [<%s> ...]", locp); } } else { bytes = - (int)snprintf(bufp, size, " %s", parameters[targetp->param]); + (int)_snprintf(bufp, size, " %s", parameters[targetp->param]); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -490,7 +490,7 @@ static void nr_spell(FILE * F, spellbook_entry * sbe, const struct locale *lang) locp = LOC(lang, mkname("spellpar", substr)); syntaxp = substr + 1; } - bytes = (int)snprintf(bufp, size, " <%s>", locp); + bytes = (int)_snprintf(bufp, size, " <%s>", locp); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -939,11 +939,11 @@ static void describe(FILE * F, const seen_region * sr, faction * f) WARN_STATIC_BUFFER(); if (sr->mode == see_travel) { - bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_travel")); + bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_travel")); } else if (sr->mode == see_neighbour) { - bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_neighbour")); + bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_neighbour")); } else if (sr->mode == see_lighthouse) { - bytes = snprintf(bufp, size, " (%s)", LOC(f->locale, "see_lighthouse")); + bytes = _snprintf(bufp, size, " (%s)", LOC(f->locale, "see_lighthouse")); } else { bytes = 0; } @@ -965,7 +965,7 @@ static void describe(FILE * F, const seen_region * sr, faction * f) saplings = rtrees(r, 1); if (production(r)) { if (trees > 0 || saplings > 0) { - bytes = snprintf(bufp, size, ", %d/%d ", trees, saplings); + bytes = _snprintf(bufp, size, ", %d/%d ", trees, saplings); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -992,7 +992,7 @@ static void describe(FILE * F, const seen_region * sr, faction * f) for (n = 0; n < numresults; ++n) { if (result[n].number >= 0 && result[n].level >= 0) { - bytes = snprintf(bufp, size, ", %d %s/%d", result[n].number, + bytes = _snprintf(bufp, size, ", %d %s/%d", result[n].number, LOC(f->locale, result[n].name), result[n].level); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1003,14 +1003,14 @@ static void describe(FILE * F, const seen_region * sr, faction * f) /* peasants & silver */ if (rpeasants(r)) { int n = rpeasants(r); - bytes = snprintf(bufp, size, ", %d", n); + bytes = _snprintf(bufp, size, ", %d", n); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); if (r->land->ownership) { const char *str = locale_string(f->locale, mkname("morale", itoa10(r->land->morale))); - bytes = snprintf(bufp, size, " %s", str); + bytes = _snprintf(bufp, size, " %s", str); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -1039,7 +1039,7 @@ static void describe(FILE * F, const seen_region * sr, faction * f) } } if (rmoney(r) && sr->mode >= see_travel) { - bytes = snprintf(bufp, size, ", %d ", rmoney(r)); + bytes = _snprintf(bufp, size, ", %d ", rmoney(r)); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); bytes = @@ -1051,7 +1051,7 @@ static void describe(FILE * F, const seen_region * sr, faction * f) /* Pferde */ if (rhorses(r)) { - bytes = snprintf(bufp, size, ", %d ", rhorses(r)); + bytes = _snprintf(bufp, size, ", %d ", rhorses(r)); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); bytes = @@ -1083,7 +1083,7 @@ static void describe(FILE * F, const seen_region * sr, faction * f) if (rule_region_owners()) { const faction *owner = region_get_owner(r); if (owner != NULL) { - bytes = snprintf(bufp, size, " Die Region ist im Besitz von %s.", + bytes = _snprintf(bufp, size, " Die Region ist im Besitz von %s.", factionname(owner)); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1134,7 +1134,7 @@ static void describe(FILE * F, const seen_region * sr, faction * f) if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); f_regionid(r2, f, regname, sizeof(regname)); - bytes = snprintf(bufp, size, trailinto(r2, f->locale), regname); + bytes = _snprintf(bufp, size, trailinto(r2, f->locale), regname); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } else { @@ -1431,9 +1431,9 @@ static void durchreisende(FILE * F, const region * r, const faction * f) } /* TODO: finish localization */ if (maxtravel == 1) { - bytes = snprintf(bufp, size, " %s", LOC(f->locale, "has_moved_one")); + bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "has_moved_one")); } else { - bytes = snprintf(bufp, size, " %s", LOC(f->locale, "has_moved_many")); + bytes = _snprintf(bufp, size, " %s", LOC(f->locale, "has_moved_many")); } if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1552,7 +1552,7 @@ report_template(const char *filename, report_context * ctx, const char *charset) bufp = buf; size = sizeof(buf) - 1; - bytes = snprintf(bufp, size, "%s %s; %s [%d,%d$", + bytes = _snprintf(bufp, size, "%s %s; %s [%d,%d$", LOC(u->faction->locale, parameters[P_UNIT]), unitid(u), u->name, u->number, get_money(u)); if (wrptr(&bufp, &size, bytes) != 0) @@ -1726,9 +1726,9 @@ static void allies(FILE * F, const faction * f) int bytes; size_t size = sizeof(buf); if (!f->allies->next) { - bytes = snprintf(buf, size, "%s ", LOC(f->locale, "faction_help_one")); + bytes = _snprintf(buf, size, "%s ", LOC(f->locale, "faction_help_one")); } else { - bytes = snprintf(buf, size, "%s ", LOC(f->locale, "faction_help_many")); + bytes = _snprintf(buf, size, "%s ", LOC(f->locale, "faction_help_many")); } size -= bytes; show_allies(f, f->allies, buf + bytes, size); @@ -1741,9 +1741,9 @@ static void allies(FILE * F, const faction * f) int bytes; size_t size = sizeof(buf); if (!g->allies->next) { - bytes = snprintf(buf, size, "%s %s ", g->name, LOC(f->locale, "group_help_one")); + bytes = _snprintf(buf, size, "%s %s ", g->name, LOC(f->locale, "group_help_one")); } else { - bytes = snprintf(buf, size, "%s %s ", g->name, LOC(f->locale, "group_help_many")); + bytes = _snprintf(buf, size, "%s %s ", g->name, LOC(f->locale, "group_help_many")); } size -= bytes; show_allies(f, g->allies, buf + bytes, size); @@ -1886,11 +1886,11 @@ nr_ship(FILE * F, const seen_region * sr, const ship * sh, const faction * f, getshipweight(sh, &n, &p); n = (n + 99) / 100; /* 1 Silber = 1 GE */ - bytes = snprintf(bufp, size, "%s, %s, (%d/%d)", shipname(sh), + bytes = _snprintf(bufp, size, "%s, %s, (%d/%d)", shipname(sh), LOC(f->locale, sh->type->name[0]), n, shipcapacity(sh) / 100); } else { bytes = - snprintf(bufp, size, "%s, %s", shipname(sh), LOC(f->locale, + _snprintf(bufp, size, "%s, %s", shipname(sh), LOC(f->locale, sh->type->name[0])); } if (wrptr(&bufp, &size, bytes) != 0) @@ -1898,7 +1898,7 @@ nr_ship(FILE * F, const seen_region * sr, const ship * sh, const faction * f, assert(sh->type->construction->improvement == NULL); /* sonst ist construction::size nicht ship_type::maxsize */ if (sh->size != sh->type->construction->maxsize) { - bytes = snprintf(bufp, size, ", %s (%d/%d)", + bytes = _snprintf(bufp, size, ", %s (%d/%d)", LOC(f->locale, "nr_undercons"), sh->size, sh->type->construction->maxsize); if (wrptr(&bufp, &size, bytes) != 0) @@ -1908,7 +1908,7 @@ nr_ship(FILE * F, const seen_region * sr, const ship * sh, const faction * f, int percent = (sh->damage * 100 + DAMAGE_SCALE - 1) / (sh->size * DAMAGE_SCALE); bytes = - snprintf(bufp, size, ", %d%% %s", percent, LOC(f->locale, "nr_damaged")); + _snprintf(bufp, size, ", %d%% %s", percent, LOC(f->locale, "nr_damaged")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -1959,7 +1959,7 @@ nr_building(FILE * F, const seen_region * sr, const building * b, lang = f->locale; bytes = - snprintf(bufp, size, "%s, %s %d, ", buildingname(b), LOC(f->locale, + _snprintf(bufp, size, "%s, %s %d, ", buildingname(b), LOC(f->locale, "nr_size"), b->size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); @@ -1974,7 +1974,7 @@ nr_building(FILE * F, const seen_region * sr, const building * b, if (owner && owner->faction == f) { /* illusion. report real type */ name = LOC(lang, bname); - bytes = snprintf(bufp, size, " (%s)", name); + bytes = _snprintf(bufp, size, " (%s)", name); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); } @@ -2264,7 +2264,7 @@ report_plaintext(const char *filename, report_context * ctx, bufp = buf; size = sizeof(buf) - 1; - bytes = snprintf(buf, size, "%s:", LOC(f->locale, "nr_options")); + bytes = _snprintf(buf, size, "%s:", LOC(f->locale, "nr_options")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); for (op = 0; op != MAXOPTIONS; op++) { @@ -2315,14 +2315,14 @@ report_plaintext(const char *filename, report_context * ctx, rnl(F); centre(F, LOC(f->locale, pname), true); - snprintf(buf, sizeof(buf), "%s %d", LOC(f->locale, "nr_level"), + _snprintf(buf, sizeof(buf), "%s %d", LOC(f->locale, "nr_level"), ptype->level); centre(F, buf, true); rnl(F); bufp = buf; size = sizeof(buf) - 1; - bytes = snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_herbsrequired")); + bytes = _snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_herbsrequired")); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); diff --git a/src/spells/spells.c b/src/spells/spells.c index d52808f19..a5d56823a 100644 --- a/src/spells/spells.c +++ b/src/spells/spells.c @@ -4671,7 +4671,7 @@ int sp_clonecopy(castorder * co) return 0; } - snprintf(name, sizeof(name), (const char *)LOC(mage->faction->locale, + _snprintf(name, sizeof(name), (const char *)LOC(mage->faction->locale, "clone_of"), unitname(mage)); clone = create_unit(target_region, mage->faction, 1, new_race[RC_CLONE], 0, name, diff --git a/src/util/bsdstring.c b/src/util/bsdstring.c index 255e9f10d..0f8b60ffe 100644 --- a/src/util/bsdstring.c +++ b/src/util/bsdstring.c @@ -9,7 +9,7 @@ int wrptr(char **ptr, size_t * size, int bytes) { - assert(bytes >= 0 || !"you're not using snprintf right, maybe?"); + assert(bytes >= 0 || !"you're not using _snprintf right, maybe?"); if (bytes == 0) { return 0; diff --git a/src/util/log.c b/src/util/log.c index 0c14a6bd7..cf01698c7 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -75,17 +75,17 @@ cp_convert(const char *format, char *buffer, size_t length, int codepage) void log_rotate(const char *filename, int maxindex) { int n; - if (access(filename, R_OK)==0) { + if (_access(filename, _A_RDONLY)==0) { char buffer[2][MAX_PATH]; int src = 1; assert(strlen(filename)no); + _snprintf(idbuf, sizeof(idbuf), "unit_%d", u->no); return (const xmlChar *)idbuf; } static const xmlChar *xml_ref_faction(const faction * f) { static char idbuf[20]; - snprintf(idbuf, sizeof(idbuf), "fctn_%d", f->no); + _snprintf(idbuf, sizeof(idbuf), "fctn_%d", f->no); return (const xmlChar *)idbuf; } static const xmlChar *xml_ref_group(const group * g) { static char idbuf[20]; - snprintf(idbuf, sizeof(idbuf), "grp_%d", g->gid); + _snprintf(idbuf, sizeof(idbuf), "grp_%d", g->gid); return (const xmlChar *)idbuf; } static const xmlChar *xml_ref_prefix(const char *str) { static char idbuf[20]; - snprintf(idbuf, sizeof(idbuf), "pref_%s", str); + _snprintf(idbuf, sizeof(idbuf), "pref_%s", str); return (const xmlChar *)idbuf; } static const xmlChar *xml_ref_building(const building * b) { static char idbuf[20]; - snprintf(idbuf, sizeof(idbuf), "bldg_%d", b->no); + _snprintf(idbuf, sizeof(idbuf), "bldg_%d", b->no); return (const xmlChar *)idbuf; } static const xmlChar *xml_ref_ship(const ship * sh) { static char idbuf[20]; - snprintf(idbuf, sizeof(idbuf), "shp_%d", sh->no); + _snprintf(idbuf, sizeof(idbuf), "shp_%d", sh->no); return (const xmlChar *)idbuf; } static const xmlChar *xml_ref_region(const region * r) { static char idbuf[20]; - snprintf(idbuf, sizeof(idbuf), "rgn_%d", r->uid); + _snprintf(idbuf, sizeof(idbuf), "rgn_%d", r->uid); return (const xmlChar *)idbuf; } @@ -736,7 +736,7 @@ static xmlNodePtr report_root(report_context * ctx) node = xmlAddChild(xmlReport, xmlNewNode(xct->ns_atl, BAD_CAST "server")); if (mailto) { - snprintf(zText, sizeof(zText), "mailto:%s?subject=%s", mailto, mailcmd); + _snprintf(zText, sizeof(zText), "mailto:%s?subject=%s", mailto, mailcmd); child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "delivery")); xmlNewNsProp(child, xct->ns_atl, BAD_CAST "method", BAD_CAST "mail"); xmlNewNsProp(child, xct->ns_atl, BAD_CAST "href", BAD_CAST zText);