| 1 | extern crate libudev_sys as udevrust-analyzer cargo libudev-sys 0.1.4 udev/; |
| 2 | extern crate libcrust-analyzer cargo libudev-sys 0.1.4 libc/; |
| 3 | |
| 4 | |
| 5 | #[cfg(hwdb)] use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/; |
| 6 | #[cfg(hwdb)] use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/; |
| 7 | #[cfg(hwdb)] use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#,CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#}; |
| 8 | #[cfg(hwdb)] use libcrust-analyzer cargo libc 0.2.189 crate/::c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#; |
| 9 | |
| 10 | #[cfg(hwdb)] |
| 11 | fn mainrust-analyzer cargo libudev-sys 0.1.4 main().() { |
| 12 | |
| 13 | let args = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/args().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>(); |
| 14 | |
| 15 | if args.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().2 { |
| 16 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Usage: hwdb_query <modalias>"); |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | let query = CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(args[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 21 | |
| 22 | unsafe { |
| 23 | let udev = udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_newrust-analyzer cargo libudev-sys 0.1.4 udev_new().(); |
| 24 | |
| 25 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().udev.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() { |
| 26 | let hwdb = udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_hwdb_newrust-analyzer cargo libudev-sys 0.1.4 udev_hwdb_new().(udev); |
| 27 | |
| 28 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().hwdb.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() { |
| 29 | query_hwdbrust-analyzer cargo libudev-sys 0.1.4 query_hwdb().(hwdb, &query); |
| 30 | udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_hwdb_unrefrust-analyzer cargo libudev-sys 0.1.4 udev_hwdb_unref().(hwdb); |
| 31 | } |
| 32 | |
| 33 | udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_unrefrust-analyzer cargo libudev-sys 0.1.4 udev_unref().(udev); |
| 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | #[cfg(hwdb)] |
| 39 | unsafe fn query_hwdbrust-analyzer cargo libudev-sys 0.1.4 query_hwdb().(hwdb: *mut udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_hwdbrust-analyzer cargo libudev-sys 0.1.4 hwdb/udev_hwdb#, query: &CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#) { |
| 40 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:>30}: {:?}", "query", query); |
| 41 | |
| 42 | udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_hwdb_refrust-analyzer cargo libudev-sys 0.1.4 udev_hwdb_ref().(hwdb); |
| 43 | print_resultsrust-analyzer cargo libudev-sys 0.1.4 print_results().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_hwdb_get_properties_list_entryrust-analyzer cargo libudev-sys 0.1.4 udev_hwdb_get_properties_list_entry().(hwdb, query.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]as_ptr().(), 0)); |
| 44 | udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_hwdb_unrefrust-analyzer cargo libudev-sys 0.1.4 udev_hwdb_unref().(hwdb); |
| 45 | } |
| 46 | |
| 47 | #[cfg(hwdb)] |
| 48 | unsafe fn print_resultsrust-analyzer cargo libudev-sys 0.1.4 print_results().(list_entry: *mut udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_list_entryrust-analyzer cargo libudev-sys 0.1.4 udev_list_entry#) { |
| 49 | if list_entry.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().() { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | let key = unwrap_strrust-analyzer cargo libudev-sys 0.1.4 unwrap_str().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_list_entry_get_namerust-analyzer cargo libudev-sys 0.1.4 udev_list_entry_get_name().(list_entry)); |
| 54 | let val = unwrap_strrust-analyzer cargo libudev-sys 0.1.4 unwrap_str().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_list_entry_get_valuerust-analyzer cargo libudev-sys 0.1.4 udev_list_entry_get_value().(list_entry)); |
| 55 | |
| 56 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:>30}: {}", key, val); |
| 57 | |
| 58 | print_resultsrust-analyzer cargo libudev-sys 0.1.4 print_results().(udevrust-analyzer cargo libudev-sys 0.1.4 crate/::udev_list_entry_get_nextrust-analyzer cargo libudev-sys 0.1.4 udev_list_entry_get_next().(list_entry)); |
| 59 | } |
| 60 | |
| 61 | #[cfg(hwdb)] |
| 62 | unsafe fn unwrap_strrust-analyzer cargo libudev-sys 0.1.4 unwrap_str().<'a>(ptr: *const c_charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/primitives/c_char#) -> &'a str { |
| 63 | strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(ptr).to_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]to_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 64 | } |
| 65 | |
| 66 | |
| 67 | #[cfg(not(hwdb))] |
| 68 | fn main() { |
| 69 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("hwdb is not supported by native libudev"); |
| 70 | } |