aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
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;
+}