X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Futil.c;h=35fbf6f11092270554918c02dc84fbfcc2da27f1;hb=eaf5b4c85a3b7b853317b887867c18a4865a83e2;hp=709ba46537d766894607a61cfbaadf5e95e44119;hpb=161e7cdd2c0d3b3c1025da452a3192d381297465;p=wimlib diff --git a/src/util.c b/src/util.c index 709ba465..35fbf6f1 100644 --- a/src/util.c +++ b/src/util.c @@ -347,6 +347,8 @@ static const tchar *error_strings[] = { = T("Failed to open a file"), [WIMLIB_ERR_OPENDIR] = T("Failed to open a directory"), + [WIMLIB_ERR_PATH_DOES_NOT_EXIST] + = T("The path does not exist in the WIM image"), [WIMLIB_ERR_READ] = T("Could not read data from a file"), [WIMLIB_ERR_READLINK] @@ -570,6 +572,45 @@ zap_backslashes(tchar *s) } } +tchar * +canonicalize_fs_path(const tchar *fs_path) +{ + tchar *canonical_path; + + if (!fs_path) + fs_path = T(""); + canonical_path = TSTRDUP(fs_path); + zap_backslashes(canonical_path); + return canonical_path; +} + +/* Strip leading and trailing slashes from a string. Also translates + * backslashes into forward slashes. */ +tchar * +canonicalize_wim_path(const tchar *wim_path) +{ + tchar *p; + tchar *canonical_path; + + if (wim_path == NULL) { + wim_path = T(""); + } else { + while (*wim_path == T('/') || *wim_path == T('\\')) + wim_path++; + } + canonical_path = TSTRDUP(wim_path); + if (canonical_path) { + zap_backslashes(canonical_path); + for (p = tstrchr(canonical_path, T('\0')) - 1; + p >= canonical_path && *p == T('/'); + p--) + { + *p = T('\0'); + } + } + return canonical_path; +} + /* Like read(), but keep trying until everything has been written or we know for * sure that there was an error (or end-of-file). */ size_t @@ -696,7 +737,7 @@ full_writev(int fd, struct iovec *iov, int iovcnt) } off_t -filedes_offset(filedes_t fd) +filedes_offset(int fd) { return lseek(fd, 0, SEEK_CUR); }