File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -1931,5 +1931,9 @@ fn test_wasi(target: &str) {
19311931 // import the same thing but have different function pointers
19321932 cfg. skip_fn_ptrcheck ( |f| f. starts_with ( "__wasi" ) ) ;
19331933
1934+ // d_name is declared as a flexible array in WASI libc, so it
1935+ // doesn't support sizeof.
1936+ cfg. skip_field ( |s, field| s == "dirent" && field == "d_name" ) ;
1937+
19341938 cfg. generate ( "../src/lib.rs" , "main.rs" ) ;
19351939}
Original file line number Diff line number Diff line change @@ -141,12 +141,6 @@ s! {
141141 fds_bits: [ c_ulong; FD_SETSIZE / ULONG_SIZE ] ,
142142 }
143143
144- pub struct dirent {
145- pub d_ino: ino_t,
146- pub d_type: c_uchar,
147- pub d_name: [ c_char; 1024 ] ,
148- }
149-
150144 pub struct lconv {
151145 pub decimal_point: * mut c_char,
152146 pub thousands_sep: * mut c_char,
@@ -303,6 +297,20 @@ s_no_extra_traits! {
303297
304298}
305299
300+ // Declare dirent outside of s! so that it doesn't implement Copy, Eq, Hash,
301+ // etc., since it contains a flexible array member with a dynamic size.
302+ #[ repr( C ) ]
303+ #[ allow( missing_copy_implementations) ]
304+ #[ cfg_attr( feature = "extra_traits" , derive( Debug ) ) ]
305+ pub struct dirent {
306+ pub d_ino : ino_t ,
307+ pub d_type : c_uchar ,
308+ /// d_name is declared in WASI libc as a flexible array member, which
309+ /// can't be directly expressed in Rust. As an imperfect workaround,
310+ /// declare it as a zero-length array instead.
311+ pub d_name : [ c_char ; 0 ] ,
312+ }
313+
306314// intentionally not public, only used for fd_set
307315cfg_if ! {
308316 if #[ cfg( target_pointer_width = "32" ) ] {
You can’t perform that action at this time.
0 commit comments