@@ -10,7 +10,10 @@ import com.intellij.openapi.project.Project
1010import com.intellij.openapi.project.guessProjectDir
1111import com.intellij.openapi.roots.ModuleRootManager
1212import com.intellij.psi.util.PsiUtilBase
13- import com.kstruct.gethostname4j.Hostname
13+ import com.sun.jna.Library
14+ import com.sun.jna.Native
15+ import com.sun.jna.Platform
16+ import com.sun.jna.platform.win32.Kernel32Util
1417import kotlinx.coroutines.runBlocking
1518import org.jetbrains.concurrency.await
1619
@@ -56,9 +59,21 @@ object ContextInformation {
5659 }
5760 }
5861
59- fun getHostname (): String? = try {
60- Hostname .getHostname()
61- } catch (e: RuntimeException ) {
62- null
62+ interface UnixCLibrary : Library {
63+ companion object {
64+ val INSTANCE : UnixCLibrary = Native .load(" c" , UnixCLibrary ::class .java)
65+ }
66+
67+ fun gethostname (name : ByteArray , len : Int ): Int
68+ }
69+
70+ fun getHostname (): String? {
71+ return if (Platform .isWindows()) {
72+ Kernel32Util .getComputerName();
73+ } else {
74+ val buffer = ByteArray (4097 )
75+ val result = UnixCLibrary .INSTANCE .gethostname(buffer, buffer.size)
76+ if (result == 0 ) String (buffer).trim { it <= ' ' } else null
77+ }
6378 }
6479}
0 commit comments