1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 #![allow(missing_docs)]
14 use io::{mod, IoError, IoResult};
16 use sys::{last_error, retry, fs};
19 use path::BytesContainer;
23 pub mod helper_thread;
25 // common error constructors
27 pub fn eof() -> IoError {
35 pub fn timeout(desc: &'static str) -> IoError {
43 pub fn short_write(n: uint, desc: &'static str) -> IoError {
45 kind: if n == 0 { io::TimedOut } else { io::ShortWrite(n) },
51 pub fn unimpl() -> IoError {
53 kind: io::IoUnavailable,
54 desc: "operations not yet supported",
59 // unix has nonzero values as errors
60 pub fn mkerr_libc<T: Int>(ret: T) -> IoResult<()> {
61 if ret != Int::zero() {
68 pub fn keep_going(data: &[u8], f: |*const u8, uint| -> i64) -> i64 {
69 let origamt = data.len();
70 let mut data = data.as_ptr();
71 let mut amt = origamt;
73 let ret = retry(|| f(data, amt));
78 data = unsafe { data.offset(ret as int) };
83 return (origamt - amt) as i64;
86 // traits for extracting representations from
88 pub trait AsFileDesc {
89 fn as_fd(&self) -> &fs::FileDesc;
92 pub trait ProcessConfig<K: BytesContainer, V: BytesContainer> {
93 fn program(&self) -> &CString;
94 fn args(&self) -> &[CString];
95 fn env(&self) -> Option<&collections::HashMap<K, V>>;
96 fn cwd(&self) -> Option<&CString>;
97 fn uid(&self) -> Option<uint>;
98 fn gid(&self) -> Option<uint>;
99 fn detach(&self) -> bool;