-
Notifications
You must be signed in to change notification settings - Fork 0
/
akfm.h
81 lines (67 loc) · 1.99 KB
/
akfm.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// akfm.h
// created Tue Dec 31 12:41:13 EST 2013
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
//errors
#define AKFM_NFM -1 //the file manager is NULL
#define AKFM_NOF -2 //can't open the file
typedef struct {
FILE *fp;
char *fn;
} ak_file_manager;
/* akfm_create */
//creates a file manager for the save file with that name
// if the save file is not created, it creates it
// if the save file is already created, it uses that one
ak_file_manager *akfm_create(const char *filename);
/* akfm_write */
//writes data to the file
//connects the key to the value
//user will retrieve the key with the value
//returns:
// 0 on success
// AKFM_NFM if file manager is NULL
// AKFM_NOF if can't open file
int akfm_write_int(ak_file_manager *akfm,
const char *key,
int value);
int akfm_write_char(ak_file_manager *akfm,
const char *key,
char value);
int akfm_write_string(ak_file_manager *akfm,
const char *key,
const char *value);
/* akfm_read */
//reads the data from the file with key
//returns the value
//returns:
// value if it is in the file
// 0 if it is not in the file
int akfm_read_int(ak_file_manager *akfm,
const char *key);
char akfm_read_char(ak_file_manager *akfm,
const char *key);
char *akfm_read_string(ak_file_manager *akfm,
const char *key);
/* akfm delete */
//deletes the key, if it exists
//returns:
// 0 if something was deleted
// 1 if nothing was deleted
int akfm_delete(ak_file_manager *akfm, const char *key);
/* akfm_erase */
//erases the whole file
//returns:
// 0 if succesfully erased
// error otherwise
int akfm_erase(ak_file_manager *akfm);
/* akfm free */
//this frees up all the pointers that the file manager has
//call this instead of free(akfm)
void akfm_free(ak_file_manager *akfm);