4
4
//! information such as keymaps without them being able to write to the handle.
5
5
6
6
use std:: {
7
- ffi:: CString ,
7
+ ffi:: { CStr , CString } ,
8
8
fs:: File ,
9
9
io:: Write ,
10
10
os:: unix:: io:: { AsFd , AsRawFd , BorrowedFd , RawFd } ,
@@ -17,16 +17,16 @@ pub(crate) struct SealedFile {
17
17
}
18
18
19
19
impl SealedFile {
20
- pub fn with_content ( name : CString , contents : CString ) -> Result < Self , std:: io:: Error > {
20
+ pub fn with_content ( name : & CStr , contents : CString ) -> Result < Self , std:: io:: Error > {
21
21
Self :: with_data ( name, contents. as_bytes_with_nul ( ) )
22
22
}
23
23
24
24
#[ cfg( any( target_os = "linux" , target_os = "freebsd" , target_os = "android" ) ) ]
25
- pub fn with_data ( name : CString , data : & [ u8 ] ) -> Result < Self , std:: io:: Error > {
25
+ pub fn with_data ( name : & CStr , data : & [ u8 ] ) -> Result < Self , std:: io:: Error > {
26
26
use rustix:: fs:: { MemfdFlags , SealFlags } ;
27
27
use std:: io:: Seek ;
28
28
29
- let fd = rustix:: fs:: memfd_create ( & name, MemfdFlags :: CLOEXEC | MemfdFlags :: ALLOW_SEALING ) ?;
29
+ let fd = rustix:: fs:: memfd_create ( name, MemfdFlags :: CLOEXEC | MemfdFlags :: ALLOW_SEALING ) ?;
30
30
31
31
let mut file: File = fd. into ( ) ;
32
32
file. write_all ( data) ?;
@@ -46,7 +46,7 @@ impl SealedFile {
46
46
}
47
47
48
48
#[ cfg( not( any( target_os = "linux" , target_os = "freebsd" , target_os = "android" ) ) ) ]
49
- pub fn with_data ( name : CString , data : & [ u8 ] ) -> Result < Self , std:: io:: Error > {
49
+ pub fn with_data ( name : & CStr , data : & [ u8 ] ) -> Result < Self , std:: io:: Error > {
50
50
use rand:: { distributions:: Alphanumeric , Rng } ;
51
51
use rustix:: {
52
52
io:: Errno ,
@@ -59,7 +59,7 @@ impl SealedFile {
59
59
// loop a couple times if it exists.
60
60
let mut n = 0 ;
61
61
let ( shm_name, mut file) = loop {
62
- let mut shm_name = name. as_bytes ( ) . to_owned ( ) ;
62
+ let mut shm_name = name. to_bytes ( ) . to_owned ( ) ;
63
63
shm_name. push ( b'-' ) ;
64
64
shm_name. extend ( ( 0 ..7 ) . map ( |_| rng. sample ( Alphanumeric ) ) ) ;
65
65
let fd = rustix:: shm:: shm_open (
0 commit comments