Lines Matching +full:use +full:- +full:libc
3 use crate::errno::Errno;
4 use crate::fcntl::{self, OFlag};
5 use crate::sys;
6 use crate::{Error, NixPath, Result};
7 use cfg_if::cfg_if;
8 use std::ffi;
9 use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
10 use std::ptr;
13 use libc::{dirent64 as dirent, readdir64_r as readdir_r};
16 use libc::{dirent, readdir_r};
20 /// This is a lower-level interface than `std::fs::ReadDir`. Notable differences:
29 /// * returns entries' names as a `CStr` (no allocation or conversion beyond whatever libc
32 pub struct Dir(ptr::NonNull<libc::DIR>);
40 ) -> Result<Self> { in open()
51 ) -> Result<Self> { in openat()
56 /// Converts from a descriptor-based object, closing the descriptor on success or failure.
58 pub fn from<F: IntoRawFd>(fd: F) -> Result<Self> { in from()
64 pub fn from_fd(fd: RawFd) -> Result<Self> { in from_fd()
65 let d = ptr::NonNull::new(unsafe { libc::fdopendir(fd) }).ok_or_else( in from_fd()
68 unsafe { libc::close(fd) }; in from_fd()
76 pub fn iter(&mut self) -> Iter { in iter()
82 // https://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html,
86 // `Dir` is safe to pass from one thread to another, as it's not reference-counted.
90 fn as_raw_fd(&self) -> RawFd { in as_raw_fd()
91 unsafe { libc::dirfd(self.0.as_ptr()) } in as_raw_fd()
97 let e = Errno::result(unsafe { libc::closedir(self.0.as_ptr()) }); in drop()
104 fn next(dir: &mut Dir) -> Option<Result<Entry>> { in next()
109 // fixed-sized buffers (and libc's dirent seems to be sized so this is appropriate). in next()
135 fn next(&mut self) -> Option<Self::Item> { in next()
142 unsafe { libc::rewinddir((self.0).0.as_ptr()) } in drop()
153 fn next(&mut self) -> Option<Self::Item> { in next()
161 fn as_raw_fd(&self) -> RawFd { in as_raw_fd()
178 /// use nix::{dir::Dir, fcntl::OFlag, sys::stat::Mode};
179 /// use std::{iter::Iterator, string::String};
181 /// fn ls_upper(dirname: &str) -> impl Iterator<Item=String> {
186 fn into_iter(self) -> Self::IntoIter { in into_iter()
213 /// Unix-domain socket
222 pub fn ino(&self) -> u64 { in ino()
242 pub fn file_name(&self) -> &ffi::CStr { in file_name()
249 /// notably, some Linux filesystems don't implement this. The caller should use `stat` or
251 pub fn file_type(&self) -> Option<Type> { in file_type()
258 libc::DT_FIFO => Some(Type::Fifo), in file_type()
259 libc::DT_CHR => Some(Type::CharacterDevice), in file_type()
260 libc::DT_DIR => Some(Type::Directory), in file_type()
261 libc::DT_BLK => Some(Type::BlockDevice), in file_type()
262 libc::DT_REG => Some(Type::File), in file_type()
263 libc::DT_LNK => Some(Type::Symlink), in file_type()
264 libc::DT_SOCK => Some(Type::Socket), in file_type()
265 /* libc::DT_UNKNOWN | */ _ => None, in file_type()