+/* Collapse and translate path separators, and strip trailing slashes. Doesn't
+ * add or delete a leading slash.
+ *
+ * @in may alias @out.
+ */
+void
+do_canonicalize_path(const tchar *in, tchar *out)
+{
+ tchar *orig_out = out;
+
+ while (*in) {
+ if (is_any_path_separator(*in)) {
+ /* Collapse multiple path separators into one */
+ *out++ = WIM_PATH_SEPARATOR;
+ do {
+ in++;
+ } while (is_any_path_separator(*in));
+ } else {
+ /* Copy non-path-separator character */
+ *out++ = *in++;
+ }
+ }
+
+ /* Remove trailing slash if existent */
+ if (out - orig_out > 1 && *(out - 1) == WIM_PATH_SEPARATOR)
+ --out;
+
+ *out = T('\0');
+}
+