diff options
| author | Alex Valavanis <valavanisalex@gmail.com> | 2014-03-30 22:08:49 +0000 |
|---|---|---|
| committer | Alex Valavanis <valavanisalex@gmail.com> | 2014-03-30 22:08:49 +0000 |
| commit | a9c82bf5e7a7cd37cef0500317e4cfa095970d56 (patch) | |
| tree | ac487342d1db95ff6063cc7c571401132c836985 /src | |
| parent | Replaced one more operator. (diff) | |
| download | inkscape-a9c82bf5e7a7cd37cef0500317e4cfa095970d56.tar.gz inkscape-a9c82bf5e7a7cd37cef0500317e4cfa095970d56.zip | |
inkjar: Handle return values correctly
(bzr r13239)
Diffstat (limited to 'src')
| -rw-r--r-- | src/io/inkjar.cpp | 44 | ||||
| -rw-r--r-- | src/io/inkjar.h | 6 |
2 files changed, 25 insertions, 25 deletions
diff --git a/src/io/inkjar.cpp b/src/io/inkjar.cpp index b31b98336..fb1fedf55 100644 --- a/src/io/inkjar.cpp +++ b/src/io/inkjar.cpp @@ -64,12 +64,11 @@ namespace Inkjar { -JarFile::JarFile(gchar const*new_filename) -{ - _filename = g_strdup(new_filename); - _last_filename = NULL; - fd = NULL; -} +JarFile::JarFile(gchar const*new_filename) : + _file(NULL), + _filename(g_strdup(new_filename)), + _last_filename(NULL) +{} //fixme: the following should probably just return a const gchar* and not // use strdup @@ -104,7 +103,7 @@ bool JarFile::init_inflation() bool JarFile::open() { - if ((fd = fopen(_filename, "r")) < 0) { + if ((_file = fopen(_filename, "r")) == NULL) { fprintf(stderr, "open failed.\n"); return false; } @@ -116,7 +115,7 @@ bool JarFile::open() bool JarFile::close() { - if (fd >= 0 && !fclose(fd)) { + if (_file != NULL && (fclose(_file) == 0)) { inflateEnd(&_zs); return true; } @@ -257,7 +256,7 @@ GByteArray *JarFile::get_next_file_contents() if (method == 8 || flags & 0x0008) { unsigned int file_length = 0;//uncompressed file length - fseek(fd, eflen, SEEK_CUR); + fseek(_file, eflen, SEEK_CUR); guint8 *file_data = get_compressed_file(compressed_size, file_length, crc, flags); if (file_data == NULL) { @@ -275,7 +274,7 @@ GByteArray *JarFile::get_next_file_contents() } g_byte_array_append(gba, file_data, compressed_size); } else { - fseek(fd, compressed_size+eflen, SEEK_CUR); + fseek(_file, compressed_size+eflen, SEEK_CUR); g_byte_array_free(gba, FALSE); return NULL; } @@ -314,7 +313,7 @@ guint8 *JarFile::get_uncompressed_file(guint32 compressed_size, guint32 crc, std::printf("%u bytes written\n", out_a); #endif } - fseek(fd, eflen, SEEK_CUR); + fseek(_file, eflen, SEEK_CUR); g_free(bytes); if (!check_crc(crc, crc2, flags)) { @@ -326,10 +325,10 @@ guint8 *JarFile::get_uncompressed_file(guint32 compressed_size, guint32 crc, return bytes; } -int JarFile::read(guint8 *buf, int count) +int JarFile::read(guint8 *buf, unsigned int count) { - int nbytes; - if ((nbytes = fread(buf, 1, count, fd)) != count) { + size_t nbytes; + if ((nbytes = fread(buf, 1, count, _file)) != count) { fprintf(stderr, "read error\n"); exit(1); return 0; @@ -347,22 +346,22 @@ guint8 *JarFile::get_compressed_file(guint32 compressed_size, guint8 in_buffer[RDSZ]; guint8 out_buffer[RDSZ]; - int nbytes; + size_t nbytes; unsigned int leftover_in = compressed_size; GByteArray *gba = g_byte_array_new(); _zs.avail_in = 0; guint32 crc = crc32(0, Z_NULL, 0); - do { - + do { if (!_zs.avail_in) { - - if ((nbytes = fread(in_buffer, 1, - (leftover_in < RDSZ ? leftover_in : RDSZ), fd)) - < 0) { + nbytes = fread(in_buffer, 1, + (leftover_in < RDSZ ? leftover_in : RDSZ), _file); + + if(ferror(_file) != 0) { fprintf(stderr, "jarfile read error"); } + _zs.avail_in = nbytes; _zs.next_in = in_buffer; crc = crc32(crc, in_buffer, _zs.avail_in); @@ -453,7 +452,7 @@ JarFile& JarFile::operator=(JarFile const& rhs) _last_filename = NULL; else _last_filename = g_strdup(rhs._last_filename); - fd = rhs.fd; + _file = rhs._file; return *this; } @@ -545,3 +544,4 @@ int main(int argc, char *argv[]) return 0; } #endif +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/io/inkjar.h b/src/io/inkjar.h index ee6e33526..637c05d80 100644 --- a/src/io/inkjar.h +++ b/src/io/inkjar.h @@ -91,7 +91,7 @@ typedef uint32_t ub4; class JarFile { public: - JarFile() : fd(NULL), _filename(NULL), _last_filename(NULL) {} + JarFile() : _file(NULL), _filename(NULL), _last_filename(NULL) {} virtual ~JarFile(); JarFile(gchar const *new_filename); @@ -99,14 +99,14 @@ public: gchar *get_last_filename() const; bool open(); bool close(); - int read(guint8 *buf, int count); + int read(guint8 *buf, unsigned int count); JarFile(JarFile const &rhs); JarFile &operator=(JarFile const &rhs); private: - FILE *fd; // File descriptor + FILE *_file; // File descriptor gchar *_filename; z_stream _zs; gchar *_last_filename; |
