Skip to content

Commit 95e01ff

Browse files
[libc] Change fcntl cmd when only fcntl64 is available
In some systems like rv32, only fcntl64 is available and it employs a different structure for file locking and the correspoding F_GETLK64, F_SETLK64, and F_SETLKW64 commands. So if we use fcntl64, the F_GETLK, F_SETLK, and F_SETLKW commands need to be changed to their 64 versions. This patch adds new cases to the swich(cmd) in our implementation of fcntl to do that. The default case was moved to outside the switch, so we don't need to change anything, the F_GETLK, F_SETLK, and F_SETLKW commands will just go through the old implementation.
1 parent 9ba5244 commit 95e01ff

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

libc/src/__support/OSUtil/linux/fcntl.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,37 @@ int fcntl(int fd, int cmd, void *arg) {
8686
libc_errno = -ret;
8787
return -1;
8888
}
89+
case F_GETLK: {
90+
#if defined(SYS_fcntl64)
91+
if constexpr (FCNTL_SYSCALL_ID == SYS_fcntl64)
92+
return fcntl(fd, F_GETLK64, arg);
93+
#endif
94+
break;
95+
}
96+
case F_SETLK: {
97+
#if defined(SYS_fcntl64)
98+
if constexpr (FCNTL_SYSCALL_ID == SYS_fcntl64)
99+
return fcntl(fd, F_SETLK64, arg);
100+
#endif
101+
break;
102+
}
103+
case F_SETLKW: {
104+
#if defined(SYS_fcntl64)
105+
if constexpr (FCNTL_SYSCALL_ID == SYS_fcntl64)
106+
return fcntl(fd, F_SETLKW64, arg);
107+
#endif
108+
break;
109+
}
89110
// The general case
90-
default: {
91-
int retVal = LIBC_NAMESPACE::syscall_impl<int>(
92-
FCNTL_SYSCALL_ID, fd, cmd, reinterpret_cast<void *>(arg));
93-
if (retVal >= 0) {
94-
return retVal;
95-
}
96-
libc_errno = -retVal;
97-
return -1;
111+
default:;
98112
}
113+
int retVal = LIBC_NAMESPACE::syscall_impl<int>(FCNTL_SYSCALL_ID, fd, cmd,
114+
reinterpret_cast<void *>(arg));
115+
if (retVal >= 0) {
116+
return retVal;
99117
}
118+
libc_errno = -retVal;
119+
return -1;
100120
}
101121

102122
} // namespace internal

0 commit comments

Comments
 (0)