Giter VIP home page Giter VIP logo

Comments (4)

gwenn avatar gwenn commented on August 28, 2024

Maybe I should use libc directly ?

libc::ioctl(libc::STDOUT_FILENO, TIOCGWINSZ, &mut size)

http://doc.rust-lang.org/libc/x86_64-apple-darwin/libc/fn.ioctl.html

from nix.

posborne avatar posborne commented on August 28, 2024

This works:

#![feature(libc)]

#[macro_use]
extern crate nix;
extern crate libc;

use std::mem;
use libc::c_ushort;


#[derive(Debug)]
#[repr(C)]
struct winsize {
    ws_row: c_ushort,
    ws_col: c_ushort,
    ws_xpixel: c_ushort,
    ws_ypixel: c_ushort
}

mod ioctl {
    use libc;

    #[cfg(any(target_os = "macos", target_os = "freebsd"))]
    const TIOCGWINSZ: libc::c_ulong = 0x40087468;
    #[cfg(any(target_os = "linux", target_os = "android"))]
    const TIOCGWINSZ: libc::c_ulong = 0x5413;
    ioctl!(bad read_winsize with TIOCGWINSZ);
}

fn main() {
    unsafe {
        let mut size: winsize = std::mem::zeroed();
        ioctl::read_winsize(0, mem::transmute(&mut size as *mut winsize)).unwrap();
        println!("Size: {:?}", size);
    }
}

from nix.

gwenn avatar gwenn commented on August 28, 2024

Thanks.

from nix.

posborne avatar posborne commented on August 28, 2024

I think the original implementation did probably find the wrong level of abstraction. Here, it would be nice to use the semantics you get with read but that is hard coded to do the equivalent of an _IOR. As discussed in #190, another option might have been to support both the macro and function interface approach.

For now, I certainly don't want to introduce another set of breaking changes.

from nix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.