diff --git a/src/port/chklocale.c b/src/port/chklocale.c
index c9c680f..44d280c 100644
--- a/src/port/chklocale.c
+++ b/src/port/chklocale.c
@@ -239,7 +239,16 @@ win32_langinfo(const char *ctype)
 	{
 		r = malloc(16);			/* excess */
 		if (r != NULL)
-			sprintf(r, "CP%u", cp);
+		{
+			/*
+			 * If the return value is value is CP_ACP (0) that means no ANSI
+			 * code page is available, only Unicode can be used for the locale.
+			 */
+			if (cp == 0)
+				strncpy(r, "utf8", 5);
+			else
+				sprintf(r, "CP%u", cp);
+		}
 	}
 	else
 #endif
@@ -257,7 +266,15 @@ win32_langinfo(const char *ctype)
 			ln = strlen(codepage);
 			r = malloc(ln + 3);
 			if (r != NULL)
-				sprintf(r, "CP%s", codepage);
+			{
+				if (isdigit(*codepage))
+					sprintf(r, "CP%s", codepage);
+				else
+				{
+					/* most likely "utf8" */
+					strcpy(r, codepage);
+				}
+			}
 		}
 
 	}
