OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [libnetworking/] [rtems/] [sghostname.c] - Blame information for rev 507

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 * RTEMS versions of hostname functions
3
 * FIXME: Not thread-safe
4
 *
5
 *  $Id: sghostname.c,v 1.2 2001-09-27 12:02:00 chris Exp $
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
 
15
static char *rtems_hostname;
16
 
17
int
18
gethostname (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
 
28
int
29
sethostname (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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.