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

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


/* 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) {
		error(errno, "cant open file");
		exit(1);
	}
	return fp;
}

/* get_file_info: return struct with info about file */
struct stat *get_file_info(char *name)
{
	struct stat *stbuf = malloc(sizeof(struct stat));
	stat(name, stbuf);
	return stbuf;
}