From e20af9124413310edcb13ffb59e867cb6a73995b Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 22 Oct 2026 20:06:42 +0100 Subject: [PATCH] LibC: Align LOCK_* with various other impls Same motivation as the previous commit. --- Userland/Libraries/LibC/sys/file.cpp | 7 ++++++- Userland/Libraries/LibC/sys/file.h | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibC/sys/file.cpp b/Userland/Libraries/LibC/sys/file.cpp index 826ca21af8b..28cc50b5ecd 100644 --- a/Userland/Libraries/LibC/sys/file.cpp +++ b/Userland/Libraries/LibC/sys/file.cpp @@ -14,8 +14,13 @@ 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 { - short(operation & 0b11), SEEK_SET, 0, 0, 0 + type, SEEK_SET, 0, 0, 0 }; return fcntl(fd, (operation & LOCK_NB) ? F_SETLK : F_SETLKW, &lock); } diff --git a/Userland/Libraries/LibC/sys/file.h b/Userland/Libraries/LibC/sys/file.h index 2abfb7665df..5f850d66b40 100644 --- a/Userland/Libraries/LibC/sys/file.h +++ b/Userland/Libraries/LibC/sys/file.h @@ -10,10 +10,10 @@ __BEGIN_DECLS -#define LOCK_SH 0 -#define LOCK_EX 1 -#define LOCK_UN 2 +#define LOCK_SH (1 << 0) +#define LOCK_EX (1 << 1) #define LOCK_NB (1 << 2) +#define LOCK_UN (1 << 3) int flock(int fd, int operation);