@@ -100,40 +100,6 @@ impl AsMut<[u8]> for BytesMut {
100
100
}
101
101
}
102
102
103
- /// CStr is a null-terminated string. Null pointers are interpreted as empty strings.
104
- #[ repr( C ) ]
105
- pub struct CStr {
106
- buf : * const c_char ,
107
- len : usize ,
108
- }
109
-
110
- impl CStr {
111
- /// Create a CStr from a null-terminated string or null pointer. Unsafe because it will read
112
- /// until it finds a null character.
113
- pub unsafe fn new ( buf : * const c_char ) -> Self {
114
- if buf. is_null ( ) {
115
- CStr {
116
- buf : core:: ptr:: NonNull :: dangling ( ) . as_ptr ( ) ,
117
- len : 0 ,
118
- }
119
- } else {
120
- let mut len = 0 ;
121
- let mut b = buf;
122
- while b. read ( ) != 0 {
123
- len += 1 ;
124
- b = b. offset ( 1 ) ;
125
- }
126
- CStr { buf, len }
127
- }
128
- }
129
- }
130
-
131
- impl AsRef < str > for CStr {
132
- fn as_ref ( & self ) -> & str {
133
- unsafe { core:: str:: from_utf8_unchecked ( core:: slice:: from_raw_parts ( self . buf , self . len ) ) }
134
- }
135
- }
136
-
137
103
/// CStrMut is a "growable" container which keeps track of some array allocated by C with a length
138
104
/// and a capacity state. It always contains a null-terminated string. The string (excluding null
139
105
/// terminator) can therefore be maximally `capacity-1` long.
@@ -245,14 +211,6 @@ pub unsafe extern "C" fn rust_util_bytes_mut(buf: *mut c_uchar, len: usize) -> B
245
211
BytesMut { buf, len }
246
212
}
247
213
248
- /// Convert buffer to str.
249
- ///
250
- /// * `buf` - Must be a valid pointer to a null terminated array of bytes.
251
- #[ no_mangle]
252
- pub unsafe extern "C" fn rust_util_cstr ( buf : * const c_char ) -> CStr {
253
- CStr :: new ( buf)
254
- }
255
-
256
214
/// Convert buffer to mutable str. The whole buffer is considered empty from start.
257
215
///
258
216
/// * `buf` - Must be a valid pointer to an array of bytes
@@ -301,17 +259,6 @@ mod tests {
301
259
rust_util_zero ( unsafe { rust_util_bytes_mut ( core:: ptr:: null_mut ( ) , 0 ) } ) ;
302
260
}
303
261
304
- #[ test]
305
- fn test_rust_util_cstr ( ) {
306
- let cstr = unsafe { rust_util_cstr ( b"\0 " . as_ptr ( ) ) } ;
307
- assert_eq ! ( cstr. as_ref( ) , "" ) ;
308
- assert_eq ! ( cstr. len, 0 ) ;
309
-
310
- let cstr = unsafe { rust_util_cstr ( b"foo\0 bar" . as_ptr ( ) ) } ;
311
- assert_eq ! ( cstr. as_ref( ) , "foo" ) ;
312
- assert_eq ! ( cstr. len, 3 ) ;
313
- }
314
-
315
262
#[ test]
316
263
#[ should_panic]
317
264
fn create_invalid_bytes_mut ( ) {
0 commit comments