summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-01-01 18:44:55 -0500
committerpommicket <pommicket@gmail.com>2022-01-01 18:44:55 -0500
commitf167f2ffd5e5c61787ab02b2353c243c3b7876e8 (patch)
tree9c40a45fe008202dcd16a87e337e7a7fc187c660 /util.c
parentba337edceb8cb5cc32d1d5cf71437e8d885cf45f (diff)
windows fixes
- mysterious carriage returns fixed? - fixed c:/x opening separately from c:\x
Diffstat (limited to 'util.c')
-rw-r--r--util.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/util.c b/util.c
index 5c7fa4d..62dddd2 100644
--- a/util.c
+++ b/util.c
@@ -265,20 +265,24 @@ static bool path_is_absolute(char const *path) {
// assuming `dir` is an absolute path, returns the absolute path of `relpath`, relative to `dir`.
static void path_full(char const *dir, char const *relpath, char *abspath, size_t abspath_size) {
assert(abspath_size);
+ abspath[0] = '\0';
+
if (path_is_absolute(relpath)) {
if (strchr(ALL_PATH_SEPARATORS, relpath[0])) {
// make sure that on windows, if dir's drive is C: the absolute path of \a is c:\a
- abspath[0] = '\0';
strn_cat(abspath, abspath_size, dir, strcspn(dir, ALL_PATH_SEPARATORS));
- str_cat(abspath, abspath_size, relpath);
} else {
- str_cpy(abspath, abspath_size, relpath);
+ // copy drive component (e.g. set abspath to "C:")
+ size_t drive_len = strcspn(relpath, ALL_PATH_SEPARATORS);
+ strn_cat(abspath, abspath_size, relpath, drive_len);
+ relpath += drive_len;
+ if (*relpath) ++relpath; // move past separator
}
- return;
+ } else {
+ str_cpy(abspath, abspath_size, dir);
}
- str_cpy(abspath, abspath_size, dir);
-
- while (1) {
+
+ while (*relpath) {
size_t component_len = strcspn(relpath, ALL_PATH_SEPARATORS);
char const *component_end = relpath + component_len;