alekmaul / pvsneslib

PVSnesLib : A small, open and free development kit for the Nintendo SNES
MIT License
847 stars 74 forks source link

strdup error #294

Closed alekmaul closed 4 days ago

alekmaul commented 1 week ago

From REHvolution2024: Can you tell my why strdup is not found, although it's in string.h: Reference to an unknown label "strdup". I just want a mutable string, that's all. (Sure I know how to write my own strdup, but if it's available I want to use this one.)

revvv commented 1 week ago

Although this code is trivial it might help in the meantime:

char* str_dup(const char* s)
{
    u8 len = strlen(s);
    char* res = malloc(len + 1);
    u8 i;
    for (i = 0; i < len; i++)
        res[i] = s[i];
    res[len] = '\0';
    return res;
}

Homework: Use memcpy

alekmaul commented 1 week ago

Yeah, I agree but my goal is to translate it in 65C816 assembly code ;)

alekmaul commented 4 days ago

it is too much complicated to add it. I will remove the declaration from the .h file and close the issue. sorry :(