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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_52/] [or1ksim/] [port/] [strndup.c] - Diff between revs 1429 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 1429 Rev 1765
 
 
#include "config.h"
#include "config.h"
#include "port.h"
#include "port.h"
 
 
#include <string.h>
#include <string.h>
 
 
#if !defined(HAVE_STRNDUP)
#if !defined(HAVE_STRNDUP)
 
 
/* Taken from glibc */
/* Taken from glibc */
char *
char *
strndup (const char *s, size_t n)
strndup (const char *s, size_t n)
{
{
        char *new;
        char *new;
        size_t len = strlen (s);
        size_t len = strlen (s);
        if (len>n)
        if (len>n)
                len=n;
                len=n;
 
 
        new = (char *) malloc (len + 1);
        new = (char *) malloc (len + 1);
 
 
        if (new == NULL)
        if (new == NULL)
                return NULL;
                return NULL;
 
 
        new[len] = '\0';
        new[len] = '\0';
        return (char *) memcpy (new, s, len);
        return (char *) memcpy (new, s, len);
}
}
 
 
#endif
#endif
 
 

powered by: WebSVN 2.1.0

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