-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.c
58 lines (51 loc) · 1022 Bytes
/
config.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
52
53
54
55
56
57
58
/**
`* config.c
`*
`* Created on: Jun 24, 2009
`* Author: blanham
`*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "main.h"
#include "config.h"
//will use libxml2 eventually
int openconfig(void);
void newconfig(void);
FILE *cfg;
CONFIG config;
int openconfig(void)
{
cfg = fopen("bnes.cfg", "r+");
if (cfg == NULL)
{
fclose(cfg);
printf("bnes.cfg not found!\n");
newconfig();
}
fread(&config, 1, sizeof(config), cfg);
fclose(cfg);
if(memcmp(config.BNES, "BNES\x1A",5) == 0){
printf("bnes.cfg found!\n");
}else{
printf("invalid cfg!");
exit(1);
}
return 0;
}
void newconfig(void)
{
cfg = fopen("bnes.cfg", "wr");
if (cfg == NULL)
{
fclose(cfg);
printf("bnes.cfg cannot be created!\n");
exit(1);
}
fprintf(cfg, "BNES\x1A\n");
}
void configwrite(void){
cfg = fopen("bnes.cfg", "r+");
fwrite(&config, 1, sizeof(config), cfg);
fclose(cfg);
}