summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Endsley <mendsley@gmail.com>2012-05-14 02:10:45 -0700
committerMatthew Endsley <mendsley@gmail.com>2012-05-14 02:10:45 -0700
commit68453c9e9765d737f789470cd0bf3b98f3dce1af (patch)
treec03e14a011d144b257a29e5cb594aa9cf0af72d0
parent15a8a2503e3a84e5a403c1ddffb1d0cace5f1702 (diff)
downloadbsdiff-68453c9e9765d737f789470cd0bf3b98f3dce1af.tar.gz
updating stream.read to return 0 on success a non-zero on failure
-rw-r--r--bspatch.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/bspatch.c b/bspatch.c
index d9929b8..9871cff 100644
--- a/bspatch.c
+++ b/bspatch.c
@@ -69,15 +69,13 @@ int bspatch(const struct bspatch_request req)
uint8_t buf[8];
int64_t oldpos,newpos;
int64_t ctrl[3];
- int64_t lenread;
int64_t i;
oldpos=0;newpos=0;
while(newpos<req.newsize) {
/* Read control data */
for(i=0;i<=2;i++) {
- lenread = req.stream.read(&req.stream, buf, 8);
- if (lenread != 8)
+ if (req.stream.read(&req.stream, buf, 8))
return -1;
ctrl[i]=offtin(buf);
};
@@ -87,8 +85,7 @@ int bspatch(const struct bspatch_request req)
return -1;
/* Read diff string */
- lenread = req.stream.read(&req.stream, req.new + newpos, ctrl[0]);
- if (lenread != ctrl[0])
+ if (req.stream.read(&req.stream, req.new + newpos, ctrl[0]))
return -1;
/* Add old data to diff string */
@@ -105,8 +102,7 @@ int bspatch(const struct bspatch_request req)
return -1;
/* Read extra string */
- lenread = req.stream.read(&req.stream, req.new + newpos, ctrl[1]);
- if (lenread != ctrl[1])
+ if (req.stream.read(&req.stream, req.new + newpos, ctrl[1]))
return -1;
/* Adjust pointers */
@@ -136,10 +132,10 @@ static int bz2_read(const struct bspatch_stream* stream, void* buffer, int lengt
bz2 = (BZFILE*)stream->opaque;
n = BZ2_bzRead(&bz2err, bz2, buffer, length);
- if (n == 0)
+ if (n != length)
return -1;
- return n;
+ return 0;
}
int main(int argc,char * argv[])