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