impl strdup and strndup by myself

This commit is contained in:
Yuichi Nishiwaki
2014-02-01 19:31:59 +09:00
parent 1e89fbaef1
commit d48ae9227a
2 changed files with 19 additions and 0 deletions
+17
View File
@@ -7,6 +7,23 @@
#include "picrin.h"
#include "picrin/blob.h"
char *
pic_strndup(pic_state *pic, const char *s, size_t n)
{
char *r;
r = pic_alloc(pic, n + 1);
memcpy(r, s, n);
r[n] = '\0';
return r;
}
char *
pic_strdup(pic_state *pic, const char *s)
{
return pic_strndup(pic, s, strlen(s));
}
struct pic_blob *
pic_blob_new(pic_state *pic, char *dat, size_t len)
{