unix: simplify uv__cloexec_fcntl() (#3492)

FD_CLOEXEC is the only defined flag for fcntl(F_SETFD) so don't bother
getting the status of that flag first with fcntl(F_GETFD), just set it.
This commit is contained in:
Ben Noordhuis 2022-03-05 18:55:49 +01:00 committed by GitHub
parent 8e67d8b364
commit c8583bbdf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -651,21 +651,9 @@ int uv__cloexec_fcntl(int fd, int set) {
int flags;
int r;
do
r = fcntl(fd, F_GETFD);
while (r == -1 && errno == EINTR);
if (r == -1)
return UV__ERR(errno);
/* Bail out now if already set/clear. */
if (!!(r & FD_CLOEXEC) == !!set)
return 0;
flags = 0;
if (set)
flags = r | FD_CLOEXEC;
else
flags = r & ~FD_CLOEXEC;
flags = FD_CLOEXEC;
do
r = fcntl(fd, F_SETFD, flags);