commonio_lock_nowait: Remove deprecated code

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
This commit is contained in:
Samanta Navarro 2023-05-05 11:57:06 +00:00 committed by Iker Pedrosa
parent 7109b7c066
commit e899e3d745

View File

@ -231,36 +231,18 @@ int do_fcntl_lock (const char *file, bool log, short type)
int commonio_lock_nowait (struct commonio_db *db, bool log) int commonio_lock_nowait (struct commonio_db *db, bool log)
{ {
char* file = NULL;
char* lock = NULL;
size_t lock_file_len;
size_t file_len;
int err = 0; int err = 0;
if (db->locked) { if (db->locked) {
return 1; return 1;
} }
file_len = strlen(db->filename) + 11;/* %lu max size */
lock_file_len = strlen(db->filename) + 6; /* sizeof ".lock" */
file = MALLOCARRAY(file_len, char);
if (file == NULL) {
goto cleanup_ENOMEM;
}
lock = MALLOCARRAY(lock_file_len, char);
if (lock == NULL) {
goto cleanup_ENOMEM;
}
snprintf (file, file_len, "%s.%lu",
db->filename, (unsigned long) getpid ());
if (do_fcntl_lock (db->filename, log, F_WRLCK | F_RDLCK) != 0) { if (do_fcntl_lock (db->filename, log, F_WRLCK | F_RDLCK) != 0) {
db->locked = true; db->locked = true;
lock_count++; lock_count++;
err = 1; err = 1;
} }
cleanup_ENOMEM:
free(file);
free(lock);
return err; return err;
} }