-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadfile.h
31 lines (27 loc) · 808 Bytes
/
readfile.h
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
#ifndef READFILE_H
#define READFILE_H
struct file_data {
int lines;
long bytes;
char* name;
char* content;
};
/**
* Read a text file from disk up to a maximum size. This gathers the file content and metadata like the number of lines
* and size in bytes.
*
* Note that the function allocates memory for the file_data and its content. Therefore, it's the caller's
* responsibility to free these later.
*
* @param name Name of the file to read
* @param max_size Maximum size in bytes to read from the file
* @return A pointer to a file_data struct, or NULL if an error occurs.
*/
struct file_data* read_file(char* name, long max_size);
/**
* Free the memory allocated by read_file.
*
* @param f Pointer to a file_data struct
*/
void free_file_data(struct file_data *f);
#endif