impl strdup and strndup by myself
This commit is contained in:
parent
1e89fbaef1
commit
d48ae9227a
|
@ -154,6 +154,8 @@ const char *pic_symbol_name(pic_state *, pic_sym);
|
||||||
pic_sym pic_gensym(pic_state *, pic_sym);
|
pic_sym pic_gensym(pic_state *, pic_sym);
|
||||||
bool pic_interned_p(pic_state *, pic_sym);
|
bool pic_interned_p(pic_state *, pic_sym);
|
||||||
|
|
||||||
|
char *pic_strdup(pic_state *pic, const char *s);
|
||||||
|
char *pic_strndup(pic_state *pic, const char *s, size_t n);
|
||||||
struct pic_string *pic_str_new(pic_state *, const char *, size_t);
|
struct pic_string *pic_str_new(pic_state *, const char *, size_t);
|
||||||
struct pic_string *pic_str_new_cstr(pic_state *, const char *);
|
struct pic_string *pic_str_new_cstr(pic_state *, const char *);
|
||||||
|
|
||||||
|
|
17
src/blob.c
17
src/blob.c
|
@ -7,6 +7,23 @@
|
||||||
#include "picrin.h"
|
#include "picrin.h"
|
||||||
#include "picrin/blob.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 *
|
struct pic_blob *
|
||||||
pic_blob_new(pic_state *pic, char *dat, size_t len)
|
pic_blob_new(pic_state *pic, char *dat, size_t len)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue