Merge pull request #1465 from facebook/noFilePresent

fixed : detection of non-existing file
This commit is contained in:
Yann Collet 2018-12-20 17:21:04 -08:00 committed by GitHub
commit 41b45b84a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 114 additions and 76 deletions

View File

@ -751,10 +751,10 @@ MEM_STATIC double ZSTD_fWeight(U32 rawStat)
{ {
U32 const fp_accuracy = 8; U32 const fp_accuracy = 8;
U32 const fp_multiplier = (1 << fp_accuracy); U32 const fp_multiplier = (1 << fp_accuracy);
U32 const stat = rawStat + 1; U32 const newStat = rawStat + 1;
U32 const hb = ZSTD_highbit32(stat); U32 const hb = ZSTD_highbit32(newStat);
U32 const BWeight = hb * fp_multiplier; U32 const BWeight = hb * fp_multiplier;
U32 const FWeight = (stat << fp_accuracy) >> hb; U32 const FWeight = (newStat << fp_accuracy) >> hb;
U32 const weight = BWeight + FWeight; U32 const weight = BWeight + FWeight;
assert(hb + fp_accuracy < 31); assert(hb + fp_accuracy < 31);
return (double)weight / fp_multiplier; return (double)weight / fp_multiplier;

View File

@ -159,15 +159,15 @@ static COVER_segment_t FASTCOVER_selectSegment(const FASTCOVER_ctx_t *ctx,
*/ */
while (activeSegment.end < end) { while (activeSegment.end < end) {
/* Get hash value of current dmer */ /* Get hash value of current dmer */
const size_t index = FASTCOVER_hashPtrToIndex(ctx->samples + activeSegment.end, f, d); const size_t idx = FASTCOVER_hashPtrToIndex(ctx->samples + activeSegment.end, f, d);
/* Add frequency of this index to score if this is the first occurence of index in active segment */ /* Add frequency of this index to score if this is the first occurence of index in active segment */
if (segmentFreqs[index] == 0) { if (segmentFreqs[idx] == 0) {
activeSegment.score += freqs[index]; activeSegment.score += freqs[idx];
} }
/* Increment end of segment and segmentFreqs*/ /* Increment end of segment and segmentFreqs*/
activeSegment.end += 1; activeSegment.end += 1;
segmentFreqs[index] += 1; segmentFreqs[idx] += 1;
/* If the window is now too large, drop the first position */ /* If the window is now too large, drop the first position */
if (activeSegment.end - activeSegment.begin == dmersInK + 1) { if (activeSegment.end - activeSegment.begin == dmersInK + 1) {
/* Get hash value of the dmer to be eliminated from active segment */ /* Get hash value of the dmer to be eliminated from active segment */

View File

@ -271,7 +271,7 @@ static FIO_compressionType_t g_compressionType = FIO_zstdCompression;
void FIO_setCompressionType(FIO_compressionType_t compressionType) { g_compressionType = compressionType; } void FIO_setCompressionType(FIO_compressionType_t compressionType) { g_compressionType = compressionType; }
static U32 g_overwrite = 0; static U32 g_overwrite = 0;
void FIO_overwriteMode(void) { g_overwrite = 1; } void FIO_overwriteMode(void) { g_overwrite = 1; }
static U32 g_sparseFileSupport = 1; /* 0: no sparse allowed; 1: auto (file yes, stdout no); 2: force sparse */ static U32 g_sparseFileSupport = ZSTD_SPARSE_DEFAULT; /* 0: no sparse allowed; 1: auto (file yes, stdout no); 2: force sparse */
void FIO_setSparseWrite(unsigned sparse) { g_sparseFileSupport = sparse; } void FIO_setSparseWrite(unsigned sparse) { g_sparseFileSupport = sparse; }
static U32 g_dictIDFlag = 1; static U32 g_dictIDFlag = 1;
void FIO_setDictIDFlag(unsigned dictIDFlag) { g_dictIDFlag = dictIDFlag; } void FIO_setDictIDFlag(unsigned dictIDFlag) { g_dictIDFlag = dictIDFlag; }
@ -388,6 +388,12 @@ static FILE* FIO_openSrcFile(const char* srcFileName)
return stdin; return stdin;
} }
if (!UTIL_fileExist(srcFileName)) {
DISPLAYLEVEL(1, "zstd: can't stat %s : %s -- ignored \n",
srcFileName, strerror(errno));
return NULL;
}
if (!UTIL_isRegularFile(srcFileName)) { if (!UTIL_isRegularFile(srcFileName)) {
DISPLAYLEVEL(1, "zstd: %s is not a regular file -- ignored \n", DISPLAYLEVEL(1, "zstd: %s is not a regular file -- ignored \n",
srcFileName); srcFileName);
@ -416,28 +422,29 @@ static FILE* FIO_openDstFile(const char* srcFileName, const char* dstFileName)
} }
return stdout; return stdout;
} }
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) ) {
if ( srcStat.st_dev == dstStat.st_dev
&& srcStat.st_ino == dstStat.st_ino ) {
DISPLAYLEVEL(1, "zstd: Refusing to open a output file which will overwrite the input file \n"); DISPLAYLEVEL(1, "zstd: Refusing to open a output file which will overwrite the input file \n");
return NULL; return NULL;
} } } }
}
}
if (g_sparseFileSupport == 1) { if (g_sparseFileSupport == 1) {
g_sparseFileSupport = ZSTD_SPARSE_DEFAULT; g_sparseFileSupport = ZSTD_SPARSE_DEFAULT;
} }
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) {
@ -803,26 +810,28 @@ FIO_compressLz4Frame(cRess_t* ress,
/* Main Loop */ /* Main Loop */
while (readSize>0) { while (readSize>0) {
size_t outSize; size_t const outSize = LZ4F_compressUpdate(ctx,
ress->dstBuffer, ress->dstBufferSize,
/* Compress Block */ ress->srcBuffer, readSize, NULL);
outSize = LZ4F_compressUpdate(ctx, ress->dstBuffer, ress->dstBufferSize, ress->srcBuffer, readSize, NULL);
if (LZ4F_isError(outSize)) if (LZ4F_isError(outSize))
EXM_THROW(35, "zstd: %s: lz4 compression failed : %s", EXM_THROW(35, "zstd: %s: lz4 compression failed : %s",
srcFileName, LZ4F_getErrorName(outSize)); srcFileName, LZ4F_getErrorName(outSize));
outFileSize += outSize; outFileSize += outSize;
if (srcFileSize == UTIL_FILESIZE_UNKNOWN) if (srcFileSize == UTIL_FILESIZE_UNKNOWN) {
DISPLAYUPDATE(2, "\rRead : %u MB ==> %.2f%%", DISPLAYUPDATE(2, "\rRead : %u MB ==> %.2f%%",
(U32)(inFileSize>>20), (U32)(inFileSize>>20),
(double)outFileSize/inFileSize*100) (double)outFileSize/inFileSize*100)
else } else {
DISPLAYUPDATE(2, "\rRead : %u / %u MB ==> %.2f%%", DISPLAYUPDATE(2, "\rRead : %u / %u MB ==> %.2f%%",
(U32)(inFileSize>>20), (U32)(srcFileSize>>20), (U32)(inFileSize>>20), (U32)(srcFileSize>>20),
(double)outFileSize/inFileSize*100); (double)outFileSize/inFileSize*100);
}
/* Write Block */ /* Write Block */
{ size_t const sizeCheck = fwrite(ress->dstBuffer, 1, outSize, ress->dstFile); { size_t const sizeCheck = fwrite(ress->dstBuffer, 1, outSize, ress->dstFile);
if (sizeCheck!=outSize) EXM_THROW(36, "Write error : %s", strerror(errno)); } if (sizeCheck != outSize)
EXM_THROW(36, "Write error : %s", strerror(errno));
}
/* Read next block */ /* Read next block */
readSize = fread(ress->srcBuffer, (size_t)1, (size_t)blockSize, ress->srcFile); readSize = fread(ress->srcBuffer, (size_t)1, (size_t)blockSize, ress->srcFile);
@ -1431,12 +1440,14 @@ static unsigned FIO_fwriteSparse(FILE* file, const void* buffer, size_t bufferSi
static void FIO_fwriteSparseEnd(FILE* file, unsigned storedSkips) static void FIO_fwriteSparseEnd(FILE* file, unsigned storedSkips)
{ {
if (storedSkips-->0) { /* implies g_sparseFileSupport>0 */ if (storedSkips>0) {
int const seekResult = LONG_SEEK(file, storedSkips, SEEK_CUR); assert(g_sparseFileSupport > 0); /* storedSkips>0 implies sparse support is enabled */
if (seekResult != 0) EXM_THROW(69, "Final skip error (sparse file)"); if (LONG_SEEK(file, storedSkips-1, SEEK_CUR) != 0)
EXM_THROW(69, "Final skip error (sparse file support)");
/* last zero must be explicitly written,
* so that skipped ones get implicitly translated as zero by FS */
{ const char lastZeroByte[1] = { 0 }; { const char lastZeroByte[1] = { 0 };
size_t const sizeCheck = fwrite(lastZeroByte, 1, 1, file); if (fwrite(lastZeroByte, 1, 1, file) != 1)
if (sizeCheck != 1)
EXM_THROW(69, "Write error : cannot write last zero"); EXM_THROW(69, "Write error : cannot write last zero");
} } } }
} }
@ -2323,7 +2334,7 @@ FIO_listFile(fileInfo_t* total, const char* inFileName, int displayLevel)
} }
displayInfo(inFileName, &info, displayLevel); displayInfo(inFileName, &info, displayLevel);
*total = FIO_addFInfo(*total, info); *total = FIO_addFInfo(*total, info);
assert(error>=0 || error<=1); assert(error == info_success || error == info_frame_error);
return error; return error;
} }
} }

