Improve quality of uname/gethostname/getdomainname

This commit is contained in:
Justine Tunney 2022-09-03 19:07:19 -07:00
parent c5c4dfcd21
commit b66bd064d8
13 changed files with 334 additions and 151 deletions

View file

@ -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();