xref: /third_party/rust/crates/rustix/src/io/close.rs (revision b8a62b91)
1//! The unsafe `close` for raw file descriptors.
2//!
3//! # Safety
4//!
5//! Operating on raw file descriptors is unsafe.
6#![allow(unsafe_code)]
7
8use crate::backend;
9use backend::fd::RawFd;
10
11/// `close(raw_fd)`—Closes a `RawFd` directly.
12///
13/// Most users won't need to use this, as `OwnedFd` automatically closes its
14/// file descriptor on `Drop`.
15///
16/// This function does not return a `Result`, as it is the [responsibility] of
17/// filesystem designers to not return errors from `close`. Users who chose to
18/// use NFS or similar filesystems should take care to monitor for problems
19/// externally.
20///
21/// [responsibility]: https://lwn.net/Articles/576518/
22///
23/// # References
24///  - [POSIX]
25///  - [Linux]
26///  - [Apple]
27///  - [Winsock2]
28///
29/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/close.html
30/// [Linux]: https://man7.org/linux/man-pages/man2/close.2.html
31/// [Apple]: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/close.2.html#//apple_ref/doc/man/2/close
32/// [Winsock2]: https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-closesocket
33///
34/// # Safety
35///
36/// This function takes a `RawFd`, which must be valid before the call, and is
37/// not valid after the call.
38#[inline]
39pub unsafe fn close(raw_fd: RawFd) {
40    backend::io::syscalls::close(raw_fd)
41}
42