Files
Linus Groh e20af91244 LibC: Align LOCK_* with various other impls
Same motivation as the previous commit.
2026-10-23 09:18:11 -04:00

28 lines
597 B
C++

/*
* Copyright (c) 2021, Peter Elliott <[email protected]>
* Copyright (c) 2022, Idan Horowitz <[email protected]>
*
* 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)
{
short type = F_RDLCK;
if (operation & LOCK_UN)
type = F_UNLCK;
else if (operation & LOCK_EX)
type = F_WRLCK;
struct flock lock {
type, SEEK_SET, 0, 0, 0
};
return fcntl(fd, (operation & LOCK_NB) ? F_SETLK : F_SETLKW, &lock);
}
}