* ext/tk/tkutil/extronf.rb: check stdndup() because it's not standard

function of C.

	* ext/tk/tkutil/tkutil.c (cbsubst_table_setup): use malloc() and
	  strncpy() instead of strndup() if not available.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16415 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2008-05-14 08:16:51 +00:00
parent d37d14c0a5
commit e9d69ca0ce
4 changed files with 21 additions and 3 deletions

View file

@ -1522,8 +1522,17 @@ cbsubst_table_setup(argc, argv, self)
chr = (unsigned char)(0x80 + idx);
subst_inf->keylen[chr] = RSTRING_LEN(RARRAY_PTR(inf)[0]);
#if HAVE_STRNDUP
subst_inf->key[chr] = strndup(RSTRING_PTR(RARRAY_PTR(inf)[0]),
RSTRING_LEN(RARRAY_PTR(inf)[0]));
#else
subst_inf->key[chr] = malloc(RSTRING_LEN(RARRAY_PTR(inf)[0]) + 1);
if (subst_inf->key[chr]) {
strncpy(subst_inf->key[chr], RSTRING_PTR(RARRAY_PTR(inf)[0]),
RSTRING_LEN(RARRAY_PTR(inf)[0]) + 1);
subst_inf->key[chr][RSTRING_LEN(RARRAY_PTR(inf)[0])] = '\0';
}
#endif
if (TYPE(RARRAY_PTR(inf)[1]) == T_STRING) {
subst_inf->type[chr] = *(RSTRING_PTR(RARRAY_PTR(inf)[1]));
} else {