Index: /trunk/include/iprt/locale.h
===================================================================
--- /trunk/include/iprt/locale.h	(revision 68119)
+++ /trunk/include/iprt/locale.h	(revision 68119)
@@ -0,0 +1,69 @@
+/** @file
+ * IPRT - Locale and Related Info.
+ */
+
+/*
+ * Copyright (C) 2017 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+#ifndef ___iprt_locale_h
+#define ___iprt_locale_h
+
+#include <iprt/cdefs.h>
+#include <iprt/types.h>
+
+RT_C_DECLS_BEGIN
+
+/** @defgroup grp_rt_time   RTLocale - Locale and Related Info
+ * @ingroup grp_rt
+ * @{
+ */
+
+/**
+ * Returns the setlocale(LC_ALL,NULL) return value.
+ *
+ * @returns IPRT status code.
+ * @retval  VERR_NOT_SUPPORTED if not supported.
+ * @param   pszName         Where to return the name.
+ * @param   cbName          The size of the name buffer.
+ */
+RTDECL(int) RTLocaleQueryLocaleName(char *pszName, size_t cbName);
+
+
+/**
+ * Gets the two letter country code (ISO 3166-1 alpha-2) for the current user.
+ *
+ * This is not necessarily the country from the locale name, when possible the
+ * source is a different setting (host specific).
+ *
+ * @returns IPRT status code.
+ * @retval  VERR_NOT_SUPPORTED if not supported.
+ * @param   pszCountryCode  Pointer buffer that's at least three bytes in size.
+ *                          The country code will be returned here on success.
+ */
+RTDECL(int) RTLocaleQueryUserCountryCode(char pszCountryCode[3]);
+
+/** @} */
+
+RT_C_DECLS_END
+
+#endif
+
+
Index: /trunk/include/iprt/mangling.h
===================================================================
--- /trunk/include/iprt/mangling.h	(revision 68118)
+++ /trunk/include/iprt/mangling.h	(revision 68119)
@@ -1123,4 +1123,6 @@
 # define RTLocalIpcSessionQueryUserId                   RT_MANGLER(RTLocalIpcSessionQueryUserId)
 # define RTLocalIpcSessionQueryGroupId                  RT_MANGLER(RTLocalIpcSessionQueryGroupId)
+# define RTLocaleQueryLocaleName                        RT_MANGLER(RTLocaleQueryLocaleName)
+# define RTLocaleQueryUserCountryCode                   RT_MANGLER(RTLocaleQueryUserCountryCode)
 # define RTLockValidatorClassAddPriorClass              RT_MANGLER(RTLockValidatorClassAddPriorClass)
 # define RTLockValidatorClassCreate                     RT_MANGLER(RTLockValidatorClassCreate)
Index: /trunk/src/VBox/Runtime/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Runtime/Makefile.kmk	(revision 68118)
+++ /trunk/src/VBox/Runtime/Makefile.kmk	(revision 68119)
@@ -811,4 +811,5 @@
  	nt/RTNtPathExpand8dot3Path.cpp \
  	nt/RTNtPathFindPossible8dot3Name.cpp \
+ 	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
  	r3/nt/fs-nt.cpp \
  	r3/nt/pathint-nt.cpp \
@@ -819,4 +820,5 @@
 	r3/win/RTCrStoreCreateSnapshotById-win.cpp \
 	r3/win/RTHandleGetStandard-win.cpp \
+	r3/win/RTLocaleQueryUserCountryCode-win.cpp \
 	r3/win/RTSystemQueryOSInfo-win.cpp \
 	r3/win/RTSystemShutdown-win.cpp \
@@ -885,4 +887,6 @@
 	generic/utf16locale-generic.cpp \
 	generic/uuid-generic.cpp \
+ 	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
 	r3/posix/allocex-r3-posix.cpp \
@@ -994,4 +998,6 @@
 	os2/RTErrConvertFromOS2.cpp \
 	r3/generic/allocex-r3-generic.cpp \
+ 	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
 	r3/os2/filelock-os2.cpp \
@@ -1074,4 +1080,6 @@
 	r3/darwin/RTPathUserDocuments-darwin.cpp \
 	r3/generic/allocex-r3-generic.cpp \
+ 	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
 	r3/posix/RTFileQueryFsSizes-posix.cpp \
