-
Notifications
You must be signed in to change notification settings - Fork 12
/
simpledb.h
63 lines (49 loc) · 1.49 KB
/
simpledb.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
#include <limits.h>
#include <stdio.h>
#ifdef DEBUG
#define dbg(X, ...) do { \
fprintf(stderr, ("LOG> " X "\n"), ## __VA_ARGS__); \
} while(0)
#else
#define dbg(X, ...)
#endif
struct item_birth { /* for storing the birth date. See usage below */
unsigned int year:12;
unsigned int month:4;
unsigned int day:5;
};
struct dbitem {
union { /* excplicitly mark field as key -- used as filename */
char last_name [20 * MB_LEN_MAX];
char key [20 * MB_LEN_MAX];
};
char first_name [20 * MB_LEN_MAX];
char email [30 * MB_LEN_MAX];
struct item_birth birth_date;
};
enum err {
E_OK = 0,
E_FNAME, // Wrong file name
E_OSERR, // miscallenous os errors
E_FOPEN, // File open
E_FREAD, // File read
E_FWRITE, // File write
E_WRONGCRC, // CRC mismatch
E_last_ // stores index of the last element
};
struct strvec {
unsigned int n; /* number of items */
char **vec; /* vector of dynamically allocated strings */
};
enum err item_read_f(FILE *, struct dbitem *);
enum err item_write_f(FILE *, struct dbitem *);
enum err item_read(const char *, struct dbitem *);
enum err item_write(const char *, struct dbitem *);
enum err item_remove_bykey(const char *, const char *);
enum err listdir(const char *, struct strvec *);
/* Warning: The resulting string is malloced.
* And memory *should* 2 be freed afterwards.
*/
char *m_strjoin(const char *, const char *, const char *);
enum err item_remove_bykey(const char *, const char *);
FILE *xopen(const char *, const char *);