gethostname.c\unistd\src - musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/src/unistd/gethostname.c
blob: 633ef571a4011332e2b47fc14a1841e398cc792a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <unistd.h>
#include <sys/utsname.h>
int gethostname(char *name, size_t len)
{
	size_t i;
	struct utsname uts;
	if (uname(&uts)) return -1;
	if (len > sizeof uts.nodename) len = sizeof uts.nodename;
	for (i=0; i<len && (name[i] = uts.nodename[i]); i++);
	if (i && i==len) name[i-1] = 0;
	return 0;
}
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月08日 03:46:41 +0000

AltStyle によって変換されたページ (->オリジナル) /