-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcfgwriter.c
29 lines (27 loc) · 868 Bytes
/
cfgwriter.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
#include <stdio.h>
#include <string.h>
#include <simple_protobuf.h>
#include "config.h"
config_t cfg;
int main() {
printf("Enter a password: ");
scanf("%s", cfg.pwd);
printf("Enter a set password: ");
scanf("%s", cfg.sps);
uint32_t* types_len = align_struct(sizeof(config_t), 2, cfg.pwd, cfg.sps);
FILE* fp = fopen("cfg.sp", "wb");
if(fp) {
set_pb(fp, types_len, sizeof(config_t), &cfg);
fclose(fp);
puts("Config is saved to cfg.sp.");
fp = NULL;
puts("Check config...");
fp = fopen("cfg.sp", "rb");
if(fp) {
simple_pb_t* spb = get_pb(fp);
memset(&cfg, 0, sizeof(config_t));
memcpy(&cfg, spb->target, sizeof(config_t));
printf("set pwd: %s, sps: %s\n", cfg.pwd, cfg.sps);
} else perror("[SPB]");
} else perror("[SPB]");
}