diff --git a/mz_os_posix.c b/mz_os_posix.c index 461e3af..cb42ded 100644 --- a/mz_os_posix.c +++ b/mz_os_posix.c @@ -37,6 +37,10 @@ # include /* arc4random_buf */ #endif +#ifndef MZ_PRESERVE_NATIVE_STRUCTURE +# define MZ_PRESERVE_NATIVE_STRUCTURE 1 +#endif + /***************************************************************************/ #if defined(HAVE_ICONV) @@ -290,7 +294,15 @@ int32_t mz_os_close_dir(DIR *dir) { } int32_t mz_os_is_dir_separator(const char c) { +#if MZ_PRESERVE_NATIVE_STRUCTURE + // While not strictly adhering to 4.4.17.1, + // this preserves UNIX filesystem structure. return c == '/'; +#else + // While strictly adhering to 4.4.17.1, + // this corrupts UNIX filesystem structure (a filename with a '\\' will become a folder + a file). + return c == '\\' || c == '/'; +#endif } int32_t mz_os_is_dir(const char *path) { diff --git a/test/test_path.cc b/test/test_path.cc index e65875e..320f9b8 100644 --- a/test/test_path.cc +++ b/test/test_path.cc @@ -57,12 +57,11 @@ TEST_P(path_resolve, os) { char output[256]; memset(output, 'z', sizeof(output)); - // The expectation is that archiving+unarchiving data on a system should preserve its structure. - // So on Windows backslash should be preserved, while on UNIX slash should be preserved. -#ifndef _WIN32 - std::replace(path.begin(), path.end(), '\\', '/'); - std::replace(expected_path.begin(), expected_path.end(), '\\', '/'); -#endif + // archiving and unarchiving data on a system should preserve its structure + if (!mz_os_is_dir_separator('\\')) { + std::replace(path.begin(), path.end(), '\\', '/'); + std::replace(expected_path.begin(), expected_path.end(), '\\', '/'); + } mz_path_resolve(path.c_str(), output, sizeof(output)); EXPECT_STREQ(output, expected_path.c_str()); }