/* 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; }