source: rtems/c/src/lib/libnetworking/rtems/sghostname.c @ 94b3ee13

4.104.114.84.95
Last change on this file since 94b3ee13 was 94b3ee13, checked in by Joel Sherrill <joel.sherrill@…>, on 01/21/99 at 22:25:43

Made to compile after hacking tftp driver into beginnings of a mini-filesystem.

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