aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-09-19 18:03:17 +0200
committerMattias Andrée <maandree@kth.se>2024-09-19 18:03:17 +0200
commit44cff01e5bbe04ff991ede843e96f0c2d83d20c6 (patch)
treef889f60eca251d716489e3b30994c435c00dbfa2 /io.c
parentm fixes (diff)
downloaddeadshred-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 '')
-rw-r--r--io.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/io.c b/io.c
new file mode 100644
index 0000000..6ee9e29
--- /dev/null
+++ b/io.c
@@ -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;
+}