server/src/util/path.c
2018-02-25 14:18:36 +01:00

32 lines
554 B
C

#ifdef _MSC_VER
#include <platform.h>
#endif
#include "path.h"
#include "strings.h"
#include <assert.h>
#include <string.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) {
size_t sz;
assert(p1 && p2);
assert(p2 != dst);
if (dst == p1) {
sz = strlen(p1);
}
else {
sz = str_strlcpy(dst, p1, len);
}
assert(sz < len);
dst[sz++] = PATH_DELIM;
str_strlcpy(dst + sz, p2, len - sz);
return dst;
}