1use lazy_static::lazy_static;
2use libc::{c_char, c_int, FILE};
3
4extern "C" {
5
6 #[allow(dead_code)]
7 pub fn printf(__restrict__fmt: *const c_char, ...) -> c_int;
8
9 #[allow(dead_code)]
10 pub fn setlocale(__category: c_int, __locale: *const c_char) -> c_char;
11
12 #[allow(dead_code)]
13 pub fn fflush(__stream: *mut FILE) -> c_int;
14
15 #[allow(dead_code)]
16 pub static stdout: *mut libc::FILE;
17}
18
19const LC_ALL: c_int = 6;
20
21#[macro_export]
22macro_rules! cstr {
23 ($arg:expr) => {{
24 let st = concat!($arg, "\0");
25 let (ptr, _): (*const libc::c_char, usize) = core::mem::transmute(st);
26 ptr
27 }};
28}
29
30lazy_static! {
31 pub static ref enable_utf8: () = {
32 unsafe {
33 setlocale(LC_ALL, cstr!("en_US.utf8"));
34 }
35 };
36}
37
38#[macro_export]
39macro_rules! printf {
40 ($st:expr, $($args:expr),*) => (unsafe {
41 let _ = *enable_utf8;
42 printf(cstr!($st), $($args),*);
43 fflush(stdout);
44 })
45}