diff --git a/.vscode/settings.json b/.vscode/settings.json index 7ab8242..9144e21 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,16 +11,17 @@ // "rust-analyzer.cargo.target": "wasm32-wasi", "rust-analyzer.cargo.target": "x86_64-apple-darwin", "cSpell.words": [ - "binstall", - "COMPUTERNAME", - "gethostname", - "libc", - "objc", - "sysinfoapi", - "thiserror", - "wasi", - "winapi", - "winbase" + "binstall", + "COMPUTERNAME", + "gethostname", + "libc", + "objc", + "sysctlbyname", + "sysinfoapi", + "thiserror", + "wasi", + "winapi", + "winbase" ], "java.configuration.updateBuildConfiguration": "interactive" } diff --git a/rust/macos/objc/nick_name.rs b/rust/macos/objc/nick_name.rs index d9ef1a1..4960a30 100644 --- a/rust/macos/objc/nick_name.rs +++ b/rust/macos/objc/nick_name.rs @@ -37,6 +37,13 @@ impl NickName { if NSImageNameComputer.is_null() { println!("NSImageNameComputer is null"); + } else { + println!("NSImageNameComputer is not null"); + // https://github.com/servo/core-foundation-rs/blob/d4ce710182f1756c9d874ab917283fe1a1b7a011/cocoa-foundation/src/foundation.rs#L632 + let rust_string: *const libc::c_char = unsafe { msg_send![ns_string, UTF8String] }; + let rust_string = unsafe { CStr::from_ptr(rust_string) }; + let rust_string = rust_string.to_str().unwrap(); + println!("rust_string: {}", rust_string); } println!("NSImageNameComputer: {:?}", NSImageNameComputer); @@ -77,7 +84,7 @@ impl NickName { Ok(hostname) } - pub fn get_hostname(&self) -> crate::Result { + pub fn get_by_gethostname(&self) -> crate::Result { // ホスト名を格納するバッファのサイズを指定 // https://pubs.opengroup.org/onlinepubs/9699919799/functions/gethostname.html let limit = unsafe { libc::sysconf(libc::_SC_HOST_NAME_MAX) }; @@ -101,7 +108,7 @@ impl NickName { } } - fn get_name(&self) -> crate::Result { + fn get_by_sysctlbyname(&self) -> crate::Result { let mut mib: [libc::c_int; 2] = [0, 0]; let mut len: libc::size_t = 0;