This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(dead_code, | |
non_camel_case_types, | |
non_upper_case_globals, | |
non_snake_case)] | |
extern crate libc; | |
extern crate apue; | |
use apue::ToPtr; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(non_camel_case_types)] | |
extern crate libc; | |
use std::ffi::CString; | |
extern { | |
pub fn getchar() -> libc::c_int; | |
} | |
// bindgen generaged code starts... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/unistd.rs b/src/unistd.rs | |
index 74d74c9..13defb8 100644 | |
--- a/src/unistd.rs | |
+++ b/src/unistd.rs | |
@@ -5,8 +5,8 @@ use fcntl::{fcntl, OFlag, O_NONBLOCK, O_CLOEXEC, FD_CLOEXEC}; | |
use fcntl::FcntlArg::{F_SETFD, F_SETFL}; | |
use libc::{self, c_char, c_void, c_int, c_uint, size_t, pid_t, off_t, uid_t, gid_t, mode_t}; | |
use std::mem; | |
-use std::ffi::{CString, CStr, OsString}; | |
-use std::os::unix::ffi::OsStringExt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fmt; | |
pub trait Join { | |
fn join(&self) -> String; | |
} | |
impl<T: fmt::Display> Join for [T] { | |
fn join(&self) -> String { | |
self.iter() | |
.map(|a| format!("{}", a)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// merges an array with ordinal numbers into a string | |
extern crate itertools; | |
use itertools::Itertools; | |
fn join_int_slice(slice:&[u8]) -> String { | |
slice.iter().map(|&a| a as char).join("") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate libc; | |
use libc::{passwd, getpwent, setpwent}; | |
use std::ffi::CString; | |
unsafe fn getpwnam(name: &str) -> Option<passwd> { | |
setpwent(); | |
while let Some(pw) = getpwent().as_ref() { | |
let pw_name = CString::from_raw(pw.pw_name).into_string().expect("found null"); | |
if pw_name == name { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn array_to_string(slice:&[i8]) -> String { | |
slice.iter().take_while(|&x| *x != 0).map(|&a| a as u8 as char).join("") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate libc; | |
extern crate itertools; | |
use libc::{utsname, uname}; | |
use std::ffi::CStr; | |
use itertools::Itertools; | |
fn array_to_string(slice:&[i8]) -> String { | |
slice.iter().take_while(|&x| *x != 0).map(|&a| a as u8 as char).join("") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# builds Cargo.toml for linux and macos | |
# and only includes files in src/bin/*/*.rs which | |
# are not excluded by a #!cfg(target_os="...") attribute | |
cd "$(dirname "$0")" | |
for os in linux macos; do | |
echo "creating Cargo.toml for $os" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub trait LibcResult<T> { | |
/// returns None if the result is empty (-1 if an integer, Null if a pointer) | |
/// and Some otherwise | |
/// | |
/// # Example | |
/// if let Some(fd) = libc::creat(fd1, FILE_MODE).to_option() { | |
/// fd | |
/// } else { | |
/// panic!("{}", io::Error::last_os_error()); | |
/// } |