diff options
-rw-r--r-- | ui.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/ui.c b/ui.c index 22b098e..2beba88 100644 --- a/ui.c +++ b/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"); |