server/src/util/path.c

33 lines
554 B
C
Raw Normal View History

2017-12-29 11:44:14 +01:00
#ifdef _MSC_VER
#include <platform.h>
#endif
#include "path.h"
2017-12-30 19:49:21 +01:00
#include "strings.h"
2017-12-29 11:44:14 +01:00
#include <assert.h>
#include <string.h>
2018-02-25 14:18:36 +01:00
#ifdef WIN32
#define PATH_DELIM '\\'
#else
#define PATH_DELIM '/'
#endif
2017-12-29 11:44:14 +01:00
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 {
2017-12-30 19:49:21 +01:00
sz = str_strlcpy(dst, p1, len);
2017-12-29 11:44:14 +01:00
}
assert(sz < len);
dst[sz++] = PATH_DELIM;
2017-12-30 19:49:21 +01:00
str_strlcpy(dst + sz, p2, len - sz);
2017-12-29 11:44:14 +01:00
return dst;
}