lib.rs 969 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //! fcntl implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.h.html
  2. #![no_std]
  3. #![allow(non_camel_case_types)]
  4. #[macro_use]
  5. extern crate syscall;
  6. pub use sys::*;
  7. #[cfg(all(not(feature="no_std"), target_os = "linux"))]
  8. #[path="linux/mod.rs"]
  9. mod sys;
  10. #[cfg(all(not(feature="no_std"), target_os = "redox"))]
  11. #[path="redox/mod.rs"]
  12. mod sys;
  13. pub mod types;
  14. use core::fmt;
  15. use types::*;
  16. pub unsafe fn c_str(s: *const c_char) -> &'static [u8] {
  17. use core::slice;
  18. let mut size = 0;
  19. loop {
  20. if *s.offset(size) == 0 {
  21. break;
  22. }
  23. size += 1;
  24. }
  25. slice::from_raw_parts(s as *const u8, size as usize)
  26. }
  27. pub struct FileWriter(pub c_int);
  28. impl FileWriter {
  29. pub fn write(&mut self, buf: &[u8]) {
  30. write(self.0, buf);
  31. }
  32. }
  33. impl fmt::Write for FileWriter {
  34. fn write_str(&mut self, s: &str) -> fmt::Result {
  35. self.write(s.as_bytes());
  36. Ok(())
  37. }
  38. }