【发布时间】:2016-07-13 20:18:39
【问题描述】:
我正在尝试访问libc 的FILE 结构的不同字段。
根据stdio.h中的内存映射在Rust中实现FILE:
#[repr(C)]
pub struct FILE {
pub _p: libc::c_char,
pub _r: libc::c_int,
pub _w: libc::c_int,
pub _flags: libc::c_short,
pub _file: libc::c_short,
...
}
当在 libc 中使用 FILEs 时,它们出现在 mut * 变体中,这在某种程度上妨碍了访问字段。以下代码触发error: attempted access of field_flagson type '*mut FILE', but no field with that name was found。
let stdout = libc::fdopen(libc::STDOUT_FILENO, &('w' as libc::c_char));
let is_unbuffered = (fp._flags & libc::_IONBF as i16) != 0
没有mut * 变体的FILE 类型的变量可以工作,但我需要让它与mut * 一起工作。
【问题讨论】: