PatchworkOS
Loading...
Searching...
No Matches
strdup.c
Go to the documentation of this file.
1#include <stdint.h>
2#include <stdlib.h>
3#include <string.h>
4
5char* strdup(const char* src)
6{
7 uint64_t len = strlen(src);
8 char* str = malloc(len + 1);
9 if (str == NULL)
10 {
11 return NULL;
12 }
13
14 memcpy(str, src, len);
15 str[len] = '\0';
16 return str;
17}
#define NULL
Pointer error value.
Definition NULL.h:23
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
_PUBLIC void * malloc(size_t size)
Definition malloc.c:5
char * strdup(const char *src)
Definition strdup.c:5
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
Definition memcpy.c:4
_PUBLIC size_t strlen(const char *s)
Definition strlen.c:3