]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
xz: Add comments about stdin and src_st.st_size.
authorLasse Collin <lasse.collin@tukaani.org>
Wed, 9 Nov 2022 12:10:52 +0000 (14:10 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Fri, 11 Nov 2022 11:48:06 +0000 (13:48 +0200)
"xz -v < regular_file > out.xz" doesn't display the percentage
and estimated remaining time because it doesn't even try to
check the input file size when input is read from stdin.
This could be improved but for now there's just a comment
to remind about it.

src/xz/coder.c
src/xz/file_io.c

index f952e80db9cfcbb4d51ec1e623e4e6d0240d8bc0..4f51e8d5c0e05f6362f18e7046e5978046014167 100644 (file)
@@ -931,6 +931,15 @@ coder_run(const char *filename)
                                mytime_set_start_time();
 
                                // Initialize the progress indicator.
+                               //
+                               // NOTE: When reading from stdin, fstat()
+                               // isn't called on it and thus src_st.st_size
+                               // is zero. If stdin pointed to a regular
+                               // file, it would still be possible to know
+                               // the file size but then we would also need
+                               // to take into account the current reading
+                               // position since with stdin it isn't
+                               // necessarily at the beginning of the file.
                                const bool is_passthru = init_ret
                                                == CODER_INIT_PASSTHRU;
                                const uint64_t in_size
index 76b1967eab19cdaf5b2f386db6dccc6ccbec0333..41e4c2d893f8059c99c37e90ff68830e1a661a73 100644 (file)
@@ -755,6 +755,10 @@ io_open_src(const char *src_name)
        // a statically allocated structure.
        static file_pair pair;
 
+       // This implicitly also initializes src_st.st_size to zero
+       // which is expected to be <= 0 by default. fstat() isn't
+       // called when reading from standard input but src_st.st_size
+       // is still read.
        pair = (file_pair){
                .src_name = src_name,
                .dest_name = NULL,