mirror of
https://github.com/facebook/zstd.git
synced 2025-07-30 22:23:13 +03:00
use strerror() to generate error message
as suggested by @terrelln . also: - hopefully fixed Windows version - changed the test, so that it passes on non-english OS stdlib errors.
This commit is contained in:
@ -365,7 +365,7 @@ void FIO_setNoProgress(unsigned noProgress) {
|
|||||||
static int FIO_remove(const char* path)
|
static int FIO_remove(const char* path)
|
||||||
{
|
{
|
||||||
if (!UTIL_isRegularFile(path)) {
|
if (!UTIL_isRegularFile(path)) {
|
||||||
DISPLAYLEVEL(2, "zstd: Refusing to remove non-regular file %s\n", path);
|
DISPLAYLEVEL(2, "zstd: Refusing to remove non-regular file %s \n", path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#if defined(_WIN32) || defined(WIN32)
|
#if defined(_WIN32) || defined(WIN32)
|
||||||
@ -383,14 +383,14 @@ static FILE* FIO_openSrcFile(const char* srcFileName)
|
|||||||
{
|
{
|
||||||
assert(srcFileName != NULL);
|
assert(srcFileName != NULL);
|
||||||
if (!strcmp (srcFileName, stdinmark)) {
|
if (!strcmp (srcFileName, stdinmark)) {
|
||||||
DISPLAYLEVEL(4,"Using stdin for input\n");
|
DISPLAYLEVEL(4,"Using stdin for input \n");
|
||||||
SET_BINARY_MODE(stdin);
|
SET_BINARY_MODE(stdin);
|
||||||
return stdin;
|
return stdin;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!UTIL_fileExist(srcFileName)) {
|
if (!UTIL_fileExist(srcFileName)) {
|
||||||
DISPLAYLEVEL(1, "zstd: %s : No such file or directory (can't stat) -- ignored \n",
|
DISPLAYLEVEL(1, "zstd: can't stat %s : %s -- ignored \n",
|
||||||
srcFileName);
|
srcFileName, strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,7 +414,7 @@ static FILE* FIO_openDstFile(const char* srcFileName, const char* dstFileName)
|
|||||||
{
|
{
|
||||||
assert(dstFileName != NULL);
|
assert(dstFileName != NULL);
|
||||||
if (!strcmp (dstFileName, stdoutmark)) {
|
if (!strcmp (dstFileName, stdoutmark)) {
|
||||||
DISPLAYLEVEL(4,"Using stdout for output\n");
|
DISPLAYLEVEL(4,"Using stdout for output \n");
|
||||||
SET_BINARY_MODE(stdout);
|
SET_BINARY_MODE(stdout);
|
||||||
if (g_sparseFileSupport==1) {
|
if (g_sparseFileSupport==1) {
|
||||||
g_sparseFileSupport = 0;
|
g_sparseFileSupport = 0;
|
||||||
@ -425,11 +425,12 @@ static FILE* FIO_openDstFile(const char* srcFileName, const char* dstFileName)
|
|||||||
if (srcFileName != NULL) {
|
if (srcFileName != NULL) {
|
||||||
stat_t srcStat;
|
stat_t srcStat;
|
||||||
stat_t dstStat;
|
stat_t dstStat;
|
||||||
if (UTIL_getFileStat(srcFileName, &srcStat) && UTIL_getFileStat(dstFileName, &dstStat)) {
|
if ( UTIL_getFileStat(srcFileName, &srcStat)
|
||||||
if (srcStat.st_dev == dstStat.st_dev && srcStat.st_ino == dstStat.st_ino) {
|
&& UTIL_getFileStat(dstFileName, &dstStat)
|
||||||
DISPLAYLEVEL(1, "zstd: Refusing to open a output file which will overwrite the input file \n");
|
&& srcStat.st_dev == dstStat.st_dev
|
||||||
return NULL;
|
&& srcStat.st_ino == dstStat.st_ino ) {
|
||||||
}
|
DISPLAYLEVEL(1, "zstd: Refusing to open a output file which will overwrite the input file \n");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,12 +439,12 @@ static FILE* FIO_openDstFile(const char* srcFileName, const char* dstFileName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (UTIL_isRegularFile(dstFileName)) {
|
if (UTIL_isRegularFile(dstFileName)) {
|
||||||
FILE* fCheck;
|
|
||||||
if (!strcmp(dstFileName, nulmark)) {
|
|
||||||
EXM_THROW(40, "%s is unexpectedly a regular file", dstFileName);
|
|
||||||
}
|
|
||||||
/* Check if destination file already exists */
|
/* Check if destination file already exists */
|
||||||
fCheck = fopen( dstFileName, "rb" );
|
FILE* const fCheck = fopen( dstFileName, "rb" );
|
||||||
|
if (!strcmp(dstFileName, nulmark)) {
|
||||||
|
EXM_THROW(40, "%s is unexpectedly categorized as a regular file",
|
||||||
|
dstFileName);
|
||||||
|
}
|
||||||
if (fCheck != NULL) { /* dst file exists, authorization prompt */
|
if (fCheck != NULL) { /* dst file exists, authorization prompt */
|
||||||
fclose(fCheck);
|
fclose(fCheck);
|
||||||
if (!g_overwrite) {
|
if (!g_overwrite) {
|
||||||
|
@ -24,8 +24,12 @@ extern "C" {
|
|||||||
int UTIL_fileExist(const char* filename)
|
int UTIL_fileExist(const char* filename)
|
||||||
{
|
{
|
||||||
stat_t statbuf;
|
stat_t statbuf;
|
||||||
int const stat_success = stat(filename, &statbuf);
|
#if defined(_MSC_VER)
|
||||||
return !stat_success;
|
int const stat_error = _stat64(filename, &statbuf);
|
||||||
|
#else
|
||||||
|
int const stat_error = stat(filename, &statbuf);
|
||||||
|
#endif
|
||||||
|
return !stat_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UTIL_isRegularFile(const char* infilename)
|
int UTIL_isRegularFile(const char* infilename)
|
||||||
|
@ -187,7 +187,7 @@ $ECHO "test: overwrite input file (must fail)"
|
|||||||
$ZSTD tmp -fo tmp && die "zstd overwrote the input file"
|
$ZSTD tmp -fo tmp && die "zstd overwrote the input file"
|
||||||
$ZSTD tmp.zst -dfo tmp.zst && die "zstd overwrote the input file"
|
$ZSTD tmp.zst -dfo tmp.zst && die "zstd overwrote the input file"
|
||||||
$ECHO "test: properly detect input file does not exist"
|
$ECHO "test: properly detect input file does not exist"
|
||||||
$ZSTD nothere 2>&1 | grep "o such file"
|
$ZSTD nothere && die "zstd hasn't detected that input file does not exist"
|
||||||
|
|
||||||
$ECHO "test : file removal"
|
$ECHO "test : file removal"
|
||||||
$ZSTD -f --rm tmp
|
$ZSTD -f --rm tmp
|
||||||
|
Reference in New Issue
Block a user