4.115
Last change
on this file since da10694 was
7ae1c30,
checked in by Chris Johns <chrisj@…>, on 10/31/14 at 05:20:02
|
libnetworking: Fix the sethostname decl to match newlib.
|
-
Property mode set to
100644
|
File size:
830 bytes
|
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 <rtems/rtems_bsdnet.h> |
---|
13 | #include <sys/param.h> |
---|
14 | #include <sys/malloc.h> |
---|
15 | #include <sys/kernel.h> |
---|
16 | |
---|
17 | static char *rtems_hostname; |
---|
18 | |
---|
19 | int |
---|
20 | gethostname (char *name, size_t namelen) |
---|
21 | { |
---|
22 | char *cp = rtems_hostname; |
---|
23 | |
---|
24 | if (cp == NULL) |
---|
25 | cp = ""; |
---|
26 | strncpy (name, cp, namelen); |
---|
27 | return 0; |
---|
28 | } |
---|
29 | |
---|
30 | int |
---|
31 | sethostname (const char *name, size_t namelen) |
---|
32 | { |
---|
33 | char *old, *new; |
---|
34 | |
---|
35 | if (namelen >= MAXHOSTNAMELEN) { |
---|
36 | errno = EINVAL; |
---|
37 | return -1; |
---|
38 | } |
---|
39 | new = malloc (namelen + 1, M_HTABLE, M_NOWAIT); |
---|
40 | if (new == NULL) { |
---|
41 | errno = ENOMEM; |
---|
42 | return -1; |
---|
43 | } |
---|
44 | strncpy (new, name, namelen); |
---|
45 | new[namelen] = '\0'; |
---|
46 | old = rtems_hostname; |
---|
47 | rtems_hostname = new; |
---|
48 | if (old) |
---|
49 | free (old, M_HTABLE); |
---|
50 | return 0; |
---|
51 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.