forked from github/server
adding a join_path function to try and narrow down misbehavior.
This commit is contained in:
parent
9bf1059d8a
commit
73f16d5bb6
|
@ -653,15 +653,26 @@ 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) {
|
||||||
|
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) {
|
static const char * relpath(char *buf, size_t sz, const char *path) {
|
||||||
if (g_basedir) {
|
if (g_basedir) {
|
||||||
strlcpy(buf, g_basedir, sz);
|
join_path(g_basedir, path, buf, sz);
|
||||||
#ifdef WIN32
|
|
||||||
strlcat(buf, "\\", sz);
|
|
||||||
#else
|
|
||||||
strlcat(buf, "/", sz);
|
|
||||||
#endif
|
|
||||||
strlcat(buf, path, sz);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
strlcpy(buf, path, sz);
|
strlcpy(buf, path, sz);
|
||||||
|
|
|
@ -185,6 +185,7 @@ struct param;
|
||||||
double config_get_flt(const char *key, double def);
|
double config_get_flt(const char *key, double def);
|
||||||
bool config_token(const char *key, const char *tok);
|
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);
|
bool ExpensiveMigrants(void);
|
||||||
int NMRTimeout(void);
|
int NMRTimeout(void);
|
||||||
int LongHunger(const struct unit *u);
|
int LongHunger(const struct unit *u);
|
||||||
|
|
|
@ -40,7 +40,7 @@ static void test_readwrite_unit(CuTest * tc)
|
||||||
fno = f->no;
|
fno = f->no;
|
||||||
u = test_create_unit(f, r);
|
u = test_create_unit(f, r);
|
||||||
_mkdir(datapath());
|
_mkdir(datapath());
|
||||||
sprintf(path, "%s/%s", datapath(), filename);
|
join_path(datapath(), filename, path, sizeof(path));
|
||||||
|
|
||||||
data = gamedata_open(path, "wb");
|
data = gamedata_open(path, "wb");
|
||||||
CuAssertPtrNotNull(tc, data); // TODO: intermittent test
|
CuAssertPtrNotNull(tc, data); // TODO: intermittent test
|
||||||
|
|
Loading…
Reference in New Issue