diff options
author | Rob Landley <rob@landley.net> | 2020-03-01 15:18:15 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-03-01 15:18:15 -0600 |
commit | e8705902647ae62bdf3c7605d76be725ef385a63 (patch) | |
tree | 5c0dad66cc05ecb2bbc2d4660cf33cd78b3560e8 | |
parent | 1a79bd562843eab3d2b630249719fdaffb06c641 (diff) | |
download | toybox-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.)
-rw-r--r-- | lib/lib.c | 6 |
1 files changed, 3 insertions, 3 deletions
@@ -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 |