Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gethostname.c « linux « sys « libc « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ef526916f659451e5623093ea20c394ab51806d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* Copyright 2002, Red Hat Inc. */

#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <machine/weakalias.h>

int
__gethostname (char *name, size_t len)
{
	struct utsname nodebuf;
	size_t nodelen;

	if (uname (&nodebuf))
		return -1;

	nodelen = strlen (nodebuf.nodename) + 1;
	if (len < nodelen)
		memcpy (name, nodebuf.nodename, len);
	else
		memcpy (name, nodebuf.nodename, nodelen);

	if (nodelen > len)
	{
		errno = ENAMETOOLONG;
		return -1;
	}
	return 0;
}
weak_alias(__gethostname, gethostname)