mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
Add error handing for bad enivronment and bad parameter
This commit is contained in:
1 parent
fb5279ad1e
commit
7a85d035c0
5 files changed
+30
-22
No files matched your search
@@ -1,10 +1,28 @@
|
||||
#include "getcomputername.h"
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <string>
|
||||
#include <langinfo.h>
|
||||
|
||||
BOOL GetComputerName(LPTSTR name, LPDWORD len)
|
||||
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)
|
||||
@@ -17,3 +35,4 @@ BOOL GetComputerName(LPTSTR name, LPDWORD len)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user