Permalink
Browse files

provide ruby_strdup

  • Loading branch information...
1 parent 7bb772c commit 21ccc204103a3d7ef96a6404aece781432fb6f69 @timfel timfel committed Sep 13, 2012
Showing with 12 additions and 0 deletions.
  1. +12 −0 lib/ruby/1.8/include/ruby.h
@@ -810,6 +810,18 @@ RUBY_DLLSPEC VALUE rb_obj_as_string(VALUE obj);
RUBY_DLLSPEC VALUE rb_check_string_type(VALUE obj);
+// duplicate cstr
+static inline char* ruby_strdup(const char *str)
+{
+ char *tmp;
+ size_t len = strlen(str) + 1;
+
+ tmp = xmalloc(len);
+ memcpy(tmp, str, len);
+
+ return tmp;
+}
+
RUBY_DLLSPEC VALUE rb_str_dup(VALUE str);
RUBY_DLLSPEC VALUE rb_str_dup_frozen(VALUE str);

0 comments on commit 21ccc20

Please sign in to comment.