-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave.c
More file actions
61 lines (51 loc) · 1.13 KB
/
Copy pathsave.c
File metadata and controls
61 lines (51 loc) · 1.13 KB
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
/*
* Copyright(C) 2010-2011, Jocelyn Falempe jock@inpactien.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include "save.h"
#include "event.h"
static int savefd = -1;
void saExit(void) {
close(savefd);
}
#ifdef _WIN32
#define O_NONBLOCK 0
#endif // _WIN32
void saInit(char *file) {
savefd = open(file, O_WRONLY | O_CREAT | O_NONBLOCK | O_TRUNC, 0660);
if (savefd < 0) {
printf("cannot open %s", file);
return;
}
atexit(saExit);
}
void saSaveEvent(ev_t *ev) {
int n;
if (savefd < 0)
return;
n = write(savefd, ev, sizeof(*ev));
n = write(savefd, ev->data, ev->size);
if (n < 0)
printf("error writing replay\n");
}
void saReplay(char *file) {
int fd;
ev_t ev;
char buf[256];
int n;
fd = open(file, O_RDONLY);
do {
n = read(fd, &ev, sizeof(ev));
n = read(fd, buf, ev.size);
evPostEventLocal(ev.time, buf, ev.size, ev.type);
} while (n > 0);
}