diff options
author | technorama <technorama@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-06-08 15:02:04 +0000 |
---|---|---|
committer | technorama <technorama@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-06-08 15:02:04 +0000 |
commit | 18342ff8e00ebe27584786276a68d99767a2c38d (patch) | |
tree | 9e7f4f09dace24fe7af05763aa9dbb6ae67550b8 /ext/openssl/ossl_bio.c | |
parent | f5be4ddc8d2d76f8d3543c5ecfd852199b20b7d2 (diff) |
import OpenSSL from trunk
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@12496 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_bio.c')
-rw-r--r-- | ext/openssl/ossl_bio.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/ext/openssl/ossl_bio.c b/ext/openssl/ossl_bio.c index 9c9aa24197..6db1fb9a62 100644 --- a/ext/openssl/ossl_bio.c +++ b/ext/openssl/ossl_bio.c @@ -19,16 +19,29 @@ ossl_obj2bio(VALUE obj) BIO *bio; if (TYPE(obj) == T_FILE) { - OpenFile *fptr; + rb_io_t *fptr; + FILE *fp; + int fd; + GetOpenFile(obj, fptr); rb_io_check_readable(fptr); - bio = BIO_new_fp(fptr->f, BIO_NOCLOSE); - } + if ((fd = dup(FPTR_TO_FD(fptr))) < 0){ + rb_sys_fail(0); + } + if (!(fp = fdopen(fd, "r"))){ + close(fd); + rb_sys_fail(0); + } + if (!(bio = BIO_new_fp(fp, BIO_CLOSE))){ + fclose(fp); + ossl_raise(eOSSLError, NULL); + } + } else { StringValue(obj); - bio = BIO_new_mem_buf(RSTRING(obj)->ptr, RSTRING(obj)->len); + bio = BIO_new_mem_buf(RSTRING_PTR(obj), RSTRING_LEN(obj)); + if (!bio) ossl_raise(eOSSLError, NULL); } - if (!bio) ossl_raise(eOSSLError, NULL); return bio; } |