basic/fileio: drop O_CREAT before passing flags to fd_reopen

Follow-up for 78c21009bf

Fixes #29938
This commit is contained in:
Mike Yuan
2023-11-09 03:38:14 +08:00
parent 05314c9c87
commit 6f9677bc7f
+3 -1
View File
@@ -1064,7 +1064,9 @@ int fdopen_independent(int fd, const char *mode, FILE **ret) {
if (mode_flags < 0)
return mode_flags;
copy_fd = fd_reopen(fd, mode_flags);
/* Flags returned by fopen_mode_to_flags might contain O_CREAT, but it doesn't make sense for fd_reopen
* since we're working on an existing fd anyway. Let's drop it here to avoid triggering assertion. */
copy_fd = fd_reopen(fd, mode_flags & ~O_CREAT);
if (copy_fd < 0)
return copy_fd;