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::{self, IoError, IoResult};
16 use sys::{last_error, retry};
19 use path::BytesContainer;
24 pub mod helper_thread;
33 // common error constructors
35 pub fn eof() -> IoError {
43 pub fn timeout(desc: &'static str) -> IoError {
51 pub fn short_write(n: uint, desc: &'static str) -> IoError {
53 kind: if n == 0 { io::TimedOut } else { io::ShortWrite(n) },
59 pub fn unimpl() -> IoError {
61 kind: io::IoUnavailable,
62 desc: "operations not yet supported",
67 // unix has nonzero values as errors
68 pub fn mkerr_libc<T: Int>(ret: T) -> IoResult<()> {
69 if ret != Int::zero() {
76 pub fn keep_going<F>(data: &[u8], mut f: F) -> i64 where
77 F: FnMut(*const u8, uint) -> i64,
79 let origamt = data.len();
80 let mut data = data.as_ptr();
81 let mut amt = origamt;
83 let ret = retry(|| f(data, amt));
88 data = unsafe { data.offset(ret as int) };
93 return (origamt - amt) as i64;
96 // A trait for extracting representations from std::io types
97 pub trait AsInner<Inner> {
98 fn as_inner(&self) -> &Inner;
101 pub trait ProcessConfig<K: BytesContainer, V: BytesContainer> {
102 fn program(&self) -> &CString;
103 fn args(&self) -> &[CString];
104 fn env(&self) -> Option<&collections::HashMap<K, V>>;
105 fn cwd(&self) -> Option<&CString>;
106 fn uid(&self) -> Option<uint>;
107 fn gid(&self) -> Option<uint>;
108 fn detach(&self) -> bool;