Change how read and write errors are detected on fstream based streams.
authorPeter Howkins <flibble@users.sf.net>
Wed, 21 Mar 2018 01:01:09 +0000 (01:01 +0000)
committerPeter Howkins <flibble@users.sf.net>
Wed, 21 Mar 2018 01:01:09 +0000 (01:01 +0000)
cde/programs/dtinfo/DtMmdb/compression/zip.C
cde/programs/dtinfo/DtMmdb/storage/unixf_storage.C

index 1b8cb4f6d8ebc190ead8adc64a0160a350b2d60d..ad88c39ef6900219777ad134796f8c508499eee8 100644 (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);
index c87dae6068daab43a4fb87b41ce2236e05e89a1d..fd55d1704054f77a00a9347129b6e4c7e1c77502 100644 (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()));
    }