File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,22 +6,24 @@ use std::io::prelude::*;
66use std:: io:: { Read , Seek , Write } ;
77use std:: os:: fd:: AsFd ;
88use std:: rc:: { Rc , Weak } ;
9- pub fn strchr_0 ( s : Ptr < u8 > , c : i32 ) -> Ptr < u8 > {
10- let s: Value < Ptr < u8 > > = Rc :: new ( RefCell :: new ( s) ) ;
11- let c: Value < i32 > = Rc :: new ( RefCell :: new ( c) ) ;
12- return Ptr :: < u8 > :: null ( ) ;
9+ pub fn fopen_0 ( path : Ptr < u8 > , mode : Ptr < u8 > ) -> Ptr < :: std:: fs:: File > {
10+ let path: Value < Ptr < u8 > > = Rc :: new ( RefCell :: new ( path) ) ;
11+ let mode: Value < Ptr < u8 > > = Rc :: new ( RefCell :: new ( mode) ) ;
12+ ( * path. borrow ( ) ) . clone ( ) ;
13+ ( * mode. borrow ( ) ) . clone ( ) ;
14+ return Ptr :: null ( ) ;
1315}
1416pub fn main ( ) {
1517 std:: process:: exit ( main_0 ( ) ) ;
1618}
1719fn main_0 ( ) -> i32 {
18- let p : Value < Ptr < u8 > > = Rc :: new ( RefCell :: new (
20+ let fp : Value < Ptr < :: std :: fs :: File > > = Rc :: new ( RefCell :: new (
1921 ( {
20- let _s : Ptr < u8 > = Ptr :: from_string_literal ( "hello " ) ;
21- let _c : i32 = ( 'l' as i32 ) ;
22- strchr_0 ( _s , _c )
22+ let _path : Ptr < u8 > = Ptr :: from_string_literal ( "/etc/passwd " ) ;
23+ let _mode : Ptr < u8 > = Ptr :: from_string_literal ( "r" ) ;
24+ fopen_0 ( _path , _mode )
2325 } ) ,
2426 ) ) ;
25- assert ! ( ( ( ( ( * p . borrow( ) ) . is_null( ) ) as i32 ) != 0 ) ) ;
27+ assert ! ( ( ( ( ( * fp . borrow( ) ) . is_null( ) ) as i32 ) != 0 ) ) ;
2628 return 0 ;
2729}
Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ use std::collections::BTreeMap;
66use std:: io:: { Read , Seek , Write } ;
77use std:: os:: fd:: { AsFd , FromRawFd , IntoRawFd } ;
88use std:: rc:: Rc ;
9- pub unsafe fn strchr_0 ( mut s : * const u8 , mut c : i32 ) -> * mut u8 {
9+ pub unsafe fn fopen_0 ( mut path : * const u8 , mut mode : * const u8 ) -> * mut :: std:: fs:: File {
10+ & ( path) ;
11+ & ( mode) ;
1012 return std:: ptr:: null_mut ( ) ;
1113}
1214pub fn main ( ) {
@@ -15,12 +17,11 @@ pub fn main() {
1517 }
1618}
1719unsafe fn main_0 ( ) -> i32 {
18- let mut p: * const u8 = ( unsafe {
19- let _s: * const u8 = b"hello\0 " . as_ptr ( ) . cast_mut ( ) . cast_const ( ) ;
20- let _c: i32 = ( 'l' as i32 ) ;
21- strchr_0 ( _s, _c)
22- } )
23- . cast_const ( ) ;
24- assert ! ( ( ( ( ( p) . is_null( ) ) as i32 ) != 0 ) ) ;
20+ let mut fp: * mut :: std:: fs:: File = ( unsafe {
21+ let _path: * const u8 = b"/etc/passwd\0 " . as_ptr ( ) . cast_mut ( ) . cast_const ( ) ;
22+ let _mode: * const u8 = b"r\0 " . as_ptr ( ) . cast_mut ( ) . cast_const ( ) ;
23+ fopen_0 ( _path, _mode)
24+ } ) ;
25+ assert ! ( ( ( ( ( fp) . is_null( ) ) as i32 ) != 0 ) ) ;
2526 return 0 ;
2627}
Original file line number Diff line number Diff line change 11#include <assert.h>
2- #include <stddef .h>
2+ #include <stdio .h>
33
4- char * strchr (const char * s , int c ) { return NULL ; }
4+ FILE * fopen (const char * path , const char * mode ) {
5+ (void )path ;
6+ (void )mode ;
7+ return NULL ;
8+ }
59
610int main () {
7- const char * p = strchr ( "hello " , 'l' );
8- assert (p == NULL );
11+ FILE * fp = fopen ( "/etc/passwd " , "r" );
12+ assert (fp == NULL );
913 return 0 ;
1014}
You can’t perform that action at this time.
0 commit comments