View File

@ -16,7 +16,21 @@ extern "C" {
/*-**************************************** /*-****************************************
* Dependencies * Dependencies
******************************************/ ******************************************/
#include "util.h" #include "util.h" /* note : ensure that platform.h is included first ! */
#include <errno.h>
#include <assert.h>
int UTIL_fileExist(const char* filename)
{
stat_t statbuf;
#if defined(_MSC_VER)
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)
{ {
@ -161,21 +175,23 @@ int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char
pathLength = dirLength+1+fnameLength; pathLength = dirLength+1+fnameLength;
path[pathLength] = 0; path[pathLength] = 0;
if (cFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (cFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
if (strcmp (cFile.cFileName, "..") == 0 || if ( strcmp (cFile.cFileName, "..") == 0
strcmp (cFile.cFileName, ".") == 0) continue; || strcmp (cFile.cFileName, ".") == 0 )
continue;
nbFiles += UTIL_prepareFileList(path, bufStart, pos, bufEnd, followLinks); /* Recursively call "UTIL_prepareFileList" with the new path. */ /* Recursively call "UTIL_prepareFileList" with the new path. */
nbFiles += UTIL_prepareFileList(path, bufStart, pos, bufEnd, followLinks);
if (*bufStart == NULL) { free(path); FindClose(hFile); return 0; } if (*bufStart == NULL) { free(path); FindClose(hFile); return 0; }
} } else if ( (cFile.dwFileAttributes & FILE_ATTRIBUTE_NORMAL)
else if ((cFile.dwFileAttributes & FILE_ATTRIBUTE_NORMAL) || (cFile.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) || (cFile.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED)) { || (cFile.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)
|| (cFile.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) ) {
if (*bufStart + *pos + pathLength >= *bufEnd) { if (*bufStart + *pos + pathLength >= *bufEnd) {
ptrdiff_t newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE; ptrdiff_t const newListSize = (*bufEnd - *bufStart) + LIST_SIZE_INCREASE;
*bufStart = (char*)UTIL_realloc(*bufStart, newListSize); *bufStart = (char*)UTIL_realloc(*bufStart, newListSize);
*bufEnd = *bufStart + newListSize;
if (*bufStart == NULL) { free(path); FindClose(hFile); return 0; } if (*bufStart == NULL) { free(path); FindClose(hFile); return 0; }
*bufEnd = *bufStart + newListSize;
} }
if (*bufStart + *pos + pathLength < *bufEnd) { if (*bufStart + *pos + pathLength < *bufEnd) {
strncpy(*bufStart + *pos, path, *bufEnd - (*bufStart + *pos)); memcpy(*bufStart + *pos, path, pathLength+1 /* include final \0 */);
*pos += pathLength + 1; *pos += pathLength + 1;
nbFiles++; nbFiles++;
} }
@ -232,7 +248,7 @@ int UTIL_prepareFileList(const char *dirName, char** bufStart, size_t* pos, char
if (*bufStart == NULL) { free(path); closedir(dir); return 0; } if (*bufStart == NULL) { free(path); closedir(dir); return 0; }
} }
if (*bufStart + *pos + pathLength < *bufEnd) { if (*bufStart + *pos + pathLength < *bufEnd) {
strncpy(*bufStart + *pos, path, *bufEnd - (*bufStart + *pos)); memcpy(*bufStart + *pos, path, pathLength + 1); /* with final \0 */
*pos += pathLength + 1; *pos += pathLength + 1;
nbFiles++; nbFiles++;
} }
@ -290,7 +306,7 @@ UTIL_createFileList(const char **inputNames, unsigned inputNamesNb,
if (!buf) return NULL; if (!buf) return NULL;
} }
if (buf + pos + len < bufend) { if (buf + pos + len < bufend) {
strncpy(buf + pos, inputNames[i], bufend - (buf + pos)); memcpy(buf+pos, inputNames[i], len+1); /* with final \0 */
pos += len + 1; pos += len + 1;
nbFiles++; nbFiles++;
} }
@ -322,6 +338,7 @@ UTIL_createFileList(const char **inputNames, unsigned inputNamesNb,
******************************************/ ******************************************/
int g_utilDisplayLevel; int g_utilDisplayLevel;
/*-**************************************** /*-****************************************
* Time functions * Time functions
******************************************/ ******************************************/
@ -340,6 +357,7 @@ U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd)
} }
return 1000000ULL*(clockEnd.QuadPart - clockStart.QuadPart)/ticksPerSecond.QuadPart; return 1000000ULL*(clockEnd.QuadPart - clockStart.QuadPart)/ticksPerSecond.QuadPart;
} }
U64 UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd) U64 UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd)
{ {
static LARGE_INTEGER ticksPerSecond; static LARGE_INTEGER ticksPerSecond;
@ -353,7 +371,9 @@ U64 UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd)
} }
#elif defined(__APPLE__) && defined(__MACH__) #elif defined(__APPLE__) && defined(__MACH__)
UTIL_time_t UTIL_getTime(void) { return mach_absolute_time(); } UTIL_time_t UTIL_getTime(void) { return mach_absolute_time(); }
U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd) U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd)
{ {
static mach_timebase_info_data_t rate; static mach_timebase_info_data_t rate;
@ -422,11 +442,11 @@ U64 UTIL_getSpanTimeNano(UTIL_time_t begin, UTIL_time_t end)
} }
#else /* relies on standard C (note : clock_t measurements can be wrong when using multi-threading) */ #else /* relies on standard C (note : clock_t measurements can be wrong when using multi-threading) */
typedef clock_t UTIL_time_t;
#define UTIL_TIME_INITIALIZER 0
UTIL_time_t UTIL_getTime(void) { return clock(); } UTIL_time_t UTIL_getTime(void) { return clock(); }
U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC; } U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC; }
U64 UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC; } U64 UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd) { return 1000000000ULL * (clockEnd - clockStart) / CLOCKS_PER_SEC; }
#endif #endif
/* returns time span in microseconds */ /* returns time span in microseconds */
@ -651,4 +671,3 @@ int UTIL_countPhysicalCores(void)
#if defined (__cplusplus) #if defined (__cplusplus)
} }
#endif #endif

