diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-09-22 18:28:42 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-09-22 18:28:42 +0000 |
commit | eea7432ba4a196ccbaba981b96af8ff8af0d86d0 (patch) | |
tree | 5b9333e8a64953bc8baa2e09d08edeb3a24ec589 /apps/graphics/tiff/tiff_utils.c | |
parent | 742308f3e3646dd27ef9679ba2ae8756a2a64f7c (diff) | |
download | px4-nuttx-eea7432ba4a196ccbaba981b96af8ff8af0d86d0.tar.gz px4-nuttx-eea7432ba4a196ccbaba981b96af8ff8af0d86d0.tar.bz2 px4-nuttx-eea7432ba4a196ccbaba981b96af8ff8af0d86d0.zip |
TIFF library now passes its unit test
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3970 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'apps/graphics/tiff/tiff_utils.c')
-rw-r--r-- | apps/graphics/tiff/tiff_utils.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/apps/graphics/tiff/tiff_utils.c b/apps/graphics/tiff/tiff_utils.c index 264219520..66599db8b 100644 --- a/apps/graphics/tiff/tiff_utils.c +++ b/apps/graphics/tiff/tiff_utils.c @@ -144,12 +144,14 @@ uint32_t tiff_get32(FAR uint8_t *src) * count - The number of bytes to write * * Returned Value: - * Zero (OK) on success. A negated errno value on failure. + * On success, then number of bytes read; Zero is returned on EOF. + * Otherwise, a negated errno value on failure. * ****************************************************************************/ -int tiff_read(int fd, FAR void *buffer, size_t count) +ssize_t tiff_read(int fd, FAR void *buffer, size_t count) { + size_t ntotal; ssize_t nbytes; int errval; @@ -157,11 +159,14 @@ int tiff_read(int fd, FAR void *buffer, size_t count) * or (2) until an irrecoverble error occurs. */ - while (count > 0) + for (ntotal = 0; ntotal < count; ) { - /* Do the read */ + /* Do the read. The number of bytes left to read is the total + * requested size (count) minus the amount that we have alread read + * (ntotal). + */ - nbytes = read(fd, buffer, count); + nbytes = read(fd, buffer, count-ntotal); /* Check for an error */ @@ -180,17 +185,26 @@ int tiff_read(int fd, FAR void *buffer, size_t count) } } - /* What if read returns some number of bytes other than the requested number? */ + /* Zero is a special case and means that the end of file was encountered. */ + + else if (nbytes == 0) + { + break; + } + + /* What if read returns some number of bytes other than the requested number? + * This probably means that the end-of-file will be encountered the next time + * that we call read(). + */ else { - DEBUGASSERT(nbytes < count && nbytes != 0); buffer += nbytes; - count -= nbytes; + ntotal += nbytes; } } - return OK; + return ntotal; } /**************************************************************************** @@ -245,7 +259,7 @@ int tiff_write(int fd, FAR const void *buffer, size_t count) else { - DEBUGASSERT(nbytes < count && nbytes != 0); + DEBUGASSERT(nbytes == count); buffer += nbytes; count -= nbytes; } |