diff options
Diffstat (limited to '')
-rw-r--r-- | io.c | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -0,0 +1,25 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + + +off_t +filesize(int fd, const char *fname) +{ + struct stat st; + + if (fstat(fd, &st)) + eprintf("fstat %s:", fname); + + switch (st.st_mode & S_IFMT) { + case S_IFREG: + break; + case S_IFBLK: + if (ioctl(fd, BLKGETSIZE64, &st.st_size) < 0) + eprintf("ioctl %s BLKGETSIZE64:", fname); + break; + default: + eprintf("%s: not a regular file or block device", fname); + } + + return st.st_size; +} |