diff options
-rw-r--r-- | contrib/meson/meson/meson.build | 9 | ||||
-rw-r--r-- | programs/lz4cli.c | 10 | ||||
-rw-r--r-- | programs/lz4io.c | 2 | ||||
-rw-r--r-- | programs/util.h | 25 | ||||
-rw-r--r-- | tests/Makefile | 1 |
5 files changed, 33 insertions, 14 deletions
diff --git a/contrib/meson/meson/meson.build b/contrib/meson/meson/meson.build index b278b7c..2cfd48c 100644 --- a/contrib/meson/meson/meson.build +++ b/contrib/meson/meson/meson.build @@ -28,13 +28,8 @@ lz4_version = meson.project_version() lz4_h_file = join_paths(meson.current_source_dir(), '../../../lib/lz4.h') GetLz4LibraryVersion_py = find_program('GetLz4LibraryVersion.py', native : true) -r = run_command(GetLz4LibraryVersion_py, lz4_h_file) -if r.returncode() == 0 - lz4_version = r.stdout().strip() - message('Project version is now: @0@'.format(lz4_version)) -else - error('Cannot find project version in @0@'.format(lz4_h_file)) -endif +lz4_version = run_command(GetLz4LibraryVersion_py, lz4_h_file, check: true).stdout().strip() +message('Project version is now: @0@'.format(lz4_version)) lz4_libversion = lz4_version diff --git a/programs/lz4cli.c b/programs/lz4cli.c index 57a6ab9..b5cb000 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -712,11 +712,6 @@ int main(int argc, const char** argv) } if (mode == om_list){ - /* Exit if trying to read from stdin as this isn't supported in this mode */ - if(!strcmp(input_filename, stdinmark)){ - DISPLAYLEVEL(1, "refusing to read from standard input in --list mode\n"); - exit(1); - } if(!multiple_inputs){ inFileNames[ifnIdx++] = input_filename; } @@ -729,7 +724,10 @@ int main(int argc, const char** argv) if (!output_filename) output_filename = "*\\dummy^!//"; /* Check if output is defined as console; trigger an error in this case */ - if (!strcmp(output_filename,stdoutmark) && IS_CONSOLE(stdout) && !forceStdout) { + if ( !strcmp(output_filename,stdoutmark) + && mode != om_list + && IS_CONSOLE(stdout) + && !forceStdout) { DISPLAYLEVEL(1, "refusing to write to console without -c \n"); exit(1); } diff --git a/programs/lz4io.c b/programs/lz4io.c index c01374b..a4c21ee 100644 --- a/programs/lz4io.c +++ b/programs/lz4io.c @@ -1639,7 +1639,7 @@ int LZ4IO_displayCompressedFilesInfo(const char** inFileNames, size_t ifnIdx) /* Get file info */ LZ4IO_cFileInfo_t cfinfo = LZ4IO_INIT_CFILEINFO; cfinfo.fileName = LZ4IO_baseName(inFileNames[idx]); - if (!UTIL_isRegFile(inFileNames[idx])) { + if ((strcmp(inFileNames[idx], stdinmark) == 0) ? !UTIL_isRegFD(0) : !UTIL_isRegFile(inFileNames[idx])) { DISPLAYLEVEL(1, "lz4: %s is not a regular file \n", inFileNames[idx]); return 0; } diff --git a/programs/util.h b/programs/util.h index 394837e..2840179 100644 --- a/programs/util.h +++ b/programs/util.h @@ -317,6 +317,7 @@ UTIL_STATIC void UTIL_waitForNextTick(void) UTIL_STATIC int UTIL_isRegFile(const char* infilename); +UTIL_STATIC int UTIL_isRegFD(int fd); UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf) @@ -352,6 +353,19 @@ UTIL_STATIC int UTIL_setFileStat(const char *filename, stat_t *statbuf) } +UTIL_STATIC int UTIL_getFDStat(int fd, stat_t *statbuf) +{ + int r; +#if defined(_MSC_VER) + r = _fstat64(fd, statbuf); + if (r || !(statbuf->st_mode & S_IFREG)) return 0; /* No good... */ +#else + r = fstat(fd, statbuf); + if (r || !S_ISREG(statbuf->st_mode)) return 0; /* No good... */ +#endif + return 1; +} + UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) { int r; @@ -366,6 +380,17 @@ UTIL_STATIC int UTIL_getFileStat(const char* infilename, stat_t *statbuf) } +UTIL_STATIC int UTIL_isRegFD(int fd) +{ + stat_t statbuf; +#ifdef _WIN32 + /* Windows runtime library always open file descriptors 0, 1 and 2 in text mode, therefore we can't use them for binary I/O */ + if(fd < 3) return 0; +#endif + return UTIL_getFDStat(fd, &statbuf); /* Only need to know whether it is a regular file */ +} + + UTIL_STATIC int UTIL_isRegFile(const char* infilename) { stat_t statbuf; diff --git a/tests/Makefile b/tests/Makefile index b7490b8..b4df3e3 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -360,6 +360,7 @@ test-lz4-basic: lz4 datagen unlz4 lz4cat $(DIFF) -q tmp-tlb-hw tmp-tlb4 $(LZ4) -f tmp-tlb-hw $(LZ4) --list tmp-tlb-hw.lz4 # test --list on valid single-frame file + $(LZ4) --list < tmp-tlb-hw.lz4 # test --list from stdin (file only) $(CAT) tmp-tlb-hw >> tmp-tlb-hw.lz4 $(LZ4) -f tmp-tlb-hw.lz4 # uncompress valid frame followed by invalid data $(LZ4) -BX tmp-tlb-hw -c -q | $(LZ4) -tv # test block checksum |