]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys_common/util.rs
a373e980b970d21263aa8389ddece4cb26442365
[rust.git] / src / libstd / sys_common / util.rs
1 // Copyright 2013 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.
4 //
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.
10
11 use fmt;
12 use io::prelude::*;
13 use sys::stdio::{Stderr, stderr_prints_nothing};
14 use thread;
15
16 pub fn dumb_print(args: fmt::Arguments) {
17     if stderr_prints_nothing() {
18         return
19     }
20     let _ = Stderr::new().map(|mut stderr| stderr.write_fmt(args));
21 }
22
23 // Other platforms should use the appropriate platform-specific mechanism for
24 // aborting the process.  If no platform-specific mechanism is available,
25 // ::intrinsics::abort() may be used instead.  The above implementations cover
26 // all targets currently supported by libstd.
27
28 pub fn abort(args: fmt::Arguments) -> ! {
29     dumb_print(format_args!("fatal runtime error: {}\n", args));
30     unsafe { ::sys::abort_internal(); }
31 }
32
33 #[allow(dead_code)] // stack overflow detection not enabled on all platforms
34 pub unsafe fn report_overflow() {
35     dumb_print(format_args!("\nthread '{}' has overflowed its stack\n",
36                             thread::current().name().unwrap_or("<unknown>")));
37 }