]> git.lizzy.rs Git - rust.git/blob - src/librustuv/macros.rs
Convert most code to new inner attribute syntax.
[rust.git] / src / librustuv / macros.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 #![macro_escape]
12
13 use std::fmt;
14
15 macro_rules! uverrln (
16     ($($arg:tt)*) => ( {
17         format_args!(::macros::dumb_println, $($arg)*)
18     } )
19 )
20
21 // Some basic logging. Enabled by passing `--cfg uvdebug` to the libstd build.
22 macro_rules! uvdebug (
23     ($($arg:tt)*) => ( {
24         if cfg!(uvdebug) {
25             uverrln!($($arg)*)
26         }
27     })
28 )
29
30 pub fn dumb_println(args: &fmt::Arguments) {
31     use std::io;
32     use std::libc;
33
34     struct Stderr;
35     impl io::Writer for Stderr {
36         fn write(&mut self, data: &[u8]) -> io::IoResult<()> {
37             let _ = unsafe {
38                 libc::write(libc::STDERR_FILENO,
39                             data.as_ptr() as *libc::c_void,
40                             data.len() as libc::size_t)
41             };
42             Ok(()) // just ignore the errors
43         }
44     }
45     let mut w = Stderr;
46     let _ = fmt::writeln(&mut w as &mut io::Writer, args);
47 }