MoarVM icon indicating copy to clipboard operation
MoarVM copied to clipboard

Building strncpy if not provided

Open Prince213 opened this issue 5 years ago • 0 comments

In MSVC, there is no strncpy, which makes it hard to build telemeh:

telemeh.obj : error LNK2001: unresolved external symbol strndup
moar.dll : fatal error LNK1120: 1 unresolved externals

A simple solution could be adding a definition of strncpy, like this:

char *strndup(char const *s, size_t n)
{
    size_t len = strnlen(s, n);
    char *new = malloc(len + 1);
    if (!new)
        return NULL;
    new[len] = '\0';
    return memcpy(new, s, len);
}

Prince213 avatar May 17 '20 16:05 Prince213