Lines Matching +full:use +full:- +full:libc
1 use crate::errno::Errno;
2 use libc::{self, c_char, c_int, c_uint, size_t, ssize_t};
3 use std::ffi::OsString;
5 use std::os::raw;
6 use std::os::unix::ffi::OsStringExt;
7 use std::os::unix::io::RawFd;
10 use crate::{sys::stat::Mode, NixPath, Result};
12 use std::ptr; // For splice and copy_file_range
24 pub use self::posix_fadvise::{posix_fadvise, PosixFadviseAdvice};
50 /// Use alternate I/O semantics.
54 /// Open the file in append-only mode.
138 /// Obtain a file descriptor for low-level access.
196 pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag, mode: Mode) -> Result<RawFd> {
198 unsafe { libc::open(cstr.as_ptr(), oflag.bits(), mode.bits() as c_uint) }
212 ) -> Result<RawFd> {
214 unsafe { libc::openat(dirfd, cstr.as_ptr(), oflag.bits(), mode.bits() as c_uint) }
225 ) -> Result<()> {
228 libc::renameat(
263 ) -> Result<()> {
266 libc::renameat2(
278 fn wrap_readlink_result(mut v: Vec<u8>, len: ssize_t) -> Result<OsString> {
288 ) -> Result<libc::ssize_t> {
294 Some(dirfd) => libc::readlinkat(
300 None => libc::readlink(
309 fn inner_readlink<P: ?Sized + NixPath>(dirfd: Option<RawFd>, path: &P) -> Result<OsString> {
310 let mut v = Vec::with_capacity(libc::PATH_MAX as usize);
341 (libc::PATH_MAX as usize).max(128) << 1
362 pub fn readlink<P: ?Sized + NixPath>(path: &P) -> Result<OsString> {
367 pub fn readlinkat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P) -> Result<OsString> {
373 pub(crate) fn at_rawfd(fd: Option<RawFd>) -> raw::c_int {
375 None => libc::AT_FDCWD,
421 F_SETLK(&'a libc::flock),
422 F_SETLKW(&'a libc::flock),
423 F_GETLK(&'a mut libc::flock),
425 F_OFD_SETLK(&'a libc::flock),
427 F_OFD_SETLKW(&'a libc::flock),
429 F_OFD_GETLK(&'a mut libc::flock),
454 pub use self::FcntlArg::*;
457 pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
460 F_DUPFD(rawfd) => libc::fcntl(fd, libc::F_DUPFD, rawfd),
461 F_DUPFD_CLOEXEC(rawfd) => libc::fcntl(fd, libc::F_DUPFD_CLOEXEC, rawfd),
462 F_GETFD => libc::fcntl(fd, libc::F_GETFD),
463 F_SETFD(flag) => libc::fcntl(fd, libc::F_SETFD, flag.bits()),
464 F_GETFL => libc::fcntl(fd, libc::F_GETFL),
465 F_SETFL(flag) => libc::fcntl(fd, libc::F_SETFL, flag.bits()),
467 F_SETLK(flock) => libc::fcntl(fd, libc::F_SETLK, flock),
469 F_SETLKW(flock) => libc::fcntl(fd, libc::F_SETLKW, flock),
471 F_GETLK(flock) => libc::fcntl(fd, libc::F_GETLK, flock),
473 F_OFD_SETLK(flock) => libc::fcntl(fd, libc::F_OFD_SETLK, flock),
475 F_OFD_SETLKW(flock) => libc::fcntl(fd, libc::F_OFD_SETLKW, flock),
477 F_OFD_GETLK(flock) => libc::fcntl(fd, libc::F_OFD_GETLK, flock),
479 F_ADD_SEALS(flag) => libc::fcntl(fd, libc::F_ADD_SEALS, flag.bits()),
481 F_GET_SEALS => libc::fcntl(fd, libc::F_GET_SEALS),
483 F_FULLFSYNC => libc::fcntl(fd, libc::F_FULLFSYNC),
485 F_GETPIPE_SZ => libc::fcntl(fd, libc::F_GETPIPE_SZ),
487 F_SETPIPE_SZ(size) => libc::fcntl(fd, libc::F_SETPIPE_SZ, size),
507 pub fn flock(fd: RawFd, arg: FlockArg) -> Result<()> {
508 use self::FlockArg::*;
512 LockShared => libc::flock(fd, libc::LOCK_SH),
513 LockExclusive => libc::flock(fd, libc::LOCK_EX),
514 Unlock => libc::flock(fd, libc::LOCK_UN),
515 LockSharedNonblock => libc::flock(fd, libc::LOCK_SH | libc::LOCK_NB),
516 LockExclusiveNonblock => libc::flock(fd, libc::LOCK_EX | libc::LOCK_NB),
517 UnlockNonblock => libc::flock(fd, libc::LOCK_UN | libc::LOCK_NB),
553 /// The `copy_file_range` system call performs an in-kernel copy between
570 off_in: Option<&mut libc::loff_t>,
572 off_out: Option<&mut libc::loff_t>,
574 ) -> Result<usize> {
576 .map(|offset| offset as *mut libc::loff_t)
579 .map(|offset| offset as *mut libc::loff_t)
583 libc::syscall(
584 libc::SYS_copy_file_range,
599 off_in: Option<&mut libc::loff_t>,
601 off_out: Option<&mut libc::loff_t>,
604 ) -> Result<usize> {
606 .map(|offset| offset as *mut libc::loff_t)
609 .map(|offset| offset as *mut libc::loff_t)
612 let ret = unsafe { libc::splice(fd_in, off_in, fd_out, off_out, len, flags.bits()) };
617 pub fn tee(fd_in: RawFd, fd_out: RawFd, len: usize, flags: SpliceFFlags) -> Result<usize> {
618 let ret = unsafe { libc::tee(fd_in, fd_out, len, flags.bits()) };
627 ) -> Result<usize>
630 libc::vmsplice(
632 iov.as_ptr() as *const libc::iovec,
686 offset: libc::off_t,
687 len: libc::off_t,
688 ) -> Result<()> {
689 let res = unsafe { libc::fallocate(fd, mode.bits(), offset, len) };
697 pub struct SpacectlRange(pub libc::off_t, pub libc::off_t);
702 pub fn is_empty(&self) -> bool {
707 pub fn len(&self) -> libc::off_t {
712 pub fn offset(&self) -> libc::off_t {
726 /// - `fd` - File to operate on
727 /// - `range.0` - File offset at which to begin deallocation
728 /// - `range.1` - Length of the region to deallocate
740 /// # use std::io::Write;
741 /// # use std::os::unix::fs::FileExt;
742 /// # use std::os::unix::io::AsRawFd;
743 /// # use nix::fcntl::*;
744 /// # use tempfile::tempfile;
757 pub fn fspacectl(fd: RawFd, range: SpacectlRange) -> Result<SpacectlRange> {
758 let mut rqsr = libc::spacectl_range{r_offset: range.0, r_len: range.1};
759 let res = unsafe { libc::fspacectl(
761 libc::SPACECTL_DEALLOC, // Only one command is supported ATM
773 /// - `fd` - File to operate on
774 /// - `offset` - File offset at which to begin deallocation
775 /// - `len` - Length of the region to deallocate
786 /// # use std::io::Write;
787 /// # use std::os::unix::fs::FileExt;
788 /// # use std::os::unix::io::AsRawFd;
789 /// # use nix::fcntl::*;
790 /// # use tempfile::tempfile;
800 pub fn fspacectl_all(fd: RawFd, offset: libc::off_t, len: libc::off_t)
801 -> Result<()>
803 let mut rqsr = libc::spacectl_range{r_offset: offset, r_len: len};
805 let res = unsafe { libc::fspacectl(
807 libc::SPACECTL_DEALLOC, // Only one command is supported ATM
827 use crate::errno::Errno;
828 use std::os::unix::io::RawFd;
829 use crate::Result;
850 offset: libc::off_t,
851 len: libc::off_t,
853 ) -> Result<()> {
854 let res = unsafe { libc::posix_fadvise(fd, offset, len, advice as libc::c_int) };
874 pub fn posix_fallocate(fd: RawFd, offset: libc::off_t, len: libc::off_t) -> Result<()> {
875 let res = unsafe { libc::posix_fallocate(fd, offset, len) };