From: Roland Schulz Date: Sun, 19 Oct 2014 17:37:22 +0000 (-0400) Subject: Add Windows support for host-/username X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=251e942683b118dfaa6659bf0f06e11d70ead4ab;p=alexxy%2Fgromacs.git Add Windows support for host-/username Change-Id: I971ffc811bddea8c8663d3d1ce95678eddfd5860 --- diff --git a/src/gromacs/utility/sysinfo.cpp b/src/gromacs/utility/sysinfo.cpp index 65a3363fdf..cf7b6693ae 100644 --- a/src/gromacs/utility/sysinfo.cpp +++ b/src/gromacs/utility/sysinfo.cpp @@ -53,6 +53,7 @@ #include #endif #ifdef GMX_NATIVE_WINDOWS +#include #include #endif #ifdef HAVE_PWD_H @@ -74,7 +75,13 @@ const char c_unknown[] = "unknown"; int gmx_gethostname(char *buf, size_t len) { GMX_RELEASE_ASSERT(len >= 8, "Input buffer is too short"); -#if defined(HAVE_UNISTD_H) && !defined(__native_client__) && !defined(__MINGW32__) +#ifdef GMX_NATIVE_WINDOWS + DWORD dlen = len; + if (GetComputerName(buf, &dlen)) + { + return 0; + } +#elif defined(HAVE_UNISTD_H) && !defined(__native_client__) if (gethostname(buf, len-1) == 0) { buf[len-1] = '\0'; @@ -108,7 +115,13 @@ int gmx_getusername(char *buf, size_t len) GMX_RELEASE_ASSERT(len >= 8, "Input buffer is too short"); // TODO: nice_header() used getpwuid() instead; consider using getpwuid_r() // here. If not, get rid of HAVE_PWD_H completely. -#if defined(HAVE_UNISTD_H) && !defined(__MINGW32__) +#ifdef GMX_NATIVE_WINDOWS + DWORD dlen = len; + if (GetUserName(buf, &dlen)) + { + return 0; + } +#elif defined(HAVE_UNISTD_H) if (!getlogin_r(buf, len)) { buf[len-1] = '\0';