diff --git a/ui.c b/ui.c index 22b098e..2beba88 100644 --- a/ui.c +++ b/ui.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -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");