-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.h
54 lines (41 loc) · 1.36 KB
/
file.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _FILE_H
#define _FILE_H
#include <stdint.h>
#include <stdio.h>
#define KIBIBYTE 1024
#define MEBIBYTE 1048576
#define FILE_MAX_DATA_SIZE (128 * MEBIBYTE)
// file list structure
typedef struct{
char *path; // file path
char *name; // file name
char *ext; // file extension
uint64_t file_size; // total file size
FILE *fp; // file pointer
uint64_t cursor; // current file cursor position
uint8_t split; // split file flag
uint8_t eof; // eof file flag
uint8_t *data; // file data
uint32_t data_size; // data size -> max FILE_MAX_DATA_SIZE
}s_File;
// Create or add a file to the file list
s_File* file_Add(s_File *f, int *size_of_files, char *name, char *path);
// Initialize new file (memset to 0)
void file_Init(s_File *f);
// Set the file name
void file_SetName(s_File *f, char *name);
// Set the file path
void file_SetPath(s_File *f, char *path);
// Get list of files from <dir> folder and subfolders
s_File* file_GetList(s_File *f, int *size_of_files, char *dir);
// Printf the file list
void file_PrintList(s_File *f, int size);
// Open file
void file_Open(s_File *f);
// Read file to data buffer
void file_Read(s_File *f);
// Close file
void file_Close(s_File *f);
// Free file path, name and extension
void file_Free(s_File *f, int size_of_files);
#endif // _FILE_H