Check locale in GetUserName

This commit is contained in:
Andrew Schwartzmeyer
2015-08-03 12:53:39 -07:00
committed by Andrew Schwartzmeyer
parent 61b4e5513a
commit 197938c6a6
2 changed files with 27 additions and 1 deletions
+26 -1
View File
@@ -1,8 +1,33 @@
#include "getusername.h"
#include <errno.h>
#include <langinfo.h>
#include <locale.h>
#include <unistd.h>
#include <string>
using namespace std;
const string utf8 = "UTF-8";
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724432(v=vs.85).aspx
// Sets errno to:
// ERROR_BAD_ENVIRONMENT - locale is not UTF-8
//
// Returns:
// 1 - succeeded
// 0 - failed
BOOL GetUserName(WCHAR_T* lpBuffer, LPDWORD lpnSize)
{
return 0;
errno = 0;
// Select locale from environment
setlocale(LC_ALL, "");
// Check that locale is UTF-8
if (nl_langinfo(CODESET) != utf8) {
errno = ERROR_BAD_ENVIRONMENT;
return 0;
}
return 1;
}
+1
View File
@@ -71,6 +71,7 @@
#define FALSE 0
#define ERROR_INVALID_PARAMETER 87
#define ERROR_OUTOFMEMORY 14
#define ERROR_BAD_ENVIRONMENT 0x0000000A
#define MAX_PATH 0x00000104
typedef unsigned long long uint64;
#endif