mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
39 lines
746 B
C++
39 lines
746 B
C++
#include "getcomputername.h"
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
#include <string>
|
|
#include <langinfo.h>
|
|
|
|
BOOL GetComputerNameW(LPTSTR name, LPDWORD len)
|
|
{
|
|
const std::string utf8 = "UTF-8";
|
|
errno = 0;
|
|
|
|
// Check parameters
|
|
if (!name || !len) {
|
|
errno = ERROR_INVALID_PARAMETER;
|
|
return 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;
|
|
}
|
|
|
|
size_t len2 = *len;
|
|
int host = gethostname(name, len2);
|
|
if(host == 0)
|
|
{
|
|
return TRUE;
|
|
}
|
|
else
|
|
{
|
|
errno = ERROR_BUFFER_OVERFLOW;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|