4.104.114.84.95
Line | |
---|
1 | /* |
---|
2 | * RTEMS versions of hostname functions |
---|
3 | * FIXME: Not thread-safe |
---|
4 | */ |
---|
5 | |
---|
6 | #include <string.h> |
---|
7 | #include <errno.h> |
---|
8 | #include <rtems/rtems_bsdnet.h> |
---|
9 | #include <sys/param.h> |
---|
10 | #include <sys/malloc.h> |
---|
11 | #include <sys/kernel.h> |
---|
12 | |
---|
13 | static char *rtems_hostname; |
---|
14 | |
---|
15 | int |
---|
16 | gethostname (char *name, int namelen) |
---|
17 | { |
---|
18 | char *cp = rtems_hostname; |
---|
19 | |
---|
20 | if (cp == NULL) |
---|
21 | cp = ""; |
---|
22 | strncpy (name, cp, namelen); |
---|
23 | return 0; |
---|
24 | } |
---|
25 | |
---|
26 | int |
---|
27 | sethostname (char *name, int namelen) |
---|
28 | { |
---|
29 | char *old, *new; |
---|
30 | |
---|
31 | if (namelen >= MAXHOSTNAMELEN) { |
---|
32 | errno = EINVAL; |
---|
33 | return -1; |
---|
34 | } |
---|
35 | new = malloc (namelen + 1, M_HTABLE, M_NOWAIT); |
---|
36 | if (new == NULL) { |
---|
37 | errno = ENOMEM; |
---|
38 | return -1; |
---|
39 | } |
---|
40 | strncpy (new, name, namelen); |
---|
41 | new[namelen] = '\0'; |
---|
42 | old = rtems_hostname; |
---|
43 | rtems_hostname = new; |
---|
44 | if (old) |
---|
45 | free (old, M_HTABLE); |
---|
46 | return 0; |
---|
47 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.