aboutsummaryrefslogtreecommitdiff
path: root/src/file.c
diff options
context:
space:
mode:
authorJan Sucan <jan@jansucan.com>2021-05-02 10:19:23 +0200
committerJan Sucan <jan@jansucan.com>2021-05-02 10:20:29 +0200
commit02ffe0ed4113e7b479197d0ba1b160e6280b4099 (patch)
treec7a3573039ba02983eec38267d61d86e1965bbab /src/file.c
parent36a92af6ee3c20c93835a34ddeb148c34ccf023c (diff)
Move the source files to a src directory
Diffstat (limited to 'src/file.c')
-rw-r--r--src/file.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/file.c b/src/file.c
new file mode 100644
index 0000000..c6823b9
--- /dev/null
+++ b/src/file.c
@@ -0,0 +1,23 @@
+#include <errno.h>
+#include <string.h>
+
+#include "file.h"
+#include "print.h"
+
+long
+file_size(FILE *const file)
+{
+ fpos_t p;
+
+ if ((fgetpos(file, &p) != 0) || (fseek(file, 0L, SEEK_END) != 0)) {
+ return -1;
+ }
+
+ const long size = ftell(file);
+
+ if (fsetpos(file, &p) != 0) {
+ return -1;
+ }
+
+ return size;
+}