Adding MZ_PRESERVE_NATIVE_STRUCTURE to control the behavior.

This commit is contained in:
Cœur 2025-04-14 00:00:07 +02:00 committed by Nathan Moinvaziri
parent 1eb579d9bc
commit f8941493a0
2 changed files with 17 additions and 6 deletions

View File

@ -37,6 +37,10 @@
# include <stdlib.h> /* 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) {

View File

@ -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
// 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(), '\\', '/');
#endif
}
mz_path_resolve(path.c_str(), output, sizeof(output));
EXPECT_STREQ(output, expected_path.c_str());
}