mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-14 21:59:20 +00:00
51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
#include "getcpinfo.h"
|
|
#include <errno.h>
|
|
#include <string>
|
|
#include <langinfo.h>
|
|
|
|
|
|
// https://msdn.microsoft.com/en-us/library/windows/desktop/ms724432(v=vs.85).aspx
|
|
// Sets errno to:
|
|
// ERROR_INVALID_PARAMETER - parameter is not valid
|
|
// ERROR_BAD_ENVIRONMENT - locale is not UTF-8
|
|
//
|
|
// Returns:
|
|
// TRUE - succeeded
|
|
// FALSE - failed
|
|
|
|
BOOL GetCPInfoW(UINT codepage, CPINFO &cpinfo)
|
|
{
|
|
|
|
const std::string utf8 = "UTF-8";
|
|
errno = 0;
|
|
|
|
//Check that codepage is not null
|
|
if(!codepage) {
|
|
errno = ERROR_INVALID_PARAMETER;
|
|
return FALSE;
|
|
}
|
|
|
|
// Select locale from environment
|
|
setlocale(LC_ALL, "");
|
|
// Check that locale is UTF-8
|
|
if (nl_langinfo(CODESET) != utf8) {
|
|
errno = ERROR_BAD_ENVIRONMENT;
|
|
return 0;
|
|
}
|
|
|
|
//if codepage is utf8
|
|
if(codepage == 65001) {
|
|
cpinfo.DefaultChar[0] = '?';
|
|
cpinfo.DefaultChar[1] = '0';
|
|
cpinfo.LeadByte[0] = '0';
|
|
cpinfo.LeadByte[1] = '0';
|
|
cpinfo.MaxCharSize = 4;
|
|
return TRUE;
|
|
}
|
|
else{
|
|
errno = ERROR_INVALID_PARAMETER;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|