mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust/pv: Replace libc wherever possible
Replace all libc references to rust-std references if available. This eliminates the need to include libc in the pv crate. However, pv_base still refers to libc::ioctl and libc::ENOTTY. Reviewed-by: Marc Hartmayer <mhartmay@linux.ibm.com> Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
b71279cda5
commit
02dded11a5
@@ -5,10 +5,10 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
use crate::FileAccessErrorType;
|
||||
use crate::{Error, Result};
|
||||
use libc::c_ulong;
|
||||
use log::debug;
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
ffi::c_ulong,
|
||||
fs::File,
|
||||
os::unix::prelude::{AsRawFd, RawFd},
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#![cfg(test)]
|
||||
|
||||
use std::{
|
||||
ffi::{c_int, c_ulong},
|
||||
os::unix::prelude::FromRawFd,
|
||||
sync::{Mutex, MutexGuard},
|
||||
};
|
||||
@@ -28,18 +29,18 @@ fn get_lock<T>(m: &'static Mutex<T>) -> MutexGuard<'static, T> {
|
||||
|
||||
struct IoctlCtx {
|
||||
modify: Box<dyn FnMut(&mut ffi::uvio_ioctl_cb) -> i32 + Send + Sync>,
|
||||
exp_cmd: ::libc::c_ulong,
|
||||
exp_cmd: c_ulong,
|
||||
called: bool,
|
||||
}
|
||||
|
||||
impl IoctlCtx {
|
||||
pub fn exp_cmd(&mut self, cmd: ::libc::c_ulong) -> &mut Self {
|
||||
pub fn exp_cmd(&mut self, cmd: c_ulong) -> &mut Self {
|
||||
self.exp_cmd = cmd;
|
||||
self
|
||||
}
|
||||
pub fn set_mdfy<F>(&mut self, mdfy: F) -> &mut Self
|
||||
where
|
||||
F: FnMut(&mut ffi::uvio_ioctl_cb) -> ::libc::c_int + 'static + Send + Sync,
|
||||
F: FnMut(&mut ffi::uvio_ioctl_cb) -> c_int + 'static + Send + Sync,
|
||||
{
|
||||
self.modify = Box::new(mdfy);
|
||||
self
|
||||
@@ -62,11 +63,7 @@ impl IoctlCtx {
|
||||
pub mod mock_libc {
|
||||
use super::*;
|
||||
|
||||
pub unsafe fn ioctl(
|
||||
fd: ::libc::c_int,
|
||||
cmd: ::libc::c_ulong,
|
||||
data: *mut ffi::uvio_ioctl_cb,
|
||||
) -> ::libc::c_int {
|
||||
pub unsafe fn ioctl(fd: c_int, cmd: c_ulong, data: *mut ffi::uvio_ioctl_cb) -> c_int {
|
||||
let mut ctx = get_lock(&IOCTL_MTX);
|
||||
assert!(!ctx.called, "IOCTL called more than once");
|
||||
ctx.called = true;
|
||||
|
||||
Reference in New Issue
Block a user