update and add spec links and only import needed types for sys_times and termios
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
//! sys/times.h implementation
|
||||
//! `sys/times.h` implementation.
|
||||
//!
|
||||
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_times.h.html>.
|
||||
|
||||
use platform;
|
||||
use platform::types::*;
|
||||
use platform::{Pal, Sys};
|
||||
use crate::platform;
|
||||
use platform::{Pal, Sys, types::clock_t};
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/sys_times.h.html>.
|
||||
#[repr(C)]
|
||||
pub struct tms {
|
||||
tms_utime: clock_t,
|
||||
@@ -12,6 +14,7 @@ pub struct tms {
|
||||
tms_cstime: clock_t,
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/times.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn times(out: *mut tms) -> clock_t {
|
||||
Sys::times(out)
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
//! termios implementation, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/termios.h.html
|
||||
//! `termios.h` implementation.
|
||||
//!
|
||||
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/termios.h.html>.
|
||||
|
||||
use crate::{
|
||||
header::{
|
||||
errno,
|
||||
sys_ioctl::{self, winsize},
|
||||
},
|
||||
platform::{self, types::*},
|
||||
platform::{
|
||||
self,
|
||||
types::{c_int, c_ulong, c_void},
|
||||
},
|
||||
};
|
||||
|
||||
pub use self::sys::*;
|
||||
@@ -35,6 +40,7 @@ pub const TCSANOW: c_int = 0;
|
||||
pub const TCSADRAIN: c_int = 1;
|
||||
pub const TCSAFLUSH: c_int = 2;
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/termios.h.html>.
|
||||
#[cfg(target_os = "linux")]
|
||||
#[repr(C)]
|
||||
#[derive(Default, Clone)]
|
||||
@@ -50,6 +56,7 @@ pub struct termios {
|
||||
}
|
||||
|
||||
// Must match structure in redox_termios
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/termios.h.html>.
|
||||
#[cfg(target_os = "redox")]
|
||||
#[repr(C)]
|
||||
#[derive(Default, Clone)]
|
||||
@@ -61,11 +68,13 @@ pub struct termios {
|
||||
pub c_cc: [cc_t; NCCS],
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcgetattr.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn tcgetattr(fd: c_int, out: *mut termios) -> c_int {
|
||||
sys_ioctl::ioctl(fd, sys_ioctl::TCGETS, out as *mut c_void)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcsetattr.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn tcsetattr(fd: c_int, act: c_int, value: *const termios) -> c_int {
|
||||
if act < 0 || act > 2 {
|
||||
@@ -76,12 +85,14 @@ pub unsafe extern "C" fn tcsetattr(fd: c_int, act: c_int, value: *const termios)
|
||||
sys_ioctl::ioctl(fd, sys_ioctl::TCSETS + act as c_ulong, value as *mut c_void)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cfgetispeed.html>.
|
||||
#[cfg(target_os = "linux")]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn cfgetispeed(termios_p: *const termios) -> speed_t {
|
||||
(*termios_p).__c_ispeed
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cfgetispeed.html>.
|
||||
#[cfg(target_os = "redox")]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn cfgetispeed(termios_p: *const termios) -> speed_t {
|
||||
@@ -89,12 +100,14 @@ pub unsafe extern "C" fn cfgetispeed(termios_p: *const termios) -> speed_t {
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cfgetospeed.html>.
|
||||
#[cfg(target_os = "linux")]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn cfgetospeed(termios_p: *const termios) -> speed_t {
|
||||
(*termios_p).__c_ospeed
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cfgetospeed.html>.
|
||||
#[cfg(target_os = "redox")]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn cfgetospeed(termios_p: *const termios) -> speed_t {
|
||||
@@ -102,6 +115,7 @@ pub unsafe extern "C" fn cfgetospeed(termios_p: *const termios) -> speed_t {
|
||||
0
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cfsetispeed.html>.
|
||||
#[cfg(target_os = "linux")]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn cfsetispeed(termios_p: *mut termios, speed: speed_t) -> c_int {
|
||||
@@ -117,6 +131,7 @@ pub unsafe extern "C" fn cfsetispeed(termios_p: *mut termios, speed: speed_t) ->
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cfsetispeed.html>.
|
||||
#[cfg(target_os = "redox")]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn cfsetispeed(termios_p: *mut termios, speed: speed_t) -> c_int {
|
||||
@@ -125,6 +140,7 @@ pub unsafe extern "C" fn cfsetispeed(termios_p: *mut termios, speed: speed_t) ->
|
||||
-1
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cfsetospeed.html>.
|
||||
#[cfg(target_os = "linux")]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn cfsetospeed(termios_p: *mut termios, speed: speed_t) -> c_int {
|
||||
@@ -140,6 +156,7 @@ pub unsafe extern "C" fn cfsetospeed(termios_p: *mut termios, speed: speed_t) ->
|
||||
}
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/cfsetospeed.html>.
|
||||
#[cfg(target_os = "redox")]
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn cfsetospeed(termios_p: *mut termios, speed: speed_t) -> c_int {
|
||||
@@ -148,6 +165,9 @@ pub unsafe extern "C" fn cfsetospeed(termios_p: *mut termios, speed: speed_t) ->
|
||||
-1
|
||||
}
|
||||
|
||||
/// Non-POSIX, 4.4 BSD extension
|
||||
///
|
||||
/// See <https://www.man7.org/linux/man-pages/man3/cfsetispeed.3.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn cfsetspeed(termios_p: *mut termios, speed: speed_t) -> c_int {
|
||||
let r = cfsetispeed(termios_p, speed);
|
||||
@@ -157,16 +177,19 @@ pub unsafe extern "C" fn cfsetspeed(termios_p: *mut termios, speed: speed_t) ->
|
||||
cfsetospeed(termios_p, speed)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcflush.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn tcflush(fd: c_int, queue: c_int) -> c_int {
|
||||
sys_ioctl::ioctl(fd, sys_ioctl::TCFLSH, queue as *mut c_void)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcdrain.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn tcdrain(fd: c_int) -> c_int {
|
||||
sys_ioctl::ioctl(fd, sys_ioctl::TCSBRK, 1 as *mut _)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcsendbreak.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn tcsendbreak(fd: c_int, _dur: c_int) -> c_int {
|
||||
// non-zero duration is ignored by musl due to it being
|
||||
@@ -174,11 +197,13 @@ pub unsafe extern "C" fn tcsendbreak(fd: c_int, _dur: c_int) -> c_int {
|
||||
sys_ioctl::ioctl(fd, sys_ioctl::TCSBRK, 0 as *mut _)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcsetwinsize.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn tcsetwinsize(fd: c_int, mut sws: winsize) -> c_int {
|
||||
sys_ioctl::ioctl(fd, sys_ioctl::TIOCSWINSZ, &mut sws as *mut _ as *mut c_void)
|
||||
}
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/tcflow.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn tcflow(fd: c_int, action: c_int) -> c_int {
|
||||
// non-zero duration is ignored by musl due to it being
|
||||
@@ -186,6 +211,9 @@ pub unsafe extern "C" fn tcflow(fd: c_int, action: c_int) -> c_int {
|
||||
sys_ioctl::ioctl(fd, sys_ioctl::TCXONC, action as *mut _)
|
||||
}
|
||||
|
||||
/// Non-POSIX, BSD extension
|
||||
///
|
||||
/// See <https://www.man7.org/linux/man-pages/man3/cfmakeraw.3.html>.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn cfmakeraw(termios_p: *mut termios) {
|
||||
(*termios_p).c_iflag &=
|
||||
|
||||
Reference in New Issue
Block a user