summaryrefslogtreecommitdiffstats
path: root/decoder.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 11:45:45 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 11:45:45 +0000
commit5e8398a39d8758cb4dee9a43f92ac958277e0ebd (patch)
tree10ba2517467532e4a002f47cc32732f1f335eae0 /decoder.cc
parentAdding upstream version 1.16~pre1. (diff)
downloadlziprecover-upstream/1.16_pre2.tar.xz
lziprecover-upstream/1.16_pre2.zip
Adding upstream version 1.16~pre2.upstream/1.16_pre2
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'decoder.cc')
-rw-r--r--decoder.cc23
1 files changed, 12 insertions, 11 deletions
diff --git a/decoder.cc b/decoder.cc
index c0defc8..75d70d0 100644
--- a/decoder.cc
+++ b/decoder.cc
@@ -54,19 +54,20 @@ void Pretty_print::operator()( const char * const msg, FILE * const f ) const
/* Returns the number of bytes really read.
If (returned value < size) and (errno == 0), means EOF was reached.
*/
-int readblock( const int fd, uint8_t * const buf, const int size )
+long readblock( const int fd, uint8_t * const buf, const long size )
{
- int rest = size;
+ long pos = 0;
errno = 0;
- while( rest > 0 )
+ while( pos < size )
{
- const int n = read( fd, buf + size - rest, rest );
- if( n > 0 ) rest -= n;
+ const int sz = std::min( 65536L, size - pos );
+ const int n = read( fd, buf + pos, sz );
+ if( n > 0 ) pos += n;
else if( n == 0 ) break; // EOF
else if( errno != EINTR ) break;
errno = 0;
}
- return size - rest;
+ return pos;
}
@@ -75,16 +76,16 @@ int readblock( const int fd, uint8_t * const buf, const int size )
*/
int writeblock( const int fd, const uint8_t * const buf, const int size )
{
- int rest = size;
+ int pos = 0;
errno = 0;
- while( rest > 0 )
+ while( pos < size )
{
- const int n = write( fd, buf + size - rest, rest );
- if( n > 0 ) rest -= n;
+ const int n = write( fd, buf + pos, size - pos );
+ if( n > 0 ) pos += n;
else if( n < 0 && errno != EINTR ) break;
errno = 0;
}
- return size - rest;
+ return pos;
}