ladybird/Userland/Libraries/LibC/sys/file.cpp
Peter Elliott 2ce8cca7b5 LibC: Implement flock(2) using fcntl's F_SETLK
While flock is not a posix interface, it exists on linux and all BSDs as
far as I am aware.
2021-07-20 17:44:30 +04:30

26 lines
484 B
C++

/*
* Copyright (c) 2021, Peter Elliott <pelliott@ualberta.ca>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Assertions.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/file.h>
extern "C" {
int flock(int fd, int operation)
{
struct flock lock {
short(operation & 0b11), SEEK_SET, 0, 0, 0
};
if (operation & LOCK_NB) {
return fcntl(fd, F_SETLK, &lock);
}
// FIXME: Implement F_SETLKW in fcntl.
VERIFY_NOT_REACHED();
}
}