View File

@ -20,10 +20,9 @@ extern "C" {
* Dependencies * Dependencies
******************************************/ ******************************************/
#include "platform.h" /* PLATFORM_POSIX_VERSION, ZSTD_NANOSLEEP_SUPPORT, ZSTD_SETPRIORITY_SUPPORT */ #include "platform.h" /* PLATFORM_POSIX_VERSION, ZSTD_NANOSLEEP_SUPPORT, ZSTD_SETPRIORITY_SUPPORT */
#include <stdlib.h> /* malloc */ #include <stdlib.h> /* malloc, realloc, free */
#include <stddef.h> /* size_t, ptrdiff_t */ #include <stddef.h> /* size_t, ptrdiff_t */
#include <stdio.h> /* fprintf */ #include <stdio.h> /* fprintf */
#include <string.h> /* strncmp */
#include <sys/types.h> /* stat, utime */ #include <sys/types.h> /* stat, utime */
#include <sys/stat.h> /* stat, chmod */ #include <sys/stat.h> /* stat, chmod */
#if defined(_MSC_VER) #if defined(_MSC_VER)
@ -34,7 +33,6 @@ extern "C" {
# include <utime.h> /* utime */ # include <utime.h> /* utime */
#endif #endif
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC, nanosleep */ #include <time.h> /* clock_t, clock, CLOCKS_PER_SEC, nanosleep */
#include <errno.h>
#include "mem.h" /* U32, U64 */ #include "mem.h" /* U32, U64 */
@ -118,12 +116,16 @@ extern int g_utilDisplayLevel;
* Time functions * Time functions
******************************************/ ******************************************/
#if defined(_WIN32) /* Windows */ #if defined(_WIN32) /* Windows */
#define UTIL_TIME_INITIALIZER { { 0, 0 } } #define UTIL_TIME_INITIALIZER { { 0, 0 } }
typedef LARGE_INTEGER UTIL_time_t; typedef LARGE_INTEGER UTIL_time_t;
#elif defined(__APPLE__) && defined(__MACH__) #elif defined(__APPLE__) && defined(__MACH__)
#include <mach/mach_time.h> #include <mach/mach_time.h>
#define UTIL_TIME_INITIALIZER 0 #define UTIL_TIME_INITIALIZER 0
typedef U64 UTIL_time_t; typedef U64 UTIL_time_t;
#elif (PLATFORM_POSIX_VERSION >= 200112L) \ #elif (PLATFORM_POSIX_VERSION >= 200112L) \
&& (defined(__UCLIBC__) \ && (defined(__UCLIBC__) \
|| (defined(__GLIBC__) \ || (defined(__GLIBC__) \
@ -135,10 +137,14 @@ extern int g_utilDisplayLevel;
typedef struct timespec UTIL_time_t; typedef struct timespec UTIL_time_t;
UTIL_time_t UTIL_getSpanTime(UTIL_time_t begin, UTIL_time_t end); UTIL_time_t UTIL_getSpanTime(UTIL_time_t begin, UTIL_time_t end);
#else /* relies on standard C (note : clock_t measurements can be wrong when using multi-threading) */ #else /* relies on standard C (note : clock_t measurements can be wrong when using multi-threading) */
typedef clock_t UTIL_time_t; typedef clock_t UTIL_time_t;
#define UTIL_TIME_INITIALIZER 0 #define UTIL_TIME_INITIALIZER 0
#endif #endif
UTIL_time_t UTIL_getTime(void); UTIL_time_t UTIL_getTime(void);
U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd); U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd);
U64 UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd); U64 UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd);
@ -163,6 +169,7 @@ void UTIL_waitForNextTick(void);
#endif #endif
int UTIL_fileExist(const char* filename);
int UTIL_isRegularFile(const char* infilename); int UTIL_isRegularFile(const char* infilename);
int UTIL_setFileStat(const char* filename, stat_t* statbuf); int UTIL_setFileStat(const char* filename, stat_t* statbuf);
U32 UTIL_isDirectory(const char* infilename); U32 UTIL_isDirectory(const char* infilename);

View File

@ -12,7 +12,7 @@
/*-************************************ /*-************************************
* Dependencies * Dependencies
**************************************/ **************************************/
#include "util.h" /* Compiler options, UTIL_GetFileSize */ #include "util.h" /* Ensure platform.h is compiled first; also : compiler options, UTIL_GetFileSize */
#include <stdlib.h> /* malloc */ #include <stdlib.h> /* malloc */
#include <stdio.h> /* fprintf, fopen, ftello64 */ #include <stdio.h> /* fprintf, fopen, ftello64 */
#include <string.h> /* strcmp */ #include <string.h> /* strcmp */
@ -24,7 +24,6 @@
#include "zstd.h" #include "zstd.h"
#include "datagen.h" #include "datagen.h"
#include "xxhash.h" #include "xxhash.h"
#include "util.h"
#include "benchfn.h" #include "benchfn.h"
#include "benchzstd.h" #include "benchzstd.h"
#include "zstd_errors.h" #include "zstd_errors.h"
@ -879,12 +878,12 @@ BMK_printWinner(FILE* f, const int cLevel, const BMK_benchResult_t result, const
if(TIMED) { if(TIMED) {
const U64 mn_in_ns = 60ULL * TIMELOOP_NANOSEC; const U64 mn_in_ns = 60ULL * TIMELOOP_NANOSEC;
const U64 time = UTIL_clockSpanNano(g_time); const U64 time_ns = UTIL_clockSpanNano(g_time);
const U64 minutes = time / mn_in_ns; const U64 minutes = time_ns / mn_in_ns;
fprintf(f, "%1lu:%2lu:%05.2f - ", fprintf(f, "%1lu:%2lu:%05.2f - ",
(unsigned long) minutes / 60, (unsigned long) minutes / 60,
(unsigned long) minutes % 60, (unsigned long) minutes % 60,
(double)(time - (minutes * mn_in_ns)) / TIMELOOP_NANOSEC ); (double)(time_ns - (minutes * mn_in_ns)) / TIMELOOP_NANOSEC );
} }
fprintf(f, "/* %s */ ", lvlstr); fprintf(f, "/* %s */ ", lvlstr);

View File

@ -196,9 +196,10 @@ $ZSTD tmpro -c --no-progress | $ZSTD -d -o "$INTOVOID" --no-progress
$ZSTD tmpro -cv --no-progress | $ZSTD -dv -o "$INTOVOID" --no-progress $ZSTD tmpro -cv --no-progress | $ZSTD -dv -o "$INTOVOID" --no-progress
rm -f tmpro tmpro.zst rm -f tmpro tmpro.zst
$ECHO "test: overwrite input file (must fail)" $ECHO "test: overwrite input file (must fail)"
$ZSTD tmp -fo tmp && die "zstd overwrote the input file" $ZSTD tmp -fo tmp && die "zstd compression overwrote the input file"
$ZSTD tmp.zst -dfo tmp.zst && die "zstd overwrote the input file" $ZSTD tmp.zst -dfo tmp.zst && die "zstd decompression overwrote the input file"
$ECHO "test: detect that input file does not exist"
$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

View File

@ -71,25 +71,25 @@ valgrindTest: clean example fitblk example_zstd fitblk_zstd zwrapbench
# $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< # $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
minigzip: $(EXAMPLE_PATH)/minigzip.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY) minigzip: $(EXAMPLE_PATH)/minigzip.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY)
$(CC) $(LDFLAGS) $^ $(ZSTDLIBRARY) $(ZLIB_LIBRARY) -o $@ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZSTDLIBRARY) $(ZLIB_LIBRARY) -o $@
minigzip_zstd: $(EXAMPLE_PATH)/minigzip.o $(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY) minigzip_zstd: $(EXAMPLE_PATH)/minigzip.o $(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY)
$(CC) $(LDFLAGS) $^ $(ZSTDLIBRARY) $(ZLIB_LIBRARY) -o $@ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZSTDLIBRARY) $(ZLIB_LIBRARY) -o $@
example: $(EXAMPLE_PATH)/example.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY) example: $(EXAMPLE_PATH)/example.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY)
$(CC) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@
example_zstd: $(EXAMPLE_PATH)/example.o $(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY) example_zstd: $(EXAMPLE_PATH)/example.o $(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o $(GZFILES) $(ZSTDLIBRARY)
$(CC) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@
fitblk: $(EXAMPLE_PATH)/fitblk.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(ZSTDLIBRARY) fitblk: $(EXAMPLE_PATH)/fitblk.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(ZSTDLIBRARY)
$(CC) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@
fitblk_zstd: $(EXAMPLE_PATH)/fitblk.o $(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o $(ZSTDLIBRARY) fitblk_zstd: $(EXAMPLE_PATH)/fitblk.o $(ZLIBWRAPPER_PATH)/zstdTurnedOn_zlibwrapper.o $(ZSTDLIBRARY)
$(CC) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@
zwrapbench: $(EXAMPLE_PATH)/zwrapbench.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(PROGRAMS_PATH)/util.o $(PROGRAMS_PATH)/datagen.o $(ZSTDLIBRARY) zwrapbench: $(EXAMPLE_PATH)/zwrapbench.o $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o $(PROGRAMS_PATH)/util.o $(PROGRAMS_PATH)/datagen.o $(ZSTDLIBRARY)
$(CC) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@ $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $^ $(ZLIB_LIBRARY) -o $@
$(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o: $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.h $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.o: $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.c $(ZLIBWRAPPER_PATH)/zstd_zlibwrapper.h

View File

@ -17,6 +17,7 @@
#include <stdio.h> /* fprintf, fopen, ftello64 */ #include <stdio.h> /* fprintf, fopen, ftello64 */
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */ #include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */
#include <ctype.h> /* toupper */ #include <ctype.h> /* toupper */
#include <errno.h> /* errno */
#include "mem.h" #include "mem.h"
#define ZSTD_STATIC_LINKING_ONLY #define ZSTD_STATIC_LINKING_ONLY