-
Notifications
You must be signed in to change notification settings - Fork 42
/
esifile.c
52 lines (42 loc) · 912 Bytes
/
esifile.c
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
#include "esifile.h"
#include <stdio.h>
#include <string.h>
const char *efile_suffix(const char *file)
{
const char *suffix = file;
const char *f = file;
while (*f != '\0') {
if (*f == '.')
suffix = f+1;
f++;
}
return suffix;
}
enum eFileType efile_type(const char *file)
{
enum eFileType type = UNKNOWN;
// - file ending (.bin or .xml)
// - first 4 bytes (?) -> "<?xml" or binary bits
const char *suffix = efile_suffix(file);
if (suffix == NULL) {
printf("Warning no suffix\n");
type = UNKNOWN;
} else if (strncmp(suffix, "xml", 3) == 0) {
type = XML;
} else if (strncmp(suffix, "bin", 3) == 0) {
type = SIIBIN;
} else {
type = UNKNOWN;
}
FILE *fh = fopen(file, "r");
char foo[7];
char *ret = fgets(foo, 5, fh);
fclose(fh);
if ((ret != NULL) && (strncmp(foo, "<?xml", 5) == 0)) {
if (type != XML)
type = UNKNOWN;
} else {
type = UNKNOWN;
}
return type;
}