diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-04 07:50:19 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-11-04 07:50:19 +0000 |
commit | 716fd88109574e8606f51a39b9fa1a22aae258f2 (patch) | |
tree | 3995ac160a013bba6bfd37203e3687bbf8539ac3 /ext/tk/tkutil/tkutil.c | |
parent | 2731cdfd9d98358c4e4f7ec9ede8e675477fb73f (diff) | |
download | ruby-716fd88109574e8606f51a39b9fa1a22aae258f2.tar.gz |
tkutil.c: strndup
* ext/tk/tkutil/tkutil.c (strndup): fallback definition.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52449 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/tkutil/tkutil.c')
-rw-r--r-- | ext/tk/tkutil/tkutil.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/ext/tk/tkutil/tkutil.c b/ext/tk/tkutil/tkutil.c index 2bfb6bf50a..5d6613c7c2 100644 --- a/ext/tk/tkutil/tkutil.c +++ b/ext/tk/tkutil/tkutil.c @@ -90,6 +90,24 @@ static unsigned long CALLBACK_ID_NUM = 0; /*************************************/ +#ifndef HAVE_STRNDUP +static char * strndup _((const char *, size_t)); +static char * +strndup(ptr, len) + const char *ptr; + size_t len; +{ + char *newptr = malloc(len + 1); + if (newptr) { + memcpy(newptr, ptr, len); + newptr[len] = '\0'; + } + return newptr; +} +#endif + +/*************************************/ + #if defined(HAVE_RB_OBJ_INSTANCE_EXEC) && !defined(RUBY_VM) extern VALUE rb_obj_instance_exec _((int, VALUE*, VALUE)); #endif @@ -1593,17 +1611,8 @@ cbsubst_table_setup(argc, argv, self) chr = (unsigned char)(0x80 + idx); subst_inf->keylen[chr] = RSTRING_LEN(infp[0]); -#if HAVE_STRNDUP subst_inf->key[chr] = strndup(RSTRING_PTR(infp[0]), RSTRING_LEN(infp[0])); -#else - subst_inf->key[chr] = malloc(RSTRING_LEN(infp[0]) + 1); - if (subst_inf->key[chr]) { - strncpy(subst_inf->key[chr], RSTRING_PTR(infp[0]), - RSTRING_LEN(infp[0]) + 1); - subst_inf->key[chr][RSTRING_LEN(infp[0])] = '\0'; - } -#endif subst_inf->type[chr] = NUM2CHR(infp[1]); subst_inf->full_subst_length += (subst_inf->keylen[chr] + 2); |