Skip to content

Commit 0906b7f

Browse files
mikhailramalhoyuxuanchen1997
authored andcommitted
[libc] Change fcntl cmd when only fcntl64 is available (#99675)
Summary: 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. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251108
1 parent 5ad45d8 commit 0906b7f

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,31 @@ int fcntl(int fd, int cmd, void *arg) {
8686
libc_errno = -ret;
8787
return -1;
8888
}
89-
// 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;
89+
#ifdef SYS_fcntl64
90+
case F_GETLK: {
91+
if constexpr (FCNTL_SYSCALL_ID == SYS_fcntl64)
92+
return fcntl(fd, F_GETLK64, arg);
93+
break;
94+
}
95+
case F_SETLK: {
96+
if constexpr (FCNTL_SYSCALL_ID == SYS_fcntl64)
97+
return fcntl(fd, F_SETLK64, arg);
98+
break;
99+
}
100+
case F_SETLKW: {
101+
if constexpr (FCNTL_SYSCALL_ID == SYS_fcntl64)
102+
return fcntl(fd, F_SETLKW64, arg);
103+
break;
98104
}
105+
#endif
106+
}
107+
int retVal = LIBC_NAMESPACE::syscall_impl<int>(FCNTL_SYSCALL_ID, fd, cmd,
108+
reinterpret_cast<void *>(arg));
109+
if (retVal >= 0) {
110+
return retVal;
99111
}
112+
libc_errno = -retVal;
113+
return -1;
100114
}
101115

102116
} // namespace internal

0 commit comments

Comments
 (0)