mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
3553a86eb5
commit
8df1863dcb
1 changed files with 18 additions and 9 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue