Skip to content

Can't compile on FreeBSD 11.0 - mismatched types at ioctl() call #12

@gchers

Description

@gchers

Problem description
Compilation fails at line 398 or src/unix/terminal.rs [1]:
let res = unsafe { ioctl(fd, TIOCGWINSZ, &mut winsz) };
with error:

398:34: 398:44 note: expected type u64
398:34: 398:44 note:    found type `u32`
error: aborting due to previous error
error: Could not compile `linefeed`.

Reason
The problem is that in rust libc for the platform x86_64-unknown-freebsd, TIOCGWINSZ is u32 and not u64 [2], while ioctl accepts u64 as a second argument [3].

I believe this is specific to freebsd. For example, in the case of x86_64-unknown-linux-gnu, TIOCGWINSZ is u64 [4].

Fix
It may be enough to cast TIOCGWINSZ to u64.

However, I'm not sure whether this has other effects (e.g., maybe for some architectures ioctl accepts u32?).

Edit
The fix I suggested would not work on the following architectures:
x86_64-unknown-linux-musl, arm-linux-androideabi, asmjs-unknown-emscripten, wasm32-unknown-emscripten,
where ioctl() accepts as a second parameter a u32 [5].

However, on those platforms TIOCGWINSZ is of type c_int, which means compilation of linefeed should succeed for them.

This means that the discrepancy (i.e., TIOCGWINSZ is u32 [2] but the second parameter of ioctl() is u64 [6]) only happens for freebsd.
Does this mean the problem should be fixed in rust libc?

[1] https://github.com/murarth/linefeed/blob/master/src/unix/terminal.rs#L398
[2] https://doc.rust-lang.org/libc/x86_64-unknown-freebsd/libc/constant.TIOCGWINSZ.html
[3] https://doc.rust-lang.org/libc/x86_64-unknown-freebsd/libc/fn.ioctl.html
[4] https://doc.rust-lang.org/libc/x86_64-unknown-linux-gnu/libc/constant.TIOCGWINSZ.html
[5] https://doc.rust-lang.org/libc/
[6] https://doc.rust-lang.org/libc/x86_64-unknown-freebsd/libc/fn.ioctl.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions