]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Remove overengineered win32 gethostname fallback code
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 15 May 2020 18:14:36 +0000 (20:14 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 20 May 2020 18:05:58 +0000 (20:05 +0200)
Let’s assume that all systems we reasonably support have access to
gethostname. If not, revisit later.

Regarding the win32 case: Since the replacement code (triggered if
HAVE_GETHOSTNAME isn’t defined) itself uses gethostname, just use
gethostname.

configure.ac
src/legacy_util.cpp

index f5baba3945f57f907c43ba342f8e96d95f48fb43..a900ed6269679de84c39d415db2cbeb4d11ea0d5 100644 (file)
@@ -120,7 +120,6 @@ AC_CHECK_HEADERS(linux/fs.h)
 AC_CHECK_HEADERS(sys/clonefile.h)
 
 AC_CHECK_FUNCS(asctime_r)
-AC_CHECK_FUNCS(gethostname)
 AC_CHECK_FUNCS(getopt_long)
 AC_CHECK_FUNCS(getpwuid)
 AC_CHECK_FUNCS(gettimeofday)
index 34e58eea22af1fc53b1cdf422d1426baaf726953..f73d4c2c68fdc81ae34516203406bdabd7c9490b 100644 (file)
@@ -267,65 +267,9 @@ get_hostname()
     return hostname;
   }
 
-  strcpy(hostname, "unknown");
-#if HAVE_GETHOSTNAME
-  gethostname(hostname, sizeof(hostname) - 1);
-#elif defined(_WIN32)
-  const char* computer_name = getenv("COMPUTERNAME");
-  if (computer_name) {
-    snprintf(hostname, sizeof(hostname), "%s", computer_name);
-    return hostname;
+  if (gethostname(hostname, sizeof(hostname)) != 0) {
+    strcpy(hostname, "unknown");
   }
-
-  WORD w_version_requested = MAKEWORD(2, 2);
-  WSADATA wsa_data;
-  int err = WSAStartup(w_version_requested, &wsa_data);
-  if (err != 0) {
-    // Tell the user that we could not find a usable Winsock DLL.
-    cc_log("WSAStartup failed with error: %d", err);
-    return hostname;
-  }
-
-  if (LOBYTE(wsa_data.wVersion) != 2 || HIBYTE(wsa_data.wVersion) != 2) {
-    // Tell the user that we could not find a usable WinSock DLL.
-    cc_log("Could not find a usable version of Winsock.dll");
-    WSACleanup();
-    return hostname;
-  }
-
-  int result = gethostname(hostname, sizeof(hostname) - 1);
-  if (result != 0) {
-    LPVOID lp_msg_buf;
-    DWORD dw = WSAGetLastError();
-
-    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
-                    | FORMAT_MESSAGE_IGNORE_INSERTS,
-                  NULL,
-                  dw,
-                  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-                  (LPTSTR)&lp_msg_buf,
-                  0,
-                  NULL);
-
-    LPVOID lp_display_buf = (LPVOID)LocalAlloc(
-      LMEM_ZEROINIT,
-      (lstrlen((LPCTSTR)lp_msg_buf) + lstrlen((LPCTSTR)__FILE__) + 200)
-        * sizeof(TCHAR));
-    _snprintf((LPTSTR)lp_display_buf,
-              LocalSize(lp_display_buf) / sizeof(TCHAR),
-              TEXT("%s failed with error %lu: %s"),
-              __FILE__,
-              dw,
-              (const char*)lp_msg_buf);
-
-    cc_log("can't get hostname OS returned error: %s", (char*)lp_display_buf);
-
-    LocalFree(lp_msg_buf);
-    LocalFree(lp_display_buf);
-  }
-  WSACleanup();
-#endif
-
   hostname[sizeof(hostname) - 1] = 0;
   return hostname;
 }