Wrong mapping of C struct to Rust
<p>For educational purpose I try to access the <code>FILE</code> struct in Rust:</p>

<pre><code>unsafe {
    let passwd = libc::fopen("/etc/passwd".to_ptr(), &amp;('r' as libc::c_char));
    let fp = &amp;mut *(passwd as *mut MY_FILE);
    println!("flags={}, file={}", fp._flags, fp._file);
}
</code></pre>

<p>the <code>MY_FILE</code> struct I obtained by running bindgen on stdio.h (I'm on OS X):</p>

<pre><code>bindgen /usr/include/stdio.h
</code></pre>

<p>Somehow <code>_flags</code> is always <code>8</code> for files open in write mode (4 in read mode), so this flags seems off (I tested with a <code>C</code> code to verify that it indeed is not 4 or 8). The file pointer however seems to be right. What could cause this? Am I extracting the binding from the wrong header file? Is there something I need to add to the <code>#[repr(C,)]</code> attribute?</p>

<p><a href="https://gist.github.com/philippkeller/1f7cd1df9c48a5694c7e1e7c7952277d" rel="nofollow noreferrer">Here</a> is the full code including the struct.</p>

<p>This is a follow up question from <a href="https://stackoverflow.com/questions/38360996">an earlier question</a></p>