mirror of
https://github.com/fumiama/CMoe-Counter.git
synced 2026-06-12 14:10:44 +08:00
feat: add volatile fp
This commit is contained in:
12
cmoe.c
12
cmoe.c
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
static uint32_t* items_len;
|
static uint32_t* items_len;
|
||||||
static counter_t counter;
|
static counter_t counter;
|
||||||
static FILE* fp;
|
static FILE* volatile fp;
|
||||||
|
|
||||||
static char* datfile = "dat.sp";
|
static char* datfile = "dat.sp";
|
||||||
static char* token = "fumiama";
|
static char* token = "fumiama";
|
||||||
@@ -188,7 +188,10 @@ static void return_count(FILE* fp, char* name, char* theme, uint32_t color) {
|
|||||||
if (!spb) continue;
|
if (!spb) continue;
|
||||||
counter_t *d = (counter_t *)spb->target;
|
counter_t *d = (counter_t *)spb->target;
|
||||||
if (strcmp(name, d->name)) continue;
|
if (strcmp(name, d->name)) continue;
|
||||||
del_user(fp, spb);
|
if (del_user(fp, spb)) {
|
||||||
|
http_error(HTTP500, "Del User Error.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
add_user(d->name, d->count + 1, fp);
|
add_user(d->name, d->count + 1, fp);
|
||||||
draw(d->count, theme, color);
|
draw(d->count, theme, color);
|
||||||
return;
|
return;
|
||||||
@@ -337,13 +340,14 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
static void __attribute__((destructor)) defer_close_fp() {
|
static void __attribute__((destructor)) defer_close_fp() {
|
||||||
if (fp) fclose(fp);
|
if (fp) fclose(fp);
|
||||||
char buf[4096];
|
fflush(stdout);
|
||||||
|
char buf[256];
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int ret;
|
int ret;
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
FD_SET(0, &rfds);
|
FD_SET(0, &rfds);
|
||||||
tv.tv_sec = 1;
|
tv.tv_sec = 2;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
if (select(1, &rfds, NULL, NULL, &tv) > 0 && FD_ISSET(0, &rfds)) {
|
if (select(1, &rfds, NULL, NULL, &tv) > 0 && FD_ISSET(0, &rfds)) {
|
||||||
read(0, buf, sizeof(buf));
|
read(0, buf, sizeof(buf));
|
||||||
|
|||||||
Reference in New Issue
Block a user