LibCore: Implement System::set_close_on_exec

This commit is contained in:
stasoid 2025-02-13 18:50:23 +05:00 committed by Andrew Kaster
parent 2e200489c8
commit 2abc792938
Notes: github-actions[bot] 2025-03-20 02:26:29 +00:00
8 changed files with 31 additions and 35 deletions

View file

@ -1017,4 +1017,17 @@ ErrorOr<void> sleep_ms(u32 milliseconds)
return {};
}
ErrorOr<void> set_close_on_exec(int fd, bool enabled)
{
int flags = TRY(fcntl(fd, F_GETFD));
if (enabled)
flags |= FD_CLOEXEC;
else
flags &= ~FD_CLOEXEC;
TRY(fcntl(fd, F_SETFD, flags));
return {};
}
}