File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
c2rust-transpile/tests/snapshots Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1
1
#include <errno.h>
2
2
#include <stdbool.h>
3
+ #include <string.h>
3
4
4
5
bool errno_is_error () { return errno != 0 ; }
5
6
@@ -17,3 +18,13 @@ int size_of_dynamic(int n) {
17
18
return SIZE ;
18
19
}
19
20
#endif
21
+
22
+ // From Lua's `lobject.c`.
23
+
24
+ #define POS "\"]"
25
+ /* number of chars of a literal string without the ending \0 */
26
+ #define LL (x ) (sizeof(x) / sizeof(char) - 1)
27
+
28
+ void memcpy_str_literal (char * out ) {
29
+ memcpy (out , POS , (LL (POS ) + 1 ) * sizeof (char ));
30
+ }
Original file line number Diff line number Diff line change @@ -14,7 +14,13 @@ input_file: c2rust-transpile/tests/snapshots/os-specific/macros.c
14
14
)]
15
15
extern " C" {
16
16
fn __errno_location () - > * mut std ::ffi ::c_int ;
17
+ fn memcpy (
18
+ __dest : * mut std ::ffi ::c_void ,
19
+ __src : * const std ::ffi ::c_void ,
20
+ __n : size_t ,
21
+ ) - > * mut std ::ffi ::c_void ;
17
22
}
23
+ pub type size_t = usize ;
18
24
#[no_mangle ]
19
25
pub unsafe extern " C" fn errno_is_error () - > bool {
20
26
return * __errno_location () != 0 as std ::ffi ::c_int ;
@@ -24,3 +30,15 @@ pub unsafe extern "C" fn size_of_const() -> std::ffi::c_int {
24
30
let mut a: [std ::ffi ::c_int ; 10 ] = [0 ; 10 ];
25
31
return ::core ::mem ::size_of ::< [std ::ffi ::c_int ; 10 ]> () as std ::ffi ::c_int ;
26
32
}
33
+ #[no_mangle ]
34
+ pub unsafe extern " C" fn memcpy_str_literal (mut out : * mut std ::ffi ::c_char ) {
35
+ memcpy (
36
+ out as *mut std ::ffi ::c_void ,
37
+ b " \" ]\0 " as *const u8 as *const std ::ffi ::c_char as *const std ::ffi ::c_void ,
38
+ (::core ::mem ::size_of ::< [std ::ffi ::c_char ; 3 ]> () as size_t )
39
+ .wrapping_div (::core ::mem ::size_of ::< std ::ffi ::c_char > () as size_t )
40
+ .wrapping_sub (1 as size_t )
41
+ .wrapping_add (1 as size_t )
42
+ .wrapping_mul (::core ::mem ::size_of ::< std ::ffi ::c_char > () as size_t ),
43
+ );
44
+ }
Original file line number Diff line number Diff line change @@ -14,7 +14,14 @@ input_file: c2rust-transpile/tests/snapshots/os-specific/macros.c
14
14
)]
15
15
extern " C" {
16
16
fn __error () - > * mut std ::ffi ::c_int ;
17
+ fn memcpy (
18
+ __dst : * mut std ::ffi ::c_void ,
19
+ __src : * const std ::ffi ::c_void ,
20
+ __n : size_t ,
21
+ ) - > * mut std ::ffi ::c_void ;
17
22
}
23
+ pub type __darwin_size_t = usize ;
24
+ pub type size_t = __darwin_size_t ;
18
25
#[no_mangle ]
19
26
pub unsafe extern " C" fn errno_is_error () - > bool {
20
27
return * __error () != 0 as std ::ffi ::c_int ;
@@ -24,3 +31,15 @@ pub unsafe extern "C" fn size_of_const() -> std::ffi::c_int {
24
31
let mut a: [std ::ffi ::c_int ; 10 ] = [0 ; 10 ];
25
32
return ::core ::mem ::size_of ::< [std ::ffi ::c_int ; 10 ]> () as std ::ffi ::c_int ;
26
33
}
34
+ #[no_mangle ]
35
+ pub unsafe extern " C" fn memcpy_str_literal (mut out : * mut std ::ffi ::c_char ) {
36
+ memcpy (
37
+ out as *mut std ::ffi ::c_void ,
38
+ b " \" ]\0 " as *const u8 as *const std ::ffi ::c_char as *const std ::ffi ::c_void ,
39
+ (::core ::mem ::size_of ::< [std ::ffi ::c_char ; 3 ]> () as size_t )
40
+ .wrapping_div (::core ::mem ::size_of ::< std ::ffi ::c_char > () as size_t )
41
+ .wrapping_sub (1 as size_t )
42
+ .wrapping_add (1 as size_t )
43
+ .wrapping_mul (::core ::mem ::size_of ::< std ::ffi ::c_char > () as size_t ),
44
+ );
45
+ }
You can’t perform that action at this time.
0 commit comments