/*
* Document-method: open
* call-seq: Iconv.open(to, from) { |iconv| ... }
*
* Equivalent to Iconv.new except that when it is called with a block, it
* yields with the new instance and closes it, and returns the result which
* returned from the block.
*/
static VALUE
iconv_s_open
(self, to, from)
VALUE self;
VALUE to;
VALUE from;
{
VALUE cd = ICONV2VALUE(iconv_create(to, from));
self = Data_Wrap_Struct(self, NULL, ICONV_FREE, (void *)cd);
if (rb_block_given_p()) {
return rb_ensure(rb_yield, self, (VALUE(*)())iconv_finish, self);
}
else {
return self;
}
}