changeset 310:8b8116214b1c

Roberto Foglietta pointed out that readall() needs fdlength() to restore the original position before exiting.
author Rob Landley <rob@landley.net>
date Fri, 18 Jul 2008 05:43:44 -0500
parents 79a61cd58596
children 962bbf7341f8
files lib/lib.c
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/lib/lib.c	Fri Jul 18 04:15:59 2008 -0500
+++ b/lib/lib.c	Fri Jul 18 05:43:44 2008 -0500
@@ -474,7 +474,7 @@
 // Return how long the file at fd is, if there's any way to determine it.
 off_t fdlength(int fd)
 {
-	off_t bottom = 0, top = 0, pos;
+	off_t bottom = 0, top = 0, pos, old;
 	int size;
 
 	// If the ioctl works for this, return it.
@@ -485,6 +485,7 @@
 	// block devices don't do BLKGETSIZE right.)  This should probably have
 	// a CONFIG option...
 
+	old = lseek(fd, 0, SEEK_CUR);
 	do {
 		char temp;
 
@@ -506,6 +507,8 @@
 		}
 	} while (bottom + 1 != top);
 
+	lseek(fd, old, SEEK_SET);
+
 	return pos + 1;
 }