adding a join_path function to try and narrow down misbehavior.

This commit is contained in:
Enno Rehling 2016-01-29 19:11:48 +01:00
parent 9bf1059d8a
commit 73f16d5bb6
3 changed files with 20 additions and 8 deletions

View File

@ -653,15 +653,26 @@ void set_basepath(const char *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) {
size_t sz;
assert(p1 && p2);
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) {
if (g_basedir) {
strlcpy(buf, g_basedir, sz);
#ifdef WIN32
strlcat(buf, "\\", sz);
#else
strlcat(buf, "/", sz);
#endif
strlcat(buf, path, sz);
join_path(g_basedir, path, buf, sz);
}
else {
strlcpy(buf, path, sz);

View File

@ -185,6 +185,7 @@ struct param;
double config_get_flt(const char *key, double def);
bool config_token(const char *key, const char *tok);
char * join_path(const char *p1, const char *p2, char *dst, size_t len);
bool ExpensiveMigrants(void);
int NMRTimeout(void);
int LongHunger(const struct unit *u);

View File

@ -40,7 +40,7 @@ static void test_readwrite_unit(CuTest * tc)
fno = f->no;
u = test_create_unit(f, r);
_mkdir(datapath());
sprintf(path, "%s/%s", datapath(), filename);
join_path(datapath(), filename, path, sizeof(path));
data = gamedata_open(path, "wb");
CuAssertPtrNotNull(tc, data); // TODO: intermittent test