ruby-changes:40368
From: nobu <ko1@a...>
Date: Wed, 4 Nov 2015 16:50:28 +0900 (JST)
Subject: [ruby-changes:40368] nobu:r52449 (trunk): tkutil.c: strndup
nobu 2015-11-04 16:50:19 +0900 (Wed, 04 Nov 2015) New Revision: 52449 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52449 Log: tkutil.c: strndup * ext/tk/tkutil/tkutil.c (strndup): fallback definition. Modified files: trunk/ext/tk/tkutil/tkutil.c Index: ext/tk/tkutil/tkutil.c =================================================================== --- ext/tk/tkutil/tkutil.c (revision 52448) +++ ext/tk/tkutil/tkutil.c (revision 52449) @@ -90,6 +90,24 @@ static unsigned long CALLBACK_ID_NUM = 0 https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L90 /*************************************/ +#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) https://github.com/ruby/ruby/blob/trunk/ext/tk/tkutil/tkutil.c#L1611 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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/