aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2020-03-01 15:18:15 -0600
committerRob Landley <rob@landley.net>2020-03-01 15:18:15 -0600
commite8705902647ae62bdf3c7605d76be725ef385a63 (patch)
tree5c0dad66cc05ecb2bbc2d4660cf33cd78b3560e8 /lib
parent1a79bd562843eab3d2b630249719fdaffb06c641 (diff)
downloadtoybox-e8705902647ae62bdf3c7605d76be725ef385a63.tar.gz
Park Ju Hyung pointed out the fast path of fdlength() was commented out.
(Update to the 64 bit API while we're there. And yes, I checked in the kernel, it's 512 byte units.)
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/lib.c b/lib/lib.c
index b57a5691..2a4cd8c5 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -347,6 +347,7 @@ int stridx(char *haystack, char needle)
}
// Convert utf8 sequence to a unicode wide character
+// returns bytes consumed, or -1 if err, or -2 if need more data.
int utf8towc(wchar_t *wc, char *str, unsigned len)
{
unsigned result, mask, first;
@@ -472,13 +473,12 @@ off_t fdlength(int fd)
{
struct stat st;
off_t base = 0, range = 1, expand = 1, old;
+ unsigned long long size;
if (!fstat(fd, &st) && S_ISREG(st.st_mode)) return st.st_size;
// If the ioctl works for this, return it.
- // TODO: is blocksize still always 512, or do we stat for it?
- // unsigned int size;
- // if (ioctl(fd, BLKGETSIZE, &size) >= 0) return size*512L;
+ if (ioctl(fd, BLKGETSIZE64, &size) >= 0) return size<<9;
// If not, do a binary search for the last location we can read. (Some
// block devices don't do BLKGETSIZE right.) This should probably have