mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-01 08:48:29 +00:00
Improve quality of uname/gethostname/getdomainname
This commit is contained in:
parent
c5c4dfcd21
commit
b66bd064d8
13 changed files with 334 additions and 151 deletions
|
@ -22,13 +22,22 @@
|
|||
#include "libc/nt/enum/computernameformat.h"
|
||||
#include "libc/nt/systeminfo.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
// Guarantees NUL-terminator, if zero is returned.
|
||||
// Mutates on ENAMETOOLONG without nul-terminator.
|
||||
textwindows int gethostname_nt(char *name, size_t len, int kind) {
|
||||
uint32_t nSize;
|
||||
char name8[256];
|
||||
char16_t name16[256];
|
||||
nSize = ARRAYLEN(name16);
|
||||
if (GetComputerNameEx(kind, name16, &nSize)) {
|
||||
tprecode16to8(name, len, name16);
|
||||
tprecode16to8(name8, sizeof(name8), name16);
|
||||
if (memccpy(name, name8, '\0', len)) {
|
||||
return 0;
|
||||
} else {
|
||||
return enametoolong();
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
return __winerr();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue