source: rtems/cpukit/libnetworking/rtems/sghostname.c @ e800b07

5
Last change on this file since e800b07 was e800b07, checked in by Sebastian Huber <sebastian.huber@…>, on 04/22/16 at 07:15:11

network: Fix warnings

  • Property mode set to 100644
File size: 850 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 <unistd.h>
13#include <rtems/rtems_bsdnet.h>
14#include <sys/param.h>
15#include <sys/malloc.h>
16#include <sys/kernel.h>
17
18static char *rtems_hostname;
19
20int
21gethostname (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
31int
32sethostname (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.