xref: /aosp_15_r20/external/crosvm/base/src/sys/unix/iobuf.rs (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1 // Copyright 2020 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use std::ffi::c_void;
6 
7 use libc::iovec;
8 
9 use crate::iobuf::PlatformIoBuf;
10 
11 /// Cross platform binary compatible iovec. See [`crate::IoBufMut`] for documentation.
12 pub type IoBuf = iovec;
13 
14 impl PlatformIoBuf for IoBuf {
15     #[inline]
new(ptr: *mut u8, len: usize) -> Self16     fn new(ptr: *mut u8, len: usize) -> Self {
17         iovec {
18             iov_base: ptr as *mut c_void,
19             iov_len: len,
20         }
21     }
22 
23     #[inline]
len(&self) -> usize24     fn len(&self) -> usize {
25         self.iov_len
26     }
27 
28     #[inline]
ptr(&self) -> *mut u829     fn ptr(&self) -> *mut u8 {
30         self.iov_base as *mut u8
31     }
32 
33     #[inline]
set_len(&mut self, len: usize)34     fn set_len(&mut self, len: usize) {
35         self.iov_len = len;
36     }
37 
38     #[inline]
set_ptr(&mut self, ptr: *mut u8)39     fn set_ptr(&mut self, ptr: *mut u8) {
40         self.iov_base = ptr as *mut c_void;
41     }
42 }
43