From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 49EF63858D32; Sun, 5 Feb 2023 21:43:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49EF63858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675633429; bh=cmCRT1foUx0doKYs1VPEC91YH6/GsiUepGEXnPwptfA=; h=To:Subject:Date:From:From; b=GNNvOOMRwhy3tCZz2wUKr/JbAGL4kAFTv4iqmzLu9OGUe3HRouV5pPROBgy32WCD/ SasVGCeA4XdNFzymMIdBMPsHE02VEZlz8Ero5UDCjGv1tYDplSHD/+T67M87h0EyPf zgOlHhkuM5JQsCAH8JbjySWm5N5KV9U73grNPLBA= To: cygwin-apps-cvs@sourceware.org Subject: [setup - the official Cygwin setup program] branch master, updated. release_2.925-4-g64a12e7e9021 X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 3a81c966d02532e3efc74c65ed9241f9548921e0 X-Git-Newrev: 64a12e7e9021e50cb935bc8fc973cee4d673f108 Message-Id: <20230205214349.49EF63858D32@sourceware.org> Date: Sun, 5 Feb 2023 21:43:49 +0000 (GMT) From: Corinna Vinschen List-Id: https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=64a12e7e9021e50cb935bc8fc973cee4d673f108 commit 64a12e7e9021e50cb935bc8fc973cee4d673f108 Author: Corinna Vinschen Date: Sun Feb 5 20:30:57 2023 +0100 io_stream: peek: call own read method rather than fread This fixes the caller's expectation that peek returns a negative value on error. https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=44d31ea07407104d2317e31800704538d0c3093a commit 44d31ea07407104d2317e31800704538d0c3093a Author: Corinna Vinschen Date: Sat Feb 4 22:12:34 2023 +0100 Use off_t more consistently for file offsets and file size - Change the seek and tell methods to off_t in the first place, and use fseeko/ftello throughout. - Change class members holding file sizes and offsets to off_t, use matching casts. - Use strtoll rather than sscanf to read octal file length in tar archives. It's faster and typesafe. - Use off_t as argument types for progress bar functions. Additionally: - Reformat io_stream_memory.h, which was next to unreadable due to bad formatting. https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/setup.git;h=4e30c4f6248fefa439a5b4e34dae260d01b25408 commit 4e30c4f6248fefa439a5b4e34dae260d01b25408 Author: Corinna Vinschen Date: Sat Feb 4 21:06:10 2023 +0100 io_stream: read/write: always return -1 on error io_stream::read and io_stream::write are defined as ssize_t, and most of the callers expect -1 in case of an error. However, io_stream_file and io_stream_cygfile both use fread/fwrite and return their return value unchanged. Both functions return a size_t and return 0 in both cases, EOF and error. Fix this by checking the return value of fread and fwrite and return -1 in case of an error. Change the two callers calling read and expecting 0 to indicate EOF and error accordingly. Diff: --- UserSettings.cc | 2 +- archive.h | 2 +- archive_tar.cc | 10 ++++----- archive_tar.h | 12 +++++----- archive_tar_file.cc | 10 ++++----- compress.h | 2 +- compress_bz.cc | 8 +++---- compress_bz.h | 4 ++-- compress_gz.cc | 14 +++++++----- compress_gz.h | 6 ++--- compress_xz.cc | 11 +++++---- compress_xz.h | 4 ++-- compress_zstd.cc | 8 +++---- compress_zstd.h | 4 ++-- gpg-packet.cc | 2 +- install.cc | 10 ++++----- io_stream.h | 4 ++-- io_stream_cygfile.cc | 55 ++++++++++++++++++++++++++++++++------------- io_stream_cygfile.h | 4 ++-- io_stream_file.cc | 58 ++++++++++++++++++++++++++++++++--------------- io_stream_file.h | 4 ++-- io_stream_memory.cc | 2 +- io_stream_memory.h | 63 +++++++++++++++++++++++++++++++++++++++++----------- threebar.cc | 6 ++--- threebar.h | 6 ++--- 25 files changed, 199 insertions(+), 112 deletions(-) diff --git a/UserSettings.cc b/UserSettings.cc index d0bb4ef497dc..514972556ebf 100644 --- a/UserSettings.cc +++ b/UserSettings.cc @@ -33,7 +33,7 @@ public: ssize_t write (const void *buffer, size_t len) {return 0;} ssize_t peek (void *buffer, size_t len) {return 0;} long tell () {return 0;} - int seek (long, io_stream_seek_t) {return 0;} + off_t seek (off_t, io_stream_seek_t) {return 0;} int error () {return 0;} void operator << (std::string); void operator << (const char *); diff --git a/archive.h b/archive.h index adab9f0f2da9..1299eb12c647 100644 --- a/archive.h +++ b/archive.h @@ -70,7 +70,7 @@ public: * Could be made valid via the read-child-directly model */ - virtual int seek (long offset, io_stream_seek_t whence) = 0; + virtual off_t seek (off_t offset, io_stream_seek_t whence) = 0; /* Find out the next stream name - * ie for foo.tar.gz, at offset 0, next_file_name = foo.tar diff --git a/archive_tar.cc b/archive_tar.cc index 63269a61c2c6..ec7b003dd109 100644 --- a/archive_tar.cc +++ b/archive_tar.cc @@ -82,14 +82,14 @@ archive_tar::error () return state.lasterr; } -long +off_t archive_tar::tell () { return state.file_offset; } -int -archive_tar::seek (long where, io_stream_seek_t whence) +off_t +archive_tar::seek (off_t where, io_stream_seek_t whence) { /* Because the parent stream is compressed, we can only easily support seek()-ing to rewind to the start */ @@ -166,7 +166,7 @@ archive_tar::next_file_name () state.have_longlink = 0; } - sscanf (state.tar_header.size, "%zo", &state.file_length); + state.file_length = strtoll (state.tar_header.size, NULL, 8); state.file_offset = 0; if (_tar_verbose) @@ -190,7 +190,7 @@ archive_tar::next_file_name () CYG_PATH_MAX); err++; state.parent->read (&state.tar_header, 512); - sscanf (state.tar_header.size, "%zo", &state.file_length); + state.file_length = strtoll (state.tar_header.size, NULL, 8); state.file_offset = 0; skip_file (); return next_file_name (); diff --git a/archive_tar.h b/archive_tar.h index 3adc05606831..da8eaa667f80 100644 --- a/archive_tar.h +++ b/archive_tar.h @@ -68,8 +68,8 @@ public: char have_longname; bool have_longlink; /* where in the current file are we? */ - size_t file_offset; - size_t file_length; + off_t file_offset; + off_t file_length; int header_read; tar_header_type tar_header; char filename[CYG_PATH_MAX + 512]; @@ -88,8 +88,8 @@ public: virtual ssize_t write (const void *buffer, size_t len); /* read data without removing it from the class's internal buffer */ virtual ssize_t peek (void *buffer, size_t len); - virtual long tell (); - virtual int seek (long where, io_stream_seek_t whence); + virtual off_t tell (); + virtual off_t seek (off_t where, io_stream_seek_t whence); /* try guessing this one */ virtual int error (); virtual time_t get_mtime (); @@ -112,8 +112,8 @@ public: virtual ssize_t write (const void *buffer, size_t len); /* read data without removing it from the class's internal buffer */ virtual ssize_t peek (void *buffer, size_t len); - virtual long tell (); - virtual int seek (long where, io_stream_seek_t whence); + virtual off_t tell (); + virtual off_t seek (off_t where, io_stream_seek_t whence); /* try guessing this one */ virtual int error (); /* Find out the next stream name - diff --git a/archive_tar_file.cc b/archive_tar_file.cc index 87e54df0de9a..1b4367739394 100644 --- a/archive_tar_file.cc +++ b/archive_tar_file.cc @@ -38,7 +38,7 @@ ssize_t archive_tar_file::read (void *buffer, size_t len) { /* how many bytes do we want to give the user */ int - want = std::min (len, state.file_length - state.file_offset); + want = std::min ((off_t) len, state.file_length - state.file_offset); /* how many do we need to read after that to line up the file pointer */ int roundup = (512 - (want % 512)) % 512; @@ -95,7 +95,7 @@ ssize_t archive_tar_file::write (const void *buffer, size_t len) ssize_t archive_tar_file::peek (void *buffer, size_t len) { int - want = std::min (len, state.file_length - state.file_offset); + want = std::min ((off_t) len, state.file_length - state.file_offset); if (want) { ssize_t @@ -115,14 +115,14 @@ ssize_t archive_tar_file::peek (void *buffer, size_t len) return 0; } -long +off_t archive_tar_file::tell () { return state.file_offset; } -int -archive_tar_file::seek (long where, io_stream_seek_t whence) +off_t +archive_tar_file::seek (off_t where, io_stream_seek_t whence) { /* nothing needs seeking here yet. Implement when needed */ diff --git a/compress.h b/compress.h index 691313382ac1..1692fa6ddc6e 100644 --- a/compress.h +++ b/compress.h @@ -37,7 +37,7 @@ public: virtual ssize_t write (const void *buffer, size_t len) = 0; /* read data without removing it from the class's internal buffer */ virtual ssize_t peek (void *buffer, size_t len) = 0; - virtual long tell () = 0; + virtual off_t tell () = 0; /* try guessing this one */ virtual int error () = 0; /* Find out the next stream name - diff --git a/compress_bz.cc b/compress_bz.cc index e4792d649123..d801de1e6bfc 100644 --- a/compress_bz.cc +++ b/compress_bz.cc @@ -187,7 +187,7 @@ ssize_t compress_bz::peek (void *buffer, size_t len) return 0; } -long +off_t compress_bz::tell () { if (writing) @@ -196,12 +196,12 @@ compress_bz::tell () return position; } -int -compress_bz::seek (long where, io_stream_seek_t whence) +off_t +compress_bz::seek (off_t where, io_stream_seek_t whence) { if ((whence == IO_SEEK_SET) && (where == 0)) { - int result = original->seek(where, whence); + off_t result = original->seek(where, whence); init_state(); return result; } diff --git a/compress_bz.h b/compress_bz.h index a7e865a0d55b..9ab59d709be6 100644 --- a/compress_bz.h +++ b/compress_bz.h @@ -33,8 +33,8 @@ public: virtual ssize_t write (const void *buffer, size_t len); /* read data without removing it from the class's internal buffer */ virtual ssize_t peek (void *buffer, size_t len); - virtual long tell (); - virtual int seek (long where, io_stream_seek_t whence); + virtual off_t tell (); + virtual off_t seek (off_t where, io_stream_seek_t whence); /* try guessing this one */ virtual int error (); /* Find out the next stream name - diff --git a/compress_gz.cc b/compress_gz.cc index e73ccd331551..c7d6d1af1cf3 100644 --- a/compress_gz.cc +++ b/compress_gz.cc @@ -282,11 +282,12 @@ compress_gz::read (void *buffer, size_t len) errno = 0; stream.avail_in = original->read (inbuf, 16384); - if (stream.avail_in == 0) + if (stream.avail_in <= 0) { z_eof = 1; if (original->error ()) { + stream.avail_in = 0; z_err = Z_ERRNO; break; } @@ -408,18 +409,18 @@ compress_gz::peek (void *buffer, size_t len) } } -long +off_t compress_gz::tell () { throw new std::logic_error("compress_gz::tell is not implemented"); } -int -compress_gz::seek (long where, io_stream_seek_t whence) +off_t +compress_gz::seek (off_t where, io_stream_seek_t whence) { if ((whence == IO_SEEK_SET) && (where == 0)) { - int result = original->seek(where, whence); + off_t result = original->seek(where, whence); destroy(); construct(); return result; @@ -566,11 +567,12 @@ compress_gz::get_byte () { errno = 0; stream.avail_in = original->read (inbuf, 16384); - if (stream.avail_in == 0) + if (stream.avail_in <= 0) { z_eof = 1; if (original->error ()) z_err = Z_ERRNO; + stream.avail_in = 0; return EOF; } stream.next_in = inbuf; diff --git a/compress_gz.h b/compress_gz.h index 90073e5ddbbc..c7ae14b228e6 100644 --- a/compress_gz.h +++ b/compress_gz.h @@ -32,8 +32,8 @@ public: virtual ssize_t write (const void *buffer, size_t len); /* read data without removing it from the class's internal buffer */ virtual ssize_t peek (void *buffer, size_t len); - virtual long tell (); - virtual int seek (long where, io_stream_seek_t whence); + virtual off_t tell (); + virtual off_t seek (off_t where, io_stream_seek_t whence); /* try guessing this one */ virtual int error (); /* Find out the next stream name - @@ -80,7 +80,7 @@ private: char *msg; /* error message */ int transparent; /* 1 if input file is not a .gz file */ char mode; /* 'w' or 'r' */ - long startpos; /* start of compressed data in file (header skipped) */ + off_t startpos; /* start of compressed data in file (header skipped) */ }; #endif /* SETUP_COMPRESS_GZ_H */ diff --git a/compress_xz.cc b/compress_xz.cc index d3f4886c3cd9..b91c8a44ab97 100644 --- a/compress_xz.cc +++ b/compress_xz.cc @@ -155,6 +155,9 @@ compress_xz::read (void *buffer, size_t len) { /* no compressed data ready; read some more */ state->in_size = (size_t) this->original->read(state->in_block, state->in_block_size); + /* We don't care for error vs EOF */ + if (state->in_size < 0) + state->in_size = 0; state->in_pos = 0; } @@ -263,18 +266,18 @@ compress_xz::peek (void *buffer, size_t len) return 0; } -long +off_t compress_xz::tell () { throw new std::logic_error("compress_xz::tell is not implemented"); } -int -compress_xz::seek (long where, io_stream_seek_t whence) +off_t +compress_xz::seek (off_t where, io_stream_seek_t whence) { if ((whence == IO_SEEK_SET) && (where == 0)) { - int result = original->seek(where, whence); + off_t result = original->seek(where, whence); destroy (); peeklen = 0; lasterr = 0; diff --git a/compress_xz.h b/compress_xz.h index 31d499c372a4..9be78225fb79 100644 --- a/compress_xz.h +++ b/compress_xz.h @@ -26,8 +26,8 @@ public: virtual ssize_t read (void *buffer, size_t len); virtual ssize_t write (const void *buffer, size_t len); /* not implemented */ virtual ssize_t peek (void *buffer, size_t len); - virtual long tell (); /* not implemented */ - virtual int seek (long where, io_stream_seek_t whence); + virtual off_t tell (); /* not implemented */ + virtual off_t seek (off_t where, io_stream_seek_t whence); virtual int error (); virtual const char *next_file_name () { return NULL; }; virtual int set_mtime (time_t); diff --git a/compress_zstd.cc b/compress_zstd.cc index bb17785423a9..8d6e51f73a6c 100644 --- a/compress_zstd.cc +++ b/compress_zstd.cc @@ -175,18 +175,18 @@ compress_zstd::peek (void *buffer, size_t len) return got; } -long +off_t compress_zstd::tell () { throw new std::logic_error("compress_zstd::tell is not implemented"); } -int -compress_zstd::seek (long where, io_stream_seek_t whence) +off_t +compress_zstd::seek (off_t where, io_stream_seek_t whence) { if ((whence == IO_SEEK_SET) && (where == 0)) { - int result = original->seek(where, whence); + off_t result = original->seek(where, whence); destroy(); create(); return result; diff --git a/compress_zstd.h b/compress_zstd.h index 3303daa4d02f..b9b541e8fb36 100644 --- a/compress_zstd.h +++ b/compress_zstd.h @@ -24,8 +24,8 @@ public: virtual ssize_t read (void *buffer, size_t len); virtual ssize_t write (const void *buffer, size_t len); /* not implemented */ virtual ssize_t peek (void *buffer, size_t len); - virtual long tell (); /* not implemented */ - virtual int seek (long where, io_stream_seek_t whence); + virtual off_t tell (); /* not implemented */ + virtual off_t seek (off_t where, io_stream_seek_t whence); virtual int error (); virtual const char *next_file_name () { return NULL; }; virtual int set_mtime (time_t); diff --git a/gpg-packet.cc b/gpg-packet.cc index 114d07dbe705..7949d756e47e 100644 --- a/gpg-packet.cc +++ b/gpg-packet.cc @@ -215,7 +215,7 @@ walk_packets_1 (struct packet_walker *wlk) char packet_type; long packet_len; enum pkt_cb_resp rv; - size_t newstartpos; + off_t newstartpos; wlk->pfile->seek (wlk->startpos, IO_SEEK_SET); diff --git a/install.cc b/install.cc index fbd28b1cf6ed..628dbd0cbf15 100644 --- a/install.cc +++ b/install.cc @@ -65,9 +65,9 @@ extern ThreeBarProgressPage Progress; -static long long int total_bytes = 0; -static long long int total_bytes_sofar = 0; -static int package_bytes = 0; +static off_t total_bytes = 0; +static off_t total_bytes_sofar = 0; +static off_t package_bytes = 0; static BoolOption NoReplaceOnReboot (false, 'r', "no-replaceonreboot", IDS_HELPTEXT_NO_REPLACEONREBOOT); static BoolOption NoWriteRegistry (false, '\0', "no-write-registry", IDS_HELPTEXT_NO_WRITE_REGISTRY); @@ -107,7 +107,7 @@ class Installer static std_dirs_t StandardDirs[]; Installer(); void initDialog(); - void progress (int bytes); + void progress (off_t bytes); void preremovePerpetual (const std::string& stratum); void preremoveOne (packagemeta &); void uninstallOne (packagemeta &); @@ -142,7 +142,7 @@ Installer::initDialog() } void -Installer::progress (int bytes) +Installer::progress (off_t bytes) { if (package_bytes > 0) Progress.SetBar1 (bytes, package_bytes); diff --git a/io_stream.h b/io_stream.h index 848251c438fd..f19e134fc927 100644 --- a/io_stream.h +++ b/io_stream.h @@ -137,8 +137,8 @@ public: /* read data without removing it from the class's internal buffer */ virtual ssize_t peek (void *buffer, size_t len) = 0; /* ever read the f* functions from libc ? */ - virtual long tell () = 0; - virtual int seek (long, io_stream_seek_t) = 0; + virtual off_t tell () = 0; + virtual off_t seek (off_t, io_stream_seek_t) = 0; /* try guessing this one */ virtual int error () = 0; /* hmm, yet another for the guessing books */ diff --git a/io_stream_cygfile.cc b/io_stream_cygfile.cc index 7fa661c67a12..1ee55f5af4dd 100644 --- a/io_stream_cygfile.cc +++ b/io_stream_cygfile.cc @@ -321,17 +321,41 @@ io_stream_cygfile::mklink (const std::string& _from, const std::string& _to, ssize_t io_stream_cygfile::read (void *buffer, size_t len) { - if (fp) - return fread (buffer, 1, len, fp); - return 0; + ssize_t ret = 0; + + if (len && fp && !feof (fp)) + { + clearerr (fp); + size_t fret = fread (buffer, 1, len, fp); + if (fret < len && ferror (fp)) + { + lasterr = errno; + ret = -1; + } + else + ret = (ssize_t) fret; + } + return ret; } ssize_t io_stream_cygfile::write (const void *buffer, size_t len) { - if (fp) - return fwrite (buffer, 1, len, fp); - return 0; + ssize_t ret = 0; + + if (len && fp) + { + clearerr (fp); + size_t fret = fwrite (buffer, 1, len, fp); + if (fret < len && ferror (fp)) + { + lasterr = errno; + ret = -1; + } + else + ret = (ssize_t) fret; + } + return ret; } ssize_t @@ -339,30 +363,29 @@ io_stream_cygfile::peek (void *buffer, size_t len) { if (fp) { - int pos = ftell (fp); - ssize_t rv = fread (buffer, 1, len, fp); - fseek (fp, pos, SEEK_SET); + off_t pos = ftello (fp); + ssize_t rv = read (buffer, len); + fseeko (fp, pos, SEEK_SET); return rv; } return 0; } -long +off_t io_stream_cygfile::tell () { if (fp) - { - return ftell (fp); - } + return ftello (fp); + return 0; } -int -io_stream_cygfile::seek (long where, io_stream_seek_t whence) +off_t +io_stream_cygfile::seek (off_t where, io_stream_seek_t whence) { if (fp) { - return fseek (fp, where, (int) whence); + return fseeko (fp, where, (int) whence); } lasterr = EBADF; return -1; diff --git a/io_stream_cygfile.h b/io_stream_cygfile.h index b9779094388a..2ffc56e2b86d 100644 --- a/io_stream_cygfile.h +++ b/io_stream_cygfile.h @@ -39,8 +39,8 @@ public: virtual ssize_t write (const void *buffer, size_t len); /* read data without removing it from the class's internal buffer */ virtual ssize_t peek (void *buffer, size_t len); - virtual long tell (); - virtual int seek (long where, io_stream_seek_t whence); + virtual off_t tell (); + virtual off_t seek (off_t where, io_stream_seek_t whence); /* can't guess, oh well */ virtual int error (); virtual int set_mtime (time_t); diff --git a/io_stream_file.cc b/io_stream_file.cc index 938d2d98061f..053229c66fe4 100644 --- a/io_stream_file.cc +++ b/io_stream_file.cc @@ -157,17 +157,41 @@ io_stream_file::mklink (const std::string& from, const std::string& to, ssize_t io_stream_file::read (void *buffer, size_t len) { - if (fp) - return fread (buffer, 1, len, fp); - return 0; + ssize_t ret = 0; + + if (len && fp && !feof (fp)) + { + clearerr (fp); + size_t fret = fread (buffer, 1, len, fp); + if (fret < len && ferror (fp)) + { + lasterr = errno; + ret = -1; + } + else + ret = (ssize_t) fret; + } + return ret; } ssize_t io_stream_file::write (const void *buffer, size_t len) { - if (fp) - return fwrite (buffer, 1, len, fp); - return 0; + ssize_t ret = 0; + + if (len && fp) + { + clearerr (fp); + size_t fret = fwrite (buffer, 1, len, fp); + if (fret < len && ferror (fp)) + { + lasterr = errno; + ret = -1; + } + else + ret = (ssize_t) fret; + } + return ret; } ssize_t @@ -175,31 +199,29 @@ io_stream_file::peek (void *buffer, size_t len) { if (fp) { - int pos = ftell (fp); - ssize_t rv = fread (buffer, 1, len, fp); - fseek (fp, pos, SEEK_SET); + off_t pos = ftello (fp); + ssize_t rv = read (buffer, len); + fseeko (fp, pos, SEEK_SET); return rv; } return 0; } -long +off_t io_stream_file::tell () { if (fp) - { - return ftell (fp); - } + return ftello (fp); + return 0; } -int -io_stream_file::seek (long where, io_stream_seek_t whence) +off_t +io_stream_file::seek (off_t where, io_stream_seek_t whence) { if (fp) - { - return fseek (fp, where, (int) whence); - } + return fseeko (fp, where, (int) whence); + lasterr = EBADF; return -1; } diff --git a/io_stream_file.h b/io_stream_file.h index b1d7f2e98437..3060e843d03f 100644 --- a/io_stream_file.h +++ b/io_stream_file.h @@ -36,8 +36,8 @@ public: virtual ssize_t write (const void *buffer, size_t len); /* read data without removing it from the class's internal buffer */ virtual ssize_t peek (void *buffer, size_t len); - virtual long tell (); - virtual int seek (long where, io_stream_seek_t whence); + virtual off_t tell (); + virtual off_t seek (off_t where, io_stream_seek_t whence); /* can't guess, oh well */ virtual int error (); virtual int set_mtime (time_t); diff --git a/io_stream_memory.cc b/io_stream_memory.cc index cbdaf8372b11..2f876d742634 100644 --- a/io_stream_memory.cc +++ b/io_stream_memory.cc @@ -47,7 +47,7 @@ io_stream_memory::read (void *buffer, size_t len) unsigned char *to = (unsigned char *) buffer; unsigned char *end = to + len; ssize_t count = 0; - while (to < end && pos < length) + while (to < end && pos < (off_t) length) { *to++ = pos_block->data[pos_block_offset++]; count++; diff --git a/io_stream_memory.h b/io_stream_memory.h index a1259f7d4e31..21d3e14fbf60 100644 --- a/io_stream_memory.h +++ b/io_stream_memory.h @@ -28,28 +28,39 @@ class memblock { public: - memblock () : next (0), len (0), data (0) {}; - memblock (size_t size) : next (0), len (size) {data = new unsigned char[size]; if (!data) len = 0;}; + memblock ():next (0), len (0), data (0) + {} + memblock (size_t size):next (0), len (size) + { + data = new unsigned char[size]; + if (!data) + len = 0; + } ~memblock (); memblock *next; size_t len; unsigned char *data; }; -class io_stream_memory :public io_stream +class io_stream_memory:public io_stream { public: - io_stream_memory () : lasterr (0), mtime(0),length (0), head(), tail (&head), pos_block (head.next), pos_block_offset (0), pos (0) {}; + io_stream_memory (): lasterr (0), mtime (0), length (0), head (), + tail (&head), pos_block (head.next), pos_block_offset (0), pos (0) + {} /* set the modification time of a file - returns 1 on failure * may distrupt internal state - use after all important io is complete */ virtual int set_mtime (time_t newmtime) - {mtime = newmtime; return 0;}; + { + mtime = newmtime; + return 0; + } /* get the mtime for a file TODO make this a stat(0 style call */ - virtual time_t get_mtime () {return mtime;}; - virtual mode_t get_mode () {return 0;}; + virtual time_t get_mtime () { return mtime; } + virtual mode_t get_mode () { return 0; } /* returns the _current_ size. */ - virtual size_t get_size () {return length;}; + virtual size_t get_size () { return length; } /* read data (duh!) */ virtual ssize_t read (void *buffer, size_t len); /* provide data to (double duh!) */ @@ -57,14 +68,40 @@ public: /* read data without removing it from the class's internal buffer */ virtual ssize_t peek (void *buffer, size_t len); /* ever read the f* functions from libc ? */ - virtual long tell () {return pos;}; - virtual int seek (long where, io_stream_seek_t whence) { if (whence != IO_SEEK_SET) { lasterr = EINVAL; return -1;} ssize_t count=0; pos = 0; pos_block = head.next; pos_block_offset = 0; while (count < where && pos < length) {pos_block_offset++; if (pos_block_offset == pos_block->len) {pos_block = pos_block->next; pos_block_offset = 0;}pos++;count++;}return 0;}; - + virtual off_t tell () + { + return pos; + } + virtual off_t seek (off_t where, io_stream_seek_t whence) + { + if (whence != IO_SEEK_SET) + { + lasterr = EINVAL; + return -1; + } + ssize_t count = 0; + pos = 0; + pos_block = head.next; + pos_block_offset = 0; + while (count < where && pos < (off_t) length) + { + pos_block_offset++; + if (pos_block_offset == pos_block->len) + { + pos_block = pos_block->next; + pos_block_offset = 0; + } + pos++; + count++; + } + return 0; + } + /* try guessing this one */ virtual int error (); // virtual const char* next_file_name() = NULL; /* if you are still needing these hints... give up now! */ - virtual ~ io_stream_memory (); + virtual ~io_stream_memory (); private: int lasterr; time_t mtime; @@ -73,7 +110,7 @@ private: memblock *tail; memblock *pos_block; size_t pos_block_offset; - size_t pos; + off_t pos; }; #endif /* SETUP_IO_STREAM_MEMORY_H */ diff --git a/threebar.cc b/threebar.cc index ff4c5cb356c1..bc356c0a2357 100644 --- a/threebar.cc +++ b/threebar.cc @@ -130,14 +130,14 @@ ThreeBarProgressPage::SetText4 (unsigned int id) } void -ThreeBarProgressPage::SetBar1 (long progress, long max) +ThreeBarProgressPage::SetBar1 (off_t progress, off_t max) { int percent = (int) (100.0 * ((double) progress) / (double) max); SendMessage (ins_pprogress, PBM_SETPOS, (WPARAM) percent, 0); } void -ThreeBarProgressPage::SetBar2 (long long progress, long long max) +ThreeBarProgressPage::SetBar2 (off_t progress, off_t max) { int percent = (int) (100.0 * ((double) progress) / (double) max); SendMessage (ins_iprogress, PBM_SETPOS, (WPARAM) percent, 0); @@ -149,7 +149,7 @@ ThreeBarProgressPage::SetBar2 (long long progress, long long max) } void -ThreeBarProgressPage::SetBar3 (long progress, long max) +ThreeBarProgressPage::SetBar3 (off_t progress, off_t max) { int percent = (int) (100.0 * ((double) progress) / (double) max); SendMessage (ins_diskfull, PBM_SETPOS, (WPARAM) percent, 0); diff --git a/threebar.h b/threebar.h index c361eed8f9ff..d7944e5e7af3 100644 --- a/threebar.h +++ b/threebar.h @@ -80,9 +80,9 @@ public: void SetText3 (unsigned int id); void SetText4 (unsigned int id); - void SetBar1 (long progress, long max = 100); - void SetBar2 (long long progress, long long max = 100); - void SetBar3 (long progress, long max = 100); + void SetBar1 (off_t progress, off_t max = 100); + void SetBar2 (off_t progress, off_t max = 100); + void SetBar3 (off_t progress, off_t max = 100); void SetActivateTask (int t) {