From e8705902647ae62bdf3c7605d76be725ef385a63 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 1 Mar 2020 15:18:15 -0600 Subject: 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.) --- lib/lib.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') 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 -- cgit v1.2.3