Exclusively lock save file
Prevents two instances of catgirl from using the same save file and clobbering each other's data.master
parent
c6009cf13c
commit
f6e8078c46
6
ui.c
6
ui.c
|
@ -32,6 +32,7 @@
|
|||
#include <curses.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
|
@ -1183,6 +1184,11 @@ void uiLoad(const char *name) {
|
|||
if (!saveFile) exit(EX_CANTCREAT);
|
||||
rewind(saveFile);
|
||||
|
||||
int error = flock(fileno(saveFile), LOCK_EX | LOCK_NB);
|
||||
if (error && errno == EWOULDBLOCK) {
|
||||
errx(EX_CANTCREAT, "%s: save file in use", name);
|
||||
}
|
||||
|
||||
time_t signature;
|
||||
fread(&signature, sizeof(signature), 1, saveFile);
|
||||
if (ferror(saveFile)) err(EX_IOERR, "fread");
|
||||
|
|
Loading…
Reference in New Issue