mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 05:42: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
|
@ -16,15 +16,19 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/utsname.h"
|
||||
#include "libc/calls/struct/utsname-linux.internal.h"
|
||||
#include "libc/calls/syscall_support-sysv.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
int gethostname_linux(char *name, size_t len) {
|
||||
struct utsname u;
|
||||
if (uname(&u) == -1) return -1;
|
||||
memccpy(name, u.nodename, '\0', len);
|
||||
name[len - 1] = '\0';
|
||||
return 0;
|
||||
struct utsname_linux uts;
|
||||
if (!sys_uname_linux(&uts)) {
|
||||
if (memccpy(name, uts.nodename, '\0', len)) {
|
||||
return 0;
|
||||
} else {
|
||||
return enametoolong();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue