aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2007-01-25 16:10:37 -0500
committerRob Landley <rob@landley.net>2007-01-25 16:10:37 -0500
commitb3a3382abf49573ba1f79d22417e9fc50125d28d (patch)
treea97a6dc5111e9701b8a4cd32457dff8191feefec /lib
parent6b7092fd084070daeef5aeb60b608a633d56f252 (diff)
downloadtoybox-b3a3382abf49573ba1f79d22417e9fc50125d28d.tar.gz
The fdlength() ioctl apparently doesn't work on files (and the lseek trick
doesn't work on some devices, and we can't always tell _when_ it failed), so go to the binary search for now.
Diffstat (limited to 'lib')
-rw-r--r--lib/functions.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/lib/functions.c b/lib/functions.c
index 88258ddc..7efc2df9 100644
--- a/lib/functions.c
+++ b/lib/functions.c
@@ -397,18 +397,6 @@ char *itoa(int n)
return itoa_buf;
}
-off_t fdlength(int fd)
-{
- int size;
-
- if (ioctl(fd, BLKGETSIZE, &size) >= 0) return size*512L;
- return -1;
-}
-
-/*
- This might be of use or might not. Unknown yet...
-
-
// Return how long the file at fd is, if there's any way to determine it.
off_t fdlength(int fd)
{
@@ -430,7 +418,7 @@ off_t fdlength(int fd)
// If we can read from the current location, it's bigger.
- if (lseek(fd, pos, 0)>=0 && safe_read(fd, &temp, 1)==1) {
+ if (lseek(fd, pos, 0)>=0 && read(fd, &temp, 1)==1) {
if (bottom == top) bottom = top = (top+1) * 2;
else bottom = pos;
@@ -447,6 +435,9 @@ off_t fdlength(int fd)
return pos + 1;
}
+/*
+ This might be of use or might not. Unknown yet...
+
// Read contents of file as a single freshly allocated nul-terminated string.
char *readfile(char *name)
{