@@ -13,13 +13,7 @@ fn main() {
13
13
fn test_read_write ( ) {
14
14
let flags = libc:: EFD_NONBLOCK | libc:: EFD_CLOEXEC ;
15
15
let fd = unsafe { libc:: eventfd ( 0 , flags) } ;
16
- let sized_8_data: [ u8 ; 8 ] ;
17
- if cfg ! ( target_endian = "big" ) {
18
- // Adjust the data based on the endianness of host system.
19
- sized_8_data = 1_i64 . to_be_bytes ( ) ;
20
- } else {
21
- sized_8_data = 1_i64 . to_le_bytes ( ) ;
22
- }
16
+ let sized_8_data: [ u8 ; 8 ] = 1_u64 . to_ne_bytes ( ) ;
23
17
// Write 1 to the counter.
24
18
let res: i64 = unsafe {
25
19
libc:: write ( fd, sized_8_data. as_ptr ( ) as * const libc:: c_void , 8 ) . try_into ( ) . unwrap ( )
@@ -34,13 +28,7 @@ fn test_read_write() {
34
28
// Read returns number of bytes has been read, which is always 8.
35
29
assert_eq ! ( res, 8 ) ;
36
30
// Check the value of counter read.
37
- let counter: u64 ;
38
- if cfg ! ( target_endian = "big" ) {
39
- // Read will store the bytes based on the endianess of the host system.
40
- counter = u64:: from_be_bytes ( buf) ;
41
- } else {
42
- counter = u64:: from_le_bytes ( buf) ;
43
- }
31
+ let counter = u64:: from_ne_bytes ( buf) ;
44
32
assert_eq ! ( counter, 1 ) ;
45
33
46
34
// After read, the counter is currently 0, read counter 0 should fail with return
@@ -105,24 +93,12 @@ fn test_race() {
105
93
} ;
106
94
// read returns number of bytes has been read, which is always 8.
107
95
assert_eq ! ( res, 8 ) ;
108
- let counter: u64 ;
109
- if cfg ! ( target_endian = "big" ) {
110
- // Read will store the bytes based on the endianness of the host system.
111
- counter = u64:: from_be_bytes ( buf) ;
112
- } else {
113
- counter = u64:: from_le_bytes ( buf) ;
114
- }
96
+ let counter = u64:: from_ne_bytes ( buf) ;
115
97
assert_eq ! ( counter, 1 ) ;
116
98
unsafe { assert_eq ! ( VAL , 1 ) } ;
117
99
} ) ;
118
100
unsafe { VAL = 1 } ;
119
- let data: [ u8 ; 8 ] ;
120
- if cfg ! ( target_endian = "big" ) {
121
- // Adjust the data based on the endianness of host system.
122
- data = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ] ;
123
- } else {
124
- data = [ 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ;
125
- }
101
+ let data: [ u8 ; 8 ] = 1_u64 . to_ne_bytes ( ) ;
126
102
let res: i64 =
127
103
unsafe { libc:: write ( fd, data. as_ptr ( ) as * const libc:: c_void , 8 ) . try_into ( ) . unwrap ( ) } ;
128
104
// write returns number of bytes written, which is always 8.
0 commit comments