2015-04-03 10:22:05 -07:00
|
|
|
#include "getcomputername.h"
|
|
|
|
|
#include <unistd.h>
|
2015-07-30 12:46:28 -07:00
|
|
|
#include <errno.h>
|
2015-08-03 10:48:46 -07:00
|
|
|
#include <string>
|
|
|
|
|
#include <langinfo.h>
|
2015-04-03 10:22:05 -07:00
|
|
|
|
2015-08-03 10:48:46 -07:00
|
|
|
BOOL GetComputerNameW(LPTSTR name, LPDWORD len)
|
2015-04-03 10:22:05 -07:00
|
|
|
{
|
2015-08-03 10:48:46 -07:00
|
|
|
const std::string utf8 = "UTF-8";
|
2015-07-30 12:46:28 -07:00
|
|
|
errno = 0;
|
2015-08-03 10:48:46 -07:00
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-30 13:47:31 -07:00
|
|
|
size_t len2 = *len;
|
|
|
|
|
int host = gethostname(name, len2);
|
2015-04-09 15:16:37 -07:00
|
|
|
if(host == 0)
|
|
|
|
|
{
|
|
|
|
|
return TRUE;
|
2015-07-30 12:46:28 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
errno = ERROR_BUFFER_OVERFLOW;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2015-04-03 10:22:05 -07:00
|
|
|
}
|
2015-08-03 10:48:46 -07:00
|
|
|
|