aboutsummaryrefslogtreecommitdiffstats
path: root/src/file/file.c
blob: 862c1ea1b547b3f5e03bdfe1b198fdf0c6452473 (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
33
34
/*
 * file/file.c
 * File related operations
 *
 * Erik Liodden
 */

#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "file.h"

/* get_file_size: return size of file with filename 'name' */
uint64_t get_file_size(char *name)
{
	uint64_t size;
	struct stat st;
	stat(name, &st);
	size = st.st_size;
	return size;
}

/* open_file: open file and return pointer to the file if it exists. */
FILE *open_file(char *name, char *mode)
{
	FILE *fp;
	fp = fopen(name, mode);
	if (fp == NULL) {
		perror("cant open file");
		exit(1);
	}
	return fp;
}