unimpl.rs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. use syscall;
  2. use libc::{c_uint, c_int, c_char, gid_t, uid_t, c_void, c_long, mode_t};
  3. use syscall::error::{Error, EACCES, EPERM, EINVAL};
  4. #[allow(non_camel_case_types)]
  5. type clock_t = c_long;
  6. macro_rules! UNIMPL {
  7. // Call with arguments and return value
  8. ($func:ident, $err:ident) => {{
  9. let err = Error::new($err);
  10. let _ = syscall::write(2, format!("unimplemented: {}: {}\n",
  11. stringify!($func), err).as_bytes());
  12. Err(err)
  13. }};
  14. }
  15. libc_fn!(alarm(_seconds: c_uint) -> c_uint {
  16. let _ = syscall::write(2, "unimplemented: alarm\n".as_bytes());
  17. 0
  18. });
  19. libc_fn!(chown(_path: *mut c_char, _order: uid_t, _group: gid_t) -> Result<c_int> {
  20. UNIMPL!(chown, EACCES)
  21. });
  22. libc_fn!(_getdtablesize() -> Result<c_int> {
  23. Ok(65536)
  24. });
  25. // XXX variadic
  26. libc_fn!(_ioctl(_file: c_int, _request: c_int) -> Result<c_int> {
  27. UNIMPL!(_ioctl, EINVAL)
  28. });
  29. libc_fn!(_link(_old: *const c_char, _new: *const c_char) -> Result<c_int> {
  30. UNIMPL!(_link, EPERM)
  31. });
  32. /*
  33. libc_fn!(sysconf(_name: c_int) -> Result<c_long> {
  34. UNIMPL!(sysconf, EINVAL)
  35. });
  36. */
  37. // XXX type of argument pointer
  38. libc_fn!(_times(_buf: *mut c_void) -> Result<clock_t> {
  39. UNIMPL!(_times, EINVAL)
  40. });
  41. libc_fn!(umask(_mode: mode_t) -> mode_t {
  42. // All permissions granted
  43. 0o000
  44. });
  45. libc_fn!(ttyname(_fd: c_int) -> Result<*const c_char> {
  46. UNIMPL!(ttyname, EINVAL)
  47. });
  48. libc_fn!(fpathconf(_fildes: c_int, _name: c_int) -> Result<c_long> {
  49. UNIMPL!(fpathconf, EINVAL)
  50. });
  51. libc_fn!(getlogin() -> Result<*const c_char> {
  52. UNIMPL!(getlogin, EINVAL)
  53. });