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
5
char
*
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
}
NULL
#define NULL
Pointer error value.
Definition
NULL.h:23
stdint.h
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
stdlib.h
malloc
_PUBLIC void * malloc(size_t size)
Definition
malloc.c:5
strdup
char * strdup(const char *src)
Definition
strdup.c:5
string.h
memcpy
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
Definition
memcpy.c:4
strlen
_PUBLIC size_t strlen(const char *s)
Definition
strlen.c:3
src
libstd
user
functions
string
strdup.c
Generated by
1.9.8