blob: 8ac5c58954b28f70dc1c0a0f9728972920191eb8 (
plain) (
blame)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
/*
* RTEMS versions of hostname functions
* FIXME: Not thread-safe
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <errno.h>
#include <rtems/rtems_bsdnet.h>
#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/kernel.h>
static char *rtems_hostname;
int
gethostname (char *name, size_t namelen)
{
char *cp = rtems_hostname;
if (cp == NULL)
cp = "";
strncpy (name, cp, namelen);
return 0;
}
int
sethostname (const char *name, size_t namelen)
{
char *old, *new;
if (namelen >= MAXHOSTNAMELEN) {
errno = EINVAL;
return -1;
}
new = malloc (namelen + 1, M_HTABLE, M_NOWAIT);
if (new == NULL) {
errno = ENOMEM;
return -1;
}
strncpy (new, name, namelen);
new[namelen] = '\0';
old = rtems_hostname;
rtems_hostname = new;
if (old)
free (old, M_HTABLE);
return 0;
}
|