feat(fileio): move output path construction to Rust
Move the basename-preserving output-directory helper behind the existing Rust utility ABI. Keep the libc allocation contract and platform separator behavior intact while leaving the C file-I/O engines and higher-level naming policy unchanged. Test Plan: - cargo test --manifest-path rust/cli/Cargo.toml (93 passed) - cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets - make -B -C tests -j2 test-cli-tests (41 passed)
This commit is contained in:
+3
-36
@@ -709,13 +709,8 @@ int FIO_checkFilenameCollisions(const char** filenameTable, unsigned nbFiles) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char*
|
||||
extractFilename(const char* path, char separator)
|
||||
{
|
||||
const char* search = strrchr(path, separator);
|
||||
if (search == NULL) return path;
|
||||
return search+1;
|
||||
}
|
||||
char* UTIL_createFilenameFromOutDir(const char* path, const char* outDirName,
|
||||
size_t suffixLen);
|
||||
|
||||
/* FIO_createFilename_fromOutDir() :
|
||||
* Takes a source file name and specified output directory, and
|
||||
@@ -725,35 +720,7 @@ extractFilename(const char* path, char separator)
|
||||
static char*
|
||||
FIO_createFilename_fromOutDir(const char* path, const char* outDirName, const size_t suffixLen)
|
||||
{
|
||||
const char* filenameStart;
|
||||
char separator;
|
||||
char* result;
|
||||
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__) || defined (__MSVCRT__) /* windows support */
|
||||
separator = '\\';
|
||||
#else
|
||||
separator = '/';
|
||||
#endif
|
||||
|
||||
filenameStart = extractFilename(path, separator);
|
||||
#if defined(_MSC_VER) || defined(__MINGW32__) || defined (__MSVCRT__) /* windows support */
|
||||
filenameStart = extractFilename(filenameStart, '/'); /* sometimes, '/' separator is also used on Windows (mingw+msys2) */
|
||||
#endif
|
||||
|
||||
result = (char*) calloc(1, strlen(outDirName) + 1 + strlen(filenameStart) + suffixLen + 1);
|
||||
if (!result) {
|
||||
EXM_THROW(30, "zstd: FIO_createFilename_fromOutDir: %s", strerror(errno));
|
||||
}
|
||||
|
||||
memcpy(result, outDirName, strlen(outDirName));
|
||||
if (outDirName[strlen(outDirName)-1] == separator) {
|
||||
memcpy(result + strlen(outDirName), filenameStart, strlen(filenameStart));
|
||||
} else {
|
||||
memcpy(result + strlen(outDirName), &separator, 1);
|
||||
memcpy(result + strlen(outDirName) + 1, filenameStart, strlen(filenameStart));
|
||||
}
|
||||
|
||||
return result;
|
||||
return UTIL_createFilenameFromOutDir(path, outDirName, suffixLen);
|
||||
}
|
||||
|
||||
/* FIO_highbit64() :
|
||||
|
||||
Reference in New Issue
Block a user