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
|
#include "database.h"
#include <stdlib.h>
#include <stdio.h>
void database_prefixPath(const char *path, char *out) {
sprintf(out, ".rolex/%s", path);
}
enum DatabaseError_t database_pushEntry(const char *path, struct TimeEnty_t *entry) {
char filePath[1024];
FILE *f;
database_prefixPath(path, filePath);
mkdir(".rolex", 0777);
f = fopen(filePath, "a");
fprintf(f, "%d %ld\n", entry->direction, entry->datetime);
fclose(f);
return DB_OK;
}
enum DatabaseError_t database_getEntries(const char *path, struct TimeEnty_t *out, int *size) {
char filePath[1024], line[2048];
bool lineDirection;
long lineTime;
FILE *f;
int i = 0;
database_prefixPath(path, filePath);
f = fopen(filePath, "r");
if(f == NULL) goto done;
while(fgets(line, 2048, f)) {
scanf(line, "%d %ld", &lineDirection, &lineTime);
out[i].direction = lineDirection;
out[i].datetime = lineTime;
i++;
}
done:
*size = i;
return DB_OK;
}
|