mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
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.
This commit is contained in:
parent
3fa2816642
commit
2ce8cca7b5
3 changed files with 40 additions and 0 deletions
|
@ -39,6 +39,7 @@ set(LIBC_SOURCES
|
|||
strings.cpp
|
||||
stubs.cpp
|
||||
syslog.cpp
|
||||
sys/file.cpp
|
||||
sys/mman.cpp
|
||||
sys/prctl.cpp
|
||||
sys/ptrace.cpp
|
||||
|
|
26
Userland/Libraries/LibC/sys/file.cpp
Normal file
26
Userland/Libraries/LibC/sys/file.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
|
@ -5,3 +5,16 @@
|
|||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define LOCK_SH 0
|
||||
#define LOCK_EX 1
|
||||
#define LOCK_UN 2
|
||||
#define LOCK_NB (1 << 2)
|
||||
|
||||
int flock(int fd, int operation);
|
||||
|
||||
__END_DECLS
|
||||
|
|
Loading…
Add table
Reference in a new issue