aboutsummaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'file.c')
-rw-r--r--file.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/file.c b/file.c
new file mode 100644
index 0000000..6b70f5e
--- /dev/null
+++ b/file.c
@@ -0,0 +1,32 @@
+#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;
+}
+
+FILE *
+file_open(const char * const path, const char * const mode)
+{
+ /* TODO: odstranit tuto funkciu? */
+ FILE * f = fopen(path, mode);
+ return f;
+}