@@ -225,19 +225,115 @@ pub unsafe fn test_ftruncate_5() {
225225 assert ! ( ( ( ( ( libc:: fclose( fp) ) == ( 0 ) ) as i32 ) != 0 ) ) ;
226226 libc:: unlink ( path as * const i8 ) ;
227227}
228- pub unsafe fn test_isatty_6 ( ) {
228+ pub unsafe fn test_open_6 ( ) {
229+ let mut path: * const u8 = ( b"/tmp/cpp2rust_open_test.tmp\0 " . as_ptr ( ) . cast_mut ( ) ) . cast_const ( ) ;
230+ let mut fd: i32 =
231+ ( unsafe { libc:: open ( path as * const i8 , ( ( ( 1 ) | ( 64 ) ) | ( 512 ) ) as i32 , ( 420 ) ) } ) ;
232+ assert ! ( ( ( ( ( fd) >= ( 0 ) ) as i32 ) != 0 ) ) ;
233+ assert ! (
234+ ( ( ( ( libc:: write(
235+ fd,
236+ ( b"hello world\0 " . as_ptr( ) . cast_mut( ) as * const u8 as * const :: libc:: c_void) ,
237+ 11_u64 as usize
238+ ) as i64 )
239+ == ( 11_i64 ) ) as i32 )
240+ != 0 )
241+ ) ;
242+ assert ! ( ( ( ( ( libc:: close( fd) ) == ( 0 ) ) as i32 ) != 0 ) ) ;
243+ fd = ( unsafe { libc:: open ( path as * const i8 , 0 as i32 ) } ) ;
244+ assert ! ( ( ( ( ( fd) >= ( 0 ) ) as i32 ) != 0 ) ) ;
245+ let mut buf: [ u8 ; 16 ] = [
246+ 0_u8 , 0_u8 , 0_u8 , 0_u8 , 0_u8 , 0_u8 , 0_u8 , 0_u8 , 0_u8 , 0_u8 , 0_u8 , 0_u8 , 0_u8 , 0_u8 , 0_u8 ,
247+ 0_u8 ,
248+ ] ;
249+ assert ! (
250+ ( ( ( ( libc:: read(
251+ fd,
252+ ( buf. as_mut_ptr( ) as * mut u8 as * mut :: libc:: c_void) ,
253+ 16_u64 as usize
254+ ) as i64 )
255+ == ( 11_i64 ) ) as i32 )
256+ != 0 )
257+ ) ;
258+ assert ! (
259+ ( ( ( ( {
260+ let sa = core:: slice:: from_raw_parts(
261+ ( buf. as_mut_ptr( ) as * const u8 as * const :: libc:: c_void) as * const u8 ,
262+ 11_u64 as usize ,
263+ ) ;
264+ let sb = core:: slice:: from_raw_parts(
265+ ( b"hello world\0 " . as_ptr( ) . cast_mut( ) as * const u8 as * const :: libc:: c_void)
266+ as * const u8 ,
267+ 11_u64 as usize ,
268+ ) ;
269+ let mut diff = 0_i32 ;
270+ for ( x, y) in sa. iter( ) . zip( sb. iter( ) ) {
271+ if x != y {
272+ diff = ( * x as i32 ) - ( * y as i32 ) ;
273+ break ;
274+ }
275+ }
276+ diff
277+ } ) == ( 0 ) ) as i32 )
278+ != 0 )
279+ ) ;
280+ assert ! ( ( ( ( ( libc:: close( fd) ) == ( 0 ) ) as i32 ) != 0 ) ) ;
281+ libc:: unlink ( path as * const i8 ) ;
282+ }
283+ pub unsafe fn test_fcntl_7 ( ) {
284+ let mut path: * const u8 = ( b"/tmp/cpp2rust_fcntl_test.tmp\0 " . as_ptr ( ) . cast_mut ( ) ) . cast_const ( ) ;
285+ let mut fd: i32 =
286+ ( unsafe { libc:: open ( path as * const i8 , ( ( ( 1 ) | ( 64 ) ) | ( 512 ) ) as i32 , ( 420 ) ) } ) ;
287+ assert ! ( ( ( ( ( fd) >= ( 0 ) ) as i32 ) != 0 ) ) ;
288+ let mut flags: i32 = ( unsafe { libc:: fcntl ( fd as i32 , 3 as i32 ) } ) ;
289+ assert ! ( ( ( ( ( flags) != ( -1_i32 ) ) as i32 ) != 0 ) ) ;
290+ assert ! (
291+ ( ( ( ( unsafe { libc:: fcntl( fd as i32 , 4 as i32 , ( ( flags) | ( 1024 ) ) , ) } ) == ( 0 ) ) as i32 ) != 0 )
292+ ) ;
293+ assert ! ( ( ( ( ( ( unsafe { libc:: fcntl( fd as i32 , 3 as i32 , ) } ) & ( 1024 ) ) != ( 0 ) ) as i32 ) != 0 ) ) ;
294+ assert ! ( ( ( ( ( libc:: close( fd) ) == ( 0 ) ) as i32 ) != 0 ) ) ;
295+ libc:: unlink ( path as * const i8 ) ;
296+ }
297+ pub unsafe fn test_ioctl_8 ( ) {
298+ let mut fds: [ i32 ; 2 ] = [ 0_i32 ; 2 ] ;
299+ assert ! ( ( ( ( ( libc:: pipe( fds. as_mut_ptr( ) ) ) == ( 0 ) ) as i32 ) != 0 ) ) ;
300+ assert ! (
301+ ( ( ( ( libc:: write(
302+ fds[ ( 1 ) as usize ] ,
303+ ( b"abcd\0 " . as_ptr( ) . cast_mut( ) as * const u8 as * const :: libc:: c_void) ,
304+ 4_u64 as usize
305+ ) as i64 )
306+ == ( 4_i64 ) ) as i32 )
307+ != 0 )
308+ ) ;
309+ let mut navail: i32 = 0 ;
310+ assert ! (
311+ ( ( ( ( unsafe {
312+ libc:: ioctl(
313+ fds[ ( 0 ) as usize ] as i32 ,
314+ 21531_u64 as u64 ,
315+ ( & mut navail as * mut i32 ) ,
316+ )
317+ } ) == ( 0 ) ) as i32 )
318+ != 0 )
319+ ) ;
320+ assert ! ( ( ( ( ( navail) == ( 4 ) ) as i32 ) != 0 ) ) ;
321+ assert ! ( ( ( ( ( libc:: close( fds[ ( 0 ) as usize ] ) ) == ( 0 ) ) as i32 ) != 0 ) ) ;
322+ assert ! ( ( ( ( ( libc:: close( fds[ ( 1 ) as usize ] ) ) == ( 0 ) ) as i32 ) != 0 ) ) ;
323+ }
324+ pub unsafe fn test_isatty_9 ( ) {
229325 printf (
230326 ( b"%d\n \0 " . as_ptr ( ) . cast_mut ( ) ) . cast_const ( ) as * const i8 ,
231327 libc:: isatty ( 0 ) ,
232328 ) ;
233329}
234- pub unsafe fn test_geteuid_7 ( ) {
330+ pub unsafe fn test_geteuid_10 ( ) {
235331 printf (
236332 ( b"%u\n \0 " . as_ptr ( ) . cast_mut ( ) ) . cast_const ( ) as * const i8 ,
237333 libc:: geteuid ( ) ,
238334 ) ;
239335}
240- pub unsafe fn test_gethostname_8 ( ) {
336+ pub unsafe fn test_gethostname_11 ( ) {
241337 let mut name: [ u8 ; 256 ] = [ 0_u8 ; 256 ] ;
242338 assert ! (
243339 ( ( ( ( libc:: gethostname(
@@ -263,8 +359,11 @@ unsafe fn main_0() -> i32 {
263359 ( unsafe { test_unlink_3 ( ) } ) ;
264360 ( unsafe { test_pipe_4 ( ) } ) ;
265361 ( unsafe { test_ftruncate_5 ( ) } ) ;
266- ( unsafe { test_isatty_6 ( ) } ) ;
267- ( unsafe { test_geteuid_7 ( ) } ) ;
268- ( unsafe { test_gethostname_8 ( ) } ) ;
362+ ( unsafe { test_open_6 ( ) } ) ;
363+ ( unsafe { test_fcntl_7 ( ) } ) ;
364+ ( unsafe { test_ioctl_8 ( ) } ) ;
365+ ( unsafe { test_isatty_9 ( ) } ) ;
366+ ( unsafe { test_geteuid_10 ( ) } ) ;
367+ ( unsafe { test_gethostname_11 ( ) } ) ;
269368 return 0 ;
270369}
0 commit comments