termios.rs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #![allow(non_camel_case_types)]
  2. use libc::{self, c_int};
  3. use redox_termios::{tcflag_t, Termios};
  4. use syscall::{self, EINVAL, Error};
  5. use ::types::pid_t;
  6. type speed_t = libc::c_uint;
  7. // tcsetattr args
  8. pub const TCSANOW: tcflag_t = 0x1;
  9. pub const TCSADRAIN: tcflag_t = 0x2;
  10. pub const TCSAFLUSH: tcflag_t = 0x4;
  11. // tcflush args
  12. pub const TCIFLUSH: tcflag_t = 0x1;
  13. pub const TCIOFLUSH: tcflag_t = 0x3;
  14. pub const TCOFLUSH: tcflag_t = 0x2;
  15. // tcflow args
  16. pub const TCIOFF: tcflag_t = 0x1;
  17. pub const TCION: tcflag_t = 0x2;
  18. pub const TCOOFF: tcflag_t = 0x4;
  19. pub const TCOON: tcflag_t = 0x8;
  20. libc_fn!(unsafe tcgetattr(fd: c_int, tio: *mut Termios) -> Result<c_int> {
  21. let fd = syscall::dup(fd as usize, b"termios")?;
  22. let res = syscall::read(fd, &mut *tio);
  23. let _ = syscall::close(fd);
  24. if res? == (&*tio).len() {
  25. Ok(0)
  26. } else {
  27. Err(Error::new(EINVAL))
  28. }
  29. });
  30. libc_fn!(unsafe tcsetattr(fd: c_int, _arg: c_int, tio: *mut Termios) -> Result<c_int> {
  31. let fd = syscall::dup(fd as usize, b"termios")?;
  32. let res = syscall::write(fd, &*tio);
  33. let _ = syscall::close(fd);
  34. if res? == (&*tio).len() {
  35. Ok(0)
  36. } else {
  37. Err(Error::new(EINVAL))
  38. }
  39. });
  40. libc_fn!(cfgetispeed(_tio: *mut Termios) -> speed_t {
  41. // TODO
  42. 0 as speed_t
  43. });
  44. libc_fn!(cfgetospeed(_tio: *mut Termios) -> speed_t {
  45. // TODO
  46. 0 as speed_t
  47. });
  48. libc_fn!(cfsetispeed(_tio: *mut Termios, _speed: speed_t) -> Result<c_int> {
  49. // TODO
  50. Ok(0)
  51. });
  52. libc_fn!(cfsetospeed(_tio: *mut Termios, _speed: speed_t) -> Result<c_int> {
  53. // TODO
  54. Ok(0)
  55. });
  56. libc_fn!(tcdrain(_i: c_int) -> Result<c_int> {
  57. // TODO
  58. Ok(0)
  59. });
  60. libc_fn!(tcflow(_fd: c_int, _arg: c_int) -> Result<c_int> {
  61. // TODO
  62. Ok(0)
  63. });
  64. libc_fn!(tcflush(_fd: c_int, _arg: c_int) -> Result<c_int> {
  65. // TODO
  66. Ok(0)
  67. });
  68. libc_fn!(unsafe tcgetsid(_fd: c_int) -> pid_t {
  69. // TODO
  70. ::process::_getpid()
  71. });
  72. libc_fn!(tcsendbreak(_fd: c_int, _arg: c_int) -> Result<c_int> {
  73. // TODO
  74. Ok(0)
  75. });