mirror of
https://github.com/RPCS3/llvm.git
synced 2024-11-26 13:10:42 +00:00
Add strndup
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11638 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
bbdfe40ba7
commit
a8032090aa
@ -6,8 +6,6 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
void *malloc(size_t);
|
||||
void free(void *);
|
||||
|
||||
size_t strlen(const char *Str) {
|
||||
size_t Count = 0;
|
||||
@ -16,12 +14,21 @@ size_t strlen(const char *Str) {
|
||||
}
|
||||
|
||||
char *strdup(const char *str) {
|
||||
long Len = strlen(str);
|
||||
size_t Len = strlen(str);
|
||||
char *Result = (char*)malloc((Len+1)*sizeof(char));
|
||||
memcpy(Result, str, Len+1);
|
||||
return Result;
|
||||
}
|
||||
|
||||
char *strndup(const char *str, size_t n) {
|
||||
size_t Len = strlen(str);
|
||||
if (Len > n) Len = n;
|
||||
char *Result = (char*)malloc((Len+1)*sizeof(char));
|
||||
memcpy(Result, str, Len);
|
||||
Result[Len] = 0;
|
||||
return Result;
|
||||
}
|
||||
|
||||
char *strcpy(char *s1, const char *s2) {
|
||||
char *dest = s1;
|
||||
while ((*s1++ = *s2++));
|
||||
|
Loading…
Reference in New Issue
Block a user