@@ -1145,4 +1153,6 @@
 	r3/freebsd/rtProcInitExePath-freebsd.cpp \
 	r3/generic/allocex-r3-generic.cpp \
+ 	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
 	r3/posix/RTFileQueryFsSizes-posix.cpp \
@@ -1215,4 +1225,6 @@
 	r3/netbsd/rtProcInitExePath-netbsd.cpp \
 	r3/generic/allocex-r3-generic.cpp \
+ 	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
 	r3/posix/RTFileQueryFsSizes-posix.cpp \
@@ -1278,4 +1290,6 @@
 	generic/RTThreadGetNativeState-generic.cpp \
 	r3/generic/allocex-r3-generic.cpp \
+ 	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
 	r3/posix/RTFileQueryFsSizes-posix.cpp \
@@ -1366,4 +1380,6 @@
 	r3/haiku/time-haiku.cpp \
 	r3/generic/allocex-r3-generic.cpp \
+ 	r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp \
+	r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp \
  	r3/generic/RTTimeZoneGetCurrent-generic.cpp \
 	r3/posix/RTFileQueryFsSizes-posix.cpp \
Index: /trunk/src/VBox/Runtime/r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp	(revision 68119)
+++ /trunk/src/VBox/Runtime/r3/generic/RTLocaleQueryLocaleName-r3-generic.cpp	(revision 68119)
@@ -0,0 +1,48 @@
+/* $Id$ */
+/** @file
+ * IPRT - RTLocaleQueryLocaleName, ring-3 generic.
+ */
+
+/*
+ * Copyright (C) 2017 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include <locale.h>
+
+#include <iprt/locale.h>
+#include "internal/iprt.h"
+
+#include <iprt/err.h>
+#include <iprt/string.h>
+
+
+
+RTDECL(int) RTLocaleQueryLocaleName(char *pszName, size_t cbName)
+{
+    const char *pszLocale = setlocale(LC_ALL, NULL);
+    if (!pszLocale)
+        return RTStrCopy(pszName, cbName, pszLocale);
+    return VERR_NOT_AVAILABLE;
+}
+
Index: /trunk/src/VBox/Runtime/r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp	(revision 68119)
+++ /trunk/src/VBox/Runtime/r3/generic/RTLocaleQueryUserCountryCode-r3-generic.cpp	(revision 68119)
@@ -0,0 +1,77 @@
+/* $Id$ */
+/** @file
+ * IPRT - RTLocaleQueryLocaleName, ring-3 generic.
+ */
+
+/*
+ * Copyright (C) 2017 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include <locale.h>
+
+#include <iprt/locale.h>
+#include "internal/iprt.h"
+
+#include <iprt/ctype.h>
+#include <iprt/err.h>
+#include <iprt/string.h>
+
+
+
+RTDECL(int) RTLocaleQueryUserCountryCode(char pszCountryCode[3])
+{
+    static const int s_aiLocales[] =
+    {
+        LC_ALL,
+        LC_CTYPE,
+        LC_COLLATE,
+        LC_MONETARY,
+        LC_NUMERIC,
+        LC_TIME
+    };
+
+    for (unsigned i = 0; i < RT_ELEMENTS(s_aiLocales); i++)
+    {
+        const char *pszLocale = setlocale(s_aiLocales[i], NULL);
+        if (   pszLocale
+            && strlen(pszLocale) >= 5
+            && RT_C_IS_ALPHA(pszLocale[0])
+            && RT_C_IS_ALPHA(pszLocale[1])
+            && pszLocale[2] == '_'
+            && RT_C_IS_ALPHA(pszLocale[3])
+            && RT_C_IS_ALPHA(pszLocale[4]))
+        {
+            pszCountryCode[0] = RT_C_TO_UPPER(pszLocale[3]);
+            pszCountryCode[1] = RT_C_TO_UPPER(pszLocale[4]);
+            pszCountryCode[2] = '\0';
+            return VINF_SUCCESS;
+        }
+    }
+
+    pszCountryCode[0] = 'Z';
+    pszCountryCode[1] = 'Z';
+    pszCountryCode[2] = '\0';
+    return VERR_NOT_AVAILABLE;
+}
+
Index: /trunk/src/VBox/Runtime/r3/win/RTLocaleQueryUserCountryCode-win.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/win/RTLocaleQueryUserCountryCode-win.cpp	(revision 68119)
+++ /trunk/src/VBox/Runtime/r3/win/RTLocaleQueryUserCountryCode-win.cpp	(revision 68119)
@@ -0,0 +1,119 @@
+/* $Id$ */
+/** @file
+ * IPRT - Log To Debugger, Win32.
+ */
+
+/*
+ * Copyright (C) 2006-2016 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+
+/*********************************************************************************************************************************
+*   Header Files                                                                                                                 *
+*********************************************************************************************************************************/
+#include <iprt/win/windows.h>
+
+#include <iprt/locale.h>
+#include "internal/iprt.h"
+
+#include <iprt/ctype.h>
+#include <iprt/err.h>
+#include <iprt/string.h>
+
+#include "internal-r3-win.h"
+
+
+/*********************************************************************************************************************************
+*   Structures and Typedefs                                                                                                      *
+*********************************************************************************************************************************/
+typedef GEOID (WINAPI *PFNGETUSERGEOID)(GEOCLASS);
+typedef INT   (WINAPI *PFNGETGEOINFOW)(GEOID,GEOTYPE,LPWSTR,INT,LANGID);
+
+
+/*********************************************************************************************************************************
+*   Global Variables                                                                                                             *
+*********************************************************************************************************************************/
+/** Pointer to GetUserGeoID. */
+static PFNGETUSERGEOID  g_pfnGetUserGeoID = NULL;
+/** Pointer to GetGeoInfoW. */
+static PFNGETGEOINFOW   g_pfnGetGeoInfoW = NULL;
+/** Set if we've tried to resolve the APIs. */
+static bool volatile    g_fResolvedApis = false;
+
+
+RTDECL(int) RTLocaleQueryUserCountryCode(char pszCountryCode[3])
+{
+    /*
+     * Get API pointers.
+     */
+    PFNGETUSERGEOID  pfnGetUserGeoID;
+    PFNGETGEOINFOW   pfnGetGeoInfoW;
+    if (g_fResolvedApis)
+    {
+        pfnGetUserGeoID = g_pfnGetUserGeoID;
+        pfnGetGeoInfoW  = g_pfnGetGeoInfoW;
+    }
+    else
+    {
+        pfnGetUserGeoID = (PFNGETUSERGEOID)GetProcAddress(g_hModKernel32, "GetUserGeoID");
+        pfnGetGeoInfoW  = (PFNGETGEOINFOW)GetProcAddress(g_hModKernel32, "GetGeoInfoW");
+        g_pfnGetUserGeoID = pfnGetUserGeoID;
+        g_pfnGetGeoInfoW  = pfnGetGeoInfoW;
+        g_fResolvedApis   = true;
+    }
+
+    int rc;
+    if (   pfnGetGeoInfoW
+        && pfnGetUserGeoID)
+    {
+        /*
+         * Call the API and retrieve the two letter ISO country code.
+         */
+        GEOID idGeo = pfnGetUserGeoID(GEOCLASS_NATION);
+        if (idGeo != GEOID_NOT_AVAILABLE)
+        {
+            RTUTF16 wszName[16];
+            RT_ZERO(wszName);
+            DWORD cwcReturned = pfnGetGeoInfoW(idGeo, GEO_ISO2, wszName, RT_ELEMENTS(wszName), LOCALE_NEUTRAL);
+            if (   cwcReturned >= 2
+                && cwcReturned <= 3
+                && wszName[2] == '\0'
+                && wszName[1] != '\0'
+                && RT_C_IS_ALPHA(wszName[1])
+                && wszName[0] != '\0'
+                && RT_C_IS_ALPHA(wszName[0]) )
+            {
+                pszCountryCode[0] = RT_C_TO_UPPER(wszName[0]);
+                pszCountryCode[1] = RT_C_TO_UPPER(wszName[1]);
+                pszCountryCode[2] = '\0';
+                return VINF_SUCCESS;
+            }
+            AssertMsgFailed(("cwcReturned=%d err=%u wszName='%.16ls'\n", cwcReturned, GetLastError(), wszName));
+        }
+        rc = VERR_NOT_AVAILABLE;
+    }
+    else
+        rc = VERR_NOT_SUPPORTED;
+    pszCountryCode[0] = 'Z';
+    pszCountryCode[1] = 'Z';
+    pszCountryCode[2] = '\0';
+    return rc;
+}
+
