diff options
author | Mattias Andrée <maandree@kth.se> | 2024-09-19 18:03:17 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-09-19 18:03:17 +0200 |
commit | 44cff01e5bbe04ff991ede843e96f0c2d83d20c6 (patch) | |
tree | f889f60eca251d716489e3b30994c435c00dbfa2 /io.c | |
parent | m fixes (diff) | |
download | deadshred-44cff01e5bbe04ff991ede843e96f0c2d83d20c6.tar.gz deadshred-44cff01e5bbe04ff991ede843e96f0c2d83d20c6.tar.bz2 deadshred-44cff01e5bbe04ff991ede843e96f0c2d83d20c6.tar.xz |
Split into multiple C files
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'io.c')
-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; +} |