winos/
lib.rs

1/// Links an exported function from the specified library.
2#[macro_export]
3macro_rules! link {
4    ($loc:literal, $($def:tt)*) => {
5        #[allow(improper_ctypes)]
6        #[link(name = $loc)]
7        extern "system" { $($def)*; }
8    };
9}
10
11/// Compile time conversion from &str to a null terminated cstring
12#[macro_export]
13macro_rules! s {
14    ($s:literal) => {
15        core::concat!($s, '\0').as_ptr()
16    };
17}
18
19/// Compile time conversion from &str to a null terminated wstring
20#[macro_export]
21macro_rules! w {
22    ($s:literal) => {{
23        const S: &[u8] = $s.as_bytes();
24        const W: &[u16] = {
25            let mut buf = ['\0' as u16; S.len() + 1];
26            let mut i = 0;
27
28            while i < S.len() {
29                buf[i] = S[i] as _;
30                i += 1;
31            }
32
33            &{ buf }
34        };
35
36        W.as_ptr()
37    }};
38}