-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomFileFunctions.c
More file actions
54 lines (47 loc) · 995 Bytes
/
Copy pathcustomFileFunctions.c
File metadata and controls
54 lines (47 loc) · 995 Bytes
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
#include "customFileFunctions.h"
int checkFileHeader(FILE *unknown, const char *refernceHeader)
{
char fileHeader[200];
fscanf(unknown, "%s", fileHeader);
if ( strcmp(fileHeader, refernceHeader) )
{
return HEADERS_MISMATCH;
}
else
{
return HEADERS_MATCH;
}
}
int loadFile(FILE **file,const char *path,const char *header)
{
*file = fopen(path, "rb");
if (*file == NULL)
{
return FILE_NOT_OPEN;
}
if ( checkFileHeader(*file, header) == HEADERS_MISMATCH )
{
fclose(*file);
return INCORRECT_FILE;
}
return FILE_LOADED;
}
int getFileType(const char *path)
{
if (NULL != strstr(path, ".table"))
{
return TABLE_TYPE_FILE;
}
else if (NULL != strstr(path, ".bin"))
{
return BINARY_TYPE_FILE;
}
else if (NULL != strstr(path, ".txt"))
{
return TEXT_TYPE_FILE;
}
else
{
return UNKNOWN_FILE_TYPE;
}
}