aboutsummaryrefslogtreecommitdiff
path: root/file.c
blob: 6b70f5e93ea6f15c4aa1535e2064620cebbf8b1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;
}