mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Check locale in GetUserName
This commit is contained in:
committed by
Andrew Schwartzmeyer
parent
61b4e5513a
commit
197938c6a6
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user