forked from github/server
PATH_MAX and MAX_PATH are crazy.
This commit is contained in:
parent
f98eab56c4
commit
50173d5be3
19 changed files with 99 additions and 65 deletions
|
@ -7,9 +7,11 @@
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include <kernel/jsonconf.h>
|
#include <kernel/jsonconf.h>
|
||||||
#include <util/bsdstring.h>
|
#include <util/bsdstring.h>
|
||||||
#include <util/nrmessage.h>
|
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
|
#include <util/nrmessage.h>
|
||||||
|
#include <util/path.h>
|
||||||
|
|
||||||
#include <cJSON.h>
|
#include <cJSON.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -58,12 +60,12 @@ int config_parse(const char *json)
|
||||||
|
|
||||||
int config_read(const char *filename, const char * relpath)
|
int config_read(const char *filename, const char * relpath)
|
||||||
{
|
{
|
||||||
char name[MAX_PATH];
|
char name[PATH_MAX];
|
||||||
FILE *F;
|
FILE *F;
|
||||||
|
|
||||||
json_relpath = relpath;
|
json_relpath = relpath;
|
||||||
if (relpath) {
|
if (relpath) {
|
||||||
join_path(relpath, filename, name, sizeof(name));
|
path_join(relpath, filename, name, sizeof(name));
|
||||||
F = fopen(name, "r");
|
F = fopen(name, "r");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
#include <util/lists.h>
|
#include <util/lists.h>
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
#include <util/macros.h>
|
#include <util/macros.h>
|
||||||
|
#include <util/path.h>
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
#include <util/unicode.h>
|
#include <util/unicode.h>
|
||||||
|
|
||||||
|
@ -879,7 +880,7 @@ static void select_regions(state * st, int selectmode)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loaddata(state *st) {
|
static void loaddata(state *st) {
|
||||||
char datafile[MAX_PATH];
|
char datafile[PATH_MAX];
|
||||||
|
|
||||||
askstring(st->wnd_status->handle, "load from:", datafile, sizeof(datafile));
|
askstring(st->wnd_status->handle, "load from:", datafile, sizeof(datafile));
|
||||||
if (strlen(datafile) > 0) {
|
if (strlen(datafile) > 0) {
|
||||||
|
@ -889,7 +890,7 @@ static void loaddata(state *st) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void savedata(state *st) {
|
static void savedata(state *st) {
|
||||||
char datafile[MAX_PATH];
|
char datafile[PATH_MAX];
|
||||||
|
|
||||||
askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile));
|
askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile));
|
||||||
if (strlen(datafile) > 0) {
|
if (strlen(datafile) > 0) {
|
||||||
|
@ -1391,7 +1392,7 @@ void run_mapper(void)
|
||||||
char sbuffer[512];
|
char sbuffer[512];
|
||||||
|
|
||||||
if (!new_players) {
|
if (!new_players) {
|
||||||
join_path(basepath(), "newfactions", sbuffer, sizeof(sbuffer));
|
path_join(basepath(), "newfactions", sbuffer, sizeof(sbuffer));
|
||||||
new_players = read_newfactions(sbuffer);
|
new_players = read_newfactions(sbuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
#include "items.h"
|
#include "items.h"
|
||||||
|
|
||||||
#include "alchemy.h"
|
#include "alchemy.h"
|
||||||
|
#include "skill.h"
|
||||||
|
#include "keyword.h"
|
||||||
|
#include "direction.h"
|
||||||
#include "study.h"
|
#include "study.h"
|
||||||
#include "economy.h"
|
#include "economy.h"
|
||||||
#include "move.h"
|
|
||||||
#include "magic.h"
|
#include "magic.h"
|
||||||
|
|
||||||
#include <attributes/fleechance.h>
|
#include <attributes/fleechance.h>
|
||||||
|
@ -14,17 +16,16 @@
|
||||||
#include <spells/regioncurse.h>
|
#include <spells/regioncurse.h>
|
||||||
|
|
||||||
#include <kernel/curse.h>
|
#include <kernel/curse.h>
|
||||||
#include <kernel/building.h>
|
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
#include <kernel/item.h>
|
#include <kernel/item.h>
|
||||||
#include <kernel/messages.h>
|
#include <kernel/messages.h>
|
||||||
#include <kernel/order.h>
|
#include <kernel/order.h>
|
||||||
#include <kernel/plane.h>
|
|
||||||
#include <kernel/pool.h>
|
#include <kernel/pool.h>
|
||||||
#include <kernel/race.h>
|
#include <kernel/race.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
#include <kernel/ship.h>
|
#include <kernel/ship.h>
|
||||||
#include <kernel/spell.h>
|
#include <kernel/spell.h>
|
||||||
|
#include <kernel/skills.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
|
||||||
/* triggers includes */
|
/* triggers includes */
|
||||||
|
@ -33,13 +34,13 @@
|
||||||
|
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
#include <util/event.h>
|
#include <util/event.h>
|
||||||
#include <util/log.h>
|
|
||||||
#include <util/macros.h>
|
#include <util/macros.h>
|
||||||
#include <util/parser.h>
|
#include <util/parser.h>
|
||||||
#include <util/rand.h>
|
#include <util/rand.h>
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stddef.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
/* BEGIN studypotion */
|
/* BEGIN studypotion */
|
||||||
|
|
|
@ -63,6 +63,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/lists.h>
|
#include <util/lists.h>
|
||||||
#include <util/macros.h>
|
#include <util/macros.h>
|
||||||
#include <util/parser.h>
|
#include <util/parser.h>
|
||||||
|
#include <util/path.h>
|
||||||
#include <util/rand.h>
|
#include <util/rand.h>
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
#include <util/strings.h>
|
#include <util/strings.h>
|
||||||
|
@ -520,31 +521,13 @@ void set_basepath(const char *path)
|
||||||
g_basedir = path;
|
g_basedir = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#define PATH_DELIM '\\'
|
|
||||||
#else
|
|
||||||
#define PATH_DELIM '/'
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char * join_path(const char *p1, const char *p2, char *dst, size_t len) {
|
char * join_path(const char *p1, const char *p2, char *dst, size_t len) {
|
||||||
size_t sz;
|
return path_join(p1, p2, dst, len);
|
||||||
assert(p1 && p2);
|
|
||||||
assert(p2 != dst);
|
|
||||||
if (dst == p1) {
|
|
||||||
sz = strlen(p1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sz = strlcpy(dst, p1, len);
|
|
||||||
}
|
|
||||||
assert(sz < len);
|
|
||||||
dst[sz++] = PATH_DELIM;
|
|
||||||
strlcpy(dst + sz, p2, len - sz);
|
|
||||||
return dst;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char * relpath(char *buf, size_t sz, const char *path) {
|
static const char * relpath(char *buf, size_t sz, const char *path) {
|
||||||
if (g_basedir) {
|
if (g_basedir) {
|
||||||
join_path(g_basedir, path, buf, sz);
|
path_join(g_basedir, path, buf, sz);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
strlcpy(buf, path, sz);
|
strlcpy(buf, path, sz);
|
||||||
|
|
|
@ -48,6 +48,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
#include <util/parser.h>
|
#include <util/parser.h>
|
||||||
#include <util/password.h>
|
#include <util/password.h>
|
||||||
|
#include <util/path.h>
|
||||||
#include <util/resolve.h>
|
#include <util/resolve.h>
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
#include <util/strings.h>
|
#include <util/strings.h>
|
||||||
|
@ -854,7 +855,7 @@ int writepasswd(void)
|
||||||
FILE *F;
|
FILE *F;
|
||||||
char zText[128];
|
char zText[128];
|
||||||
|
|
||||||
join_path(basepath(), "passwd", zText, sizeof(zText));
|
path_join(basepath(), "passwd", zText, sizeof(zText));
|
||||||
F = fopen(zText, "w");
|
F = fopen(zText, "w");
|
||||||
if (!F) {
|
if (!F) {
|
||||||
perror(zText);
|
perror(zText);
|
||||||
|
|
|
@ -45,6 +45,7 @@ without prior permission by the authors of Eressea.
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
#include <util/message.h>
|
#include <util/message.h>
|
||||||
#include <util/nrmessage.h>
|
#include <util/nrmessage.h>
|
||||||
|
#include <util/path.h>
|
||||||
#include <util/strings.h>
|
#include <util/strings.h>
|
||||||
#include <util/xml.h>
|
#include <util/xml.h>
|
||||||
|
|
||||||
|
@ -897,8 +898,8 @@ static void json_include(cJSON *json) {
|
||||||
for (child = json->child; child; child = child->next) {
|
for (child = json->child; child; child = child->next) {
|
||||||
FILE *F;
|
FILE *F;
|
||||||
if (json_relpath) {
|
if (json_relpath) {
|
||||||
char name[MAX_PATH];
|
char name[PATH_MAX];
|
||||||
join_path(json_relpath, child->valuestring, name, sizeof(name));
|
path_join(json_relpath, child->valuestring, name, sizeof(name));
|
||||||
F = fopen(name, "r");
|
F = fopen(name, "r");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -70,6 +70,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
#include <util/parser.h>
|
#include <util/parser.h>
|
||||||
#include <util/password.h>
|
#include <util/password.h>
|
||||||
|
#include <util/path.h>
|
||||||
#include <util/rand.h>
|
#include <util/rand.h>
|
||||||
#include <util/resolve.h>
|
#include <util/resolve.h>
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
|
@ -292,11 +293,11 @@ static void write_owner(gamedata *data, region_owner * owner)
|
||||||
|
|
||||||
int current_turn(void)
|
int current_turn(void)
|
||||||
{
|
{
|
||||||
char zText[MAX_PATH];
|
char zText[PATH_MAX];
|
||||||
int cturn = 0;
|
int cturn = 0;
|
||||||
FILE *F;
|
FILE *F;
|
||||||
|
|
||||||
join_path(basepath(), "turn", zText, sizeof(zText));
|
path_join(basepath(), "turn", zText, sizeof(zText));
|
||||||
F = fopen(zText, "r");
|
F = fopen(zText, "r");
|
||||||
if (!F) {
|
if (!F) {
|
||||||
perror(zText);
|
perror(zText);
|
||||||
|
@ -1151,7 +1152,7 @@ static int cb_sb_maxlevel(spellbook_entry *sbe, void *cbdata) {
|
||||||
int readgame(const char *filename)
|
int readgame(const char *filename)
|
||||||
{
|
{
|
||||||
int n, stream_version;
|
int n, stream_version;
|
||||||
char path[MAX_PATH];
|
char path[PATH_MAX];
|
||||||
gamedata gdata = { 0 };
|
gamedata gdata = { 0 };
|
||||||
storage store;
|
storage store;
|
||||||
stream strm;
|
stream strm;
|
||||||
|
@ -1159,7 +1160,7 @@ int readgame(const char *filename)
|
||||||
size_t sz;
|
size_t sz;
|
||||||
|
|
||||||
log_debug("- reading game data from %s", filename);
|
log_debug("- reading game data from %s", filename);
|
||||||
join_path(datapath(), filename, path, sizeof(path));
|
path_join(datapath(), filename, path, sizeof(path));
|
||||||
|
|
||||||
F = fopen(path, "rb");
|
F = fopen(path, "rb");
|
||||||
if (!F) {
|
if (!F) {
|
||||||
|
@ -1562,14 +1563,14 @@ static void clear_npc_orders(faction *f)
|
||||||
int writegame(const char *filename)
|
int writegame(const char *filename)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
char path[MAX_PATH];
|
char path[PATH_MAX];
|
||||||
gamedata gdata;
|
gamedata gdata;
|
||||||
storage store;
|
storage store;
|
||||||
stream strm;
|
stream strm;
|
||||||
FILE *F;
|
FILE *F;
|
||||||
|
|
||||||
create_directories();
|
create_directories();
|
||||||
join_path(datapath(), filename, path, sizeof(path));
|
path_join(datapath(), filename, path, sizeof(path));
|
||||||
/* make sure we don't overwrite an existing file (hard links) */
|
/* make sure we don't overwrite an existing file (hard links) */
|
||||||
if (remove(path) != 0) {
|
if (remove(path) != 0) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <util/event.h>
|
#include <util/event.h>
|
||||||
#include <util/gamedata.h>
|
#include <util/gamedata.h>
|
||||||
#include <util/password.h>
|
#include <util/password.h>
|
||||||
|
#include <util/path.h>
|
||||||
#include <util/strings.h>
|
#include <util/strings.h>
|
||||||
|
|
||||||
#include <storage.h>
|
#include <storage.h>
|
||||||
|
@ -36,11 +37,11 @@
|
||||||
static void test_readwrite_data(CuTest * tc)
|
static void test_readwrite_data(CuTest * tc)
|
||||||
{
|
{
|
||||||
const char *filename = "test.dat";
|
const char *filename = "test.dat";
|
||||||
char path[MAX_PATH];
|
char path[PATH_MAX];
|
||||||
test_setup();
|
test_setup();
|
||||||
CuAssertIntEquals(tc, 0, writegame(filename));
|
CuAssertIntEquals(tc, 0, writegame(filename));
|
||||||
CuAssertIntEquals(tc, 0, readgame(filename));
|
CuAssertIntEquals(tc, 0, readgame(filename));
|
||||||
join_path(datapath(), filename, path, sizeof(path));
|
path_join(datapath(), filename, path, sizeof(path));
|
||||||
CuAssertIntEquals(tc, 0, remove(path));
|
CuAssertIntEquals(tc, 0, remove(path));
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,6 +89,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/message.h>
|
#include <util/message.h>
|
||||||
#include <util/parser.h>
|
#include <util/parser.h>
|
||||||
#include <util/password.h>
|
#include <util/password.h>
|
||||||
|
#include <util/path.h>
|
||||||
#include <util/rand.h>
|
#include <util/rand.h>
|
||||||
#include <util/rng.h>
|
#include <util/rng.h>
|
||||||
#include <util/strings.h>
|
#include <util/strings.h>
|
||||||
|
@ -4260,7 +4261,7 @@ void update_subscriptions(void)
|
||||||
FILE *F;
|
FILE *F;
|
||||||
char zText[4096];
|
char zText[4096];
|
||||||
|
|
||||||
join_path(basepath(), "subscriptions", zText, sizeof(zText));
|
path_join(basepath(), "subscriptions", zText, sizeof(zText));
|
||||||
F = fopen(zText, "r");
|
F = fopen(zText, "r");
|
||||||
if (F == NULL) {
|
if (F == NULL) {
|
||||||
log_warning(0, "could not open %s.\n", zText);
|
log_warning(0, "could not open %s.\n", zText);
|
||||||
|
|
11
src/main.c
11
src/main.c
|
@ -20,14 +20,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <util/log.h>
|
|
||||||
|
|
||||||
#include <kernel/config.h>
|
#include <kernel/config.h>
|
||||||
#include <kernel/database.h>
|
#include <kernel/database.h>
|
||||||
#include <kernel/version.h>
|
#include <kernel/version.h>
|
||||||
#include <kernel/save.h>
|
#include <kernel/save.h>
|
||||||
|
|
||||||
#include <util/filereader.h>
|
#include <util/filereader.h>
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
|
#include <util/log.h>
|
||||||
|
#include <util/macros.h>
|
||||||
|
#include <util/path.h>
|
||||||
|
|
||||||
#include "eressea.h"
|
#include "eressea.h"
|
||||||
#ifdef USE_CURSES
|
#ifdef USE_CURSES
|
||||||
#include "gmtool.h"
|
#include "gmtool.h"
|
||||||
|
@ -98,12 +101,12 @@ static const char * valid_keys[] = {
|
||||||
|
|
||||||
static dictionary *parse_config(const char *filename)
|
static dictionary *parse_config(const char *filename)
|
||||||
{
|
{
|
||||||
char path[MAX_PATH];
|
char path[PATH_MAX];
|
||||||
dictionary *d;
|
dictionary *d;
|
||||||
const char *str, *cfgpath = config_get("config.path");
|
const char *str, *cfgpath = config_get("config.path");
|
||||||
|
|
||||||
if (cfgpath) {
|
if (cfgpath) {
|
||||||
join_path(cfgpath, filename, path, sizeof(path));
|
path_join(cfgpath, filename, path, sizeof(path));
|
||||||
log_debug("reading from configuration file %s\n", path);
|
log_debug("reading from configuration file %s\n", path);
|
||||||
d = iniparser_load(path);
|
d = iniparser_load(path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
|
#include <util/path.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -152,7 +153,7 @@ void score(void)
|
||||||
allscores = 1;
|
allscores = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
join_path(basepath(), "score", path, sizeof(path));
|
path_join(basepath(), "score", path, sizeof(path));
|
||||||
scoreFP = fopen(path, "w");
|
scoreFP = fopen(path, "w");
|
||||||
if (scoreFP) {
|
if (scoreFP) {
|
||||||
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
|
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
|
||||||
|
@ -177,7 +178,7 @@ void score(void)
|
||||||
alliance *a;
|
alliance *a;
|
||||||
const item_type *token = it_find("conquesttoken");
|
const item_type *token = it_find("conquesttoken");
|
||||||
|
|
||||||
join_path(basepath(), "score.alliances", path, sizeof(path));
|
path_join(basepath(), "score.alliances", path, sizeof(path));
|
||||||
scoreFP = fopen(path, "w");
|
scoreFP = fopen(path, "w");
|
||||||
if (scoreFP) {
|
if (scoreFP) {
|
||||||
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
|
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|
||||||
|
/* @see https://developercommunity.visualstudio.com/content/problem/69874/warning-c4001-in-standard-library-stringh-header.html */
|
||||||
#if _MSC_VER >= 1900
|
#if _MSC_VER >= 1900
|
||||||
#pragma warning(disable: 4710 4820 4001)
|
#pragma warning(disable: 4710 4820 4001)
|
||||||
#pragma warning(disable: 4100) // unreferenced formal parameter
|
#pragma warning(disable: 4100) // unreferenced formal parameter
|
||||||
|
@ -13,6 +15,10 @@
|
||||||
#pragma warning(disable: 4459) // declaration hides global
|
#pragma warning(disable: 4459) // declaration hides global
|
||||||
#pragma warning(disable: 4224) // formal parameter was previously defined as a type
|
#pragma warning(disable: 4224) // formal parameter was previously defined as a type
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* @see https://insanecoding.blogspot.no/2007/11/pathmax-simply-isnt.html */
|
||||||
|
#define PATH_MAX 260
|
||||||
|
|
||||||
#else /* assume gcc */
|
#else /* assume gcc */
|
||||||
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
|
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
|
||||||
# define va_copy(a,b) __va_copy(a,b)
|
# define va_copy(a,b) __va_copy(a,b)
|
||||||
|
@ -20,13 +26,5 @@
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* #define _POSIX_C_SOURCE 200809L
|
|
||||||
*/
|
|
||||||
#ifndef MAX_PATH
|
|
||||||
# define MAX_PATH 4096
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||||
|
|
||||||
#define TOLUA_CAST (char*)
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <util/lists.h>
|
#include <util/lists.h>
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
#include <util/macros.h>
|
#include <util/macros.h>
|
||||||
|
#include <util/path.h>
|
||||||
#include <util/strings.h>
|
#include <util/strings.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <stream.h>
|
#include <stream.h>
|
||||||
|
@ -1567,7 +1568,7 @@ int write_reports(faction * f, time_t ltime)
|
||||||
char path[4096];
|
char path[4096];
|
||||||
sprintf(filename, "%d-%s.%s", turn, itoa36(f->no),
|
sprintf(filename, "%d-%s.%s", turn, itoa36(f->no),
|
||||||
rtype->extension);
|
rtype->extension);
|
||||||
join_path(reportpath(), filename, path, sizeof(path));
|
path_join(reportpath(), filename, path, sizeof(path));
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (rtype->write(path, &ctx, (const char *)utf8_bom) == 0) {
|
if (rtype->write(path, &ctx, (const char *)utf8_bom) == 0) {
|
||||||
gotit = true;
|
gotit = true;
|
||||||
|
@ -1645,7 +1646,7 @@ int reports(void)
|
||||||
report_donations();
|
report_donations();
|
||||||
remove_empty_units();
|
remove_empty_units();
|
||||||
|
|
||||||
join_path(rpath, "reports.txt", path, sizeof(path));
|
path_join(rpath, "reports.txt", path, sizeof(path));
|
||||||
mailit = fopen(path, "w");
|
mailit = fopen(path, "w");
|
||||||
if (mailit == NULL) {
|
if (mailit == NULL) {
|
||||||
log_error("%s could not be opened!\n", path);
|
log_error("%s could not be opened!\n", path);
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <util/language.h>
|
#include <util/language.h>
|
||||||
#include <util/lists.h>
|
#include <util/lists.h>
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
|
#include <util/path.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -165,7 +166,7 @@ static void writeturn(void)
|
||||||
char zText[4096];
|
char zText[4096];
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
join_path(basepath(), "datum", zText, sizeof(zText));
|
path_join(basepath(), "datum", zText, sizeof(zText));
|
||||||
f = fopen(zText, "w");
|
f = fopen(zText, "w");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
perror(zText);
|
perror(zText);
|
||||||
|
@ -173,7 +174,7 @@ static void writeturn(void)
|
||||||
}
|
}
|
||||||
fputs(gamedate2(default_locale), f);
|
fputs(gamedate2(default_locale), f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
join_path(basepath(), "turn", zText, sizeof(zText));
|
path_join(basepath(), "turn", zText, sizeof(zText));
|
||||||
f = fopen(zText, "w");
|
f = fopen(zText, "w");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
perror(zText);
|
perror(zText);
|
||||||
|
@ -192,10 +193,10 @@ void report_summary(summary * s, summary * o, bool full)
|
||||||
int timeout = NMRTimeout();
|
int timeout = NMRTimeout();
|
||||||
|
|
||||||
if (full) {
|
if (full) {
|
||||||
join_path(basepath(), "parteien.full", zText, sizeof(zText));
|
path_join(basepath(), "parteien.full", zText, sizeof(zText));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
join_path(basepath(), "parteien", zText, sizeof(zText));
|
path_join(basepath(), "parteien", zText, sizeof(zText));
|
||||||
}
|
}
|
||||||
F = fopen(zText, "w");
|
F = fopen(zText, "w");
|
||||||
if (!F) {
|
if (!F) {
|
||||||
|
|
|
@ -50,6 +50,7 @@ mt19937ar.c
|
||||||
nrmessage.c
|
nrmessage.c
|
||||||
parser.c
|
parser.c
|
||||||
password.c
|
password.c
|
||||||
|
path.c
|
||||||
rand.c
|
rand.c
|
||||||
resolve.c
|
resolve.c
|
||||||
strings.c
|
strings.c
|
||||||
|
|
|
@ -10,8 +10,10 @@ This program may not be used, modified or distributed
|
||||||
without prior permission by the authors of Eressea.
|
without prior permission by the authors of Eressea.
|
||||||
*/
|
*/
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include "log.h"
|
|
||||||
#include "bsdstring.h"
|
#include "bsdstring.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "path.h"
|
||||||
#include "unicode.h"
|
#include "unicode.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -92,7 +94,7 @@ cp_convert(const char *format, unsigned char *buffer, size_t length, int codepag
|
||||||
|
|
||||||
void log_rotate(const char *filename, int maxindex)
|
void log_rotate(const char *filename, int maxindex)
|
||||||
{
|
{
|
||||||
char buffer[2][MAX_PATH];
|
char buffer[2][PATH_MAX];
|
||||||
int dst = 1;
|
int dst = 1;
|
||||||
assert(strlen(filename) < sizeof(buffer[0]) - 4);
|
assert(strlen(filename) < sizeof(buffer[0]) - 4);
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
#define UNUSED_ARG(x) (void)(x)
|
#define UNUSED_ARG(x) (void)(x)
|
||||||
#define TOLUA_CAST (char*)
|
#define TOLUA_CAST (char*)
|
||||||
|
|
||||||
|
|
26
src/util/path.c
Normal file
26
src/util/path.c
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#include <platform.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "path.h"
|
||||||
|
#include "bsdstring.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char * path_join(const char *p1, const char *p2, char *dst, size_t len) {
|
||||||
|
size_t sz;
|
||||||
|
assert(p1 && p2);
|
||||||
|
assert(p2 != dst);
|
||||||
|
if (dst == p1) {
|
||||||
|
sz = strlen(p1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sz = strlcpy(dst, p1, len);
|
||||||
|
}
|
||||||
|
assert(sz < len);
|
||||||
|
dst[sz++] = PATH_DELIM;
|
||||||
|
strlcpy(dst + sz, p2, len - sz);
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
10
src/util/path.h
Normal file
10
src/util/path.h
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define PATH_DELIM '\\'
|
||||||
|
#else
|
||||||
|
#define PATH_DELIM '/'
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char * path_join(const char *p1, const char *p2, char *dst, size_t len);
|
Loading…
Reference in a new issue