1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

Change how read and write errors are detected on fstream based streams.

This commit is contained in:
Peter Howkins 2018-03-21 01:01:09 +00:00
parent 490890cd23
commit abd209a83c
2 changed files with 12 additions and 6 deletions

View file

@ -67,7 +67,8 @@ void zip::compress(const buffer& uncompressed, buffer& compressed)
if ( !out )
throw(streamException(out.rdstate()));
if ( out.write(uncompressed.get_base(), uncompressed.content_sz()) == 0 )
out.write(uncompressed.get_base(), uncompressed.content_sz());
if ( out.bad() )
throw(streamException(out.rdstate()));
out.close();
@ -84,7 +85,8 @@ void zip::compress(const buffer& uncompressed, buffer& compressed)
compressed.expand_chunk(x);
if ( in.read(compressed.get_base(), x) == 0 || x != in.gcount() )
in.read(compressed.get_base(), x);
if ( in.bad() || x != in.gcount() )
throw(streamException(in.rdstate()));
compressed.set_content_sz(x);
@ -102,7 +104,8 @@ void zip::decompress(buffer& compressed, buffer& uncompressed)
if ( !out )
throw(streamException(out.rdstate()));
if ( out.write(compressed.get_base(), compressed.content_sz()) == 0 )
out.write(compressed.get_base(), compressed.content_sz());
if ( out.bad() )
throw(streamException(out.rdstate()));
out.close();
@ -119,7 +122,8 @@ void zip::decompress(buffer& compressed, buffer& uncompressed)
uncompressed.expand_chunk(x);
if ( in.read(uncompressed.get_base(), x) == 0 || x != in.gcount() )
in.read(uncompressed.get_base(), x);
if ( in.bad() || x != in.gcount() )
throw(streamException(in.rdstate()));
uncompressed.set_content_sz(x);

View file

@ -208,12 +208,14 @@ unixf_storage::readString(mmdb_pos_t loc, char* base, int len, int str_off)
int offset = int(loc) + str_off;
if ( seekg( offset, ios::beg ) == 0 ) {
seekg( offset, ios::beg );
if ( bad() ) {
MESSAGE(cerr, "seekg failed");
throw(streamException(fstream::rdstate()));
}
if ( read( base, len ) == 0 || len != fstream::gcount() ) {
read( base, len );
if ( bad() || len != fstream::gcount() ) {
MESSAGE(cerr, "read() failed");
throw(streamException(fstream::rdstate()));
}