Skip to content

File strdup.c

File List > base > posix > strdup.c

Go to the documentation of this file.

/* Copyright (c) Kuba Szczodrzyński 2022-05-16. */

#include <stddef.h>
#include <stdlib.h>
#include <string.h>

__attribute__((weak)) char *strdup(const char *s) {
    size_t len = strlen(s) + 1;
    void *newp = malloc(len);
    if (newp == NULL)
        return NULL;
    return (char *)memcpy(newp, s, len);
}