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