source: rtems/c/src/lib/libnetworking/rtems/sghostname.c @ 39e6e65a

4.104.114.84.95
Last change on this file since 39e6e65a was 39e6e65a, checked in by Joel Sherrill <joel.sherrill@…>, on 08/19/98 at 21:32:28

Base files

  • Property mode set to 100644
File size: 772 bytes
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
13static char *rtems_hostname;
14
15int
16gethostname (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
26int
27sethostname (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.