diff --git a/include/stdex/idrec.h b/include/stdex/idrec.h index 59c995907..04fdeea8c 100644 --- a/include/stdex/idrec.h +++ b/include/stdex/idrec.h @@ -40,16 +40,15 @@ namespace stdex { template inline bool ignore(std::istream& stream) { - T_SIZE size; - // Read record size. - stream.read(&size, sizeof(size)); - if (stream.fail()) return false; + T_SIZE size; + stream.read((char*)&size, sizeof(size)); + if (!stream.good()) return false; // Skip the record data. size += (T_SIZE)(ALIGN - size) % ALIGN; stream.ignore(size); - if (stream.fail()) return false; + if (!stream.good()) return false; return true; } @@ -72,8 +71,8 @@ namespace stdex { T_ID _id; while (end == (std::streamoff)-1 || stream.tellg() < end) { - stream.read(&_id, sizeof(_id)); - if (stream.fail()) return false; + stream.read((char*)&_id, sizeof(_id)); + if (!stream.good()) return false; if (_id == id) { // The record was found. @@ -237,13 +236,9 @@ inline std::ostream& operator <<(std::ostream& stream, const stdex::idrec::recor { // Parameter r does not need to be passed by reference. It has only one field (data), which is a reference itself already. The id field is static anyway. - if (stream.fail()) return stream; std::streamoff start = r.open(stream); - if (stream.fail()) return stream; stream << r.data; - - if (stream.fail()) return stream; r.close(stream, start); return stream; @@ -265,15 +260,12 @@ inline std::istream& operator >>(std::istream& stream, stdex::idrec::record> r.data; - } + stream >> r.data; // TODO: operator >> should not read past the record data! Make a size limited stream and read from it instead. size += (T_SIZE)(ALIGN - size) % ALIGN; stream.seekg(start + size);