Align BIO_get_fd with upstream.

OpenSSL's BIO_get_fd returns the fd or -1, not a boolean.

Change-Id: I12a3429c71bb9c9064f9f91329a88923025f1fb5
Reviewed-on: https://boringssl-review.googlesource.com/6080
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/bio/connect.c b/crypto/bio/connect.c
index 2ed2def..cc28ef8 100644
--- a/crypto/bio/connect.c
+++ b/crypto/bio/connect.c
@@ -445,9 +445,9 @@
         if (ip != NULL) {
           *ip = bio->num;
         }
-        ret = 1;
+        ret = bio->num;
       } else {
-        ret = 0;
+        ret = -1;
       }
       break;
     case BIO_CTRL_GET_CLOSE:
diff --git a/crypto/bio/fd.c b/crypto/bio/fd.c
index 0b5baca..0b3484c 100644
--- a/crypto/bio/fd.c
+++ b/crypto/bio/fd.c
@@ -208,9 +208,9 @@
         if (ip != NULL) {
           *ip = b->num;
         }
-        return 1;
+        return b->num;
       } else {
-        ret = 0;
+        ret = -1;
       }
       break;
     case BIO_CTRL_GET_CLOSE:
diff --git a/include/openssl/bio.h b/include/openssl/bio.h
index 04e3790..481b97e 100644
--- a/include/openssl/bio.h
+++ b/include/openssl/bio.h
@@ -444,8 +444,9 @@
  * or zero on error. */
 OPENSSL_EXPORT int BIO_set_fd(BIO *bio, int fd, int close_flag);
 
-/* BIO_get_fd sets |*out_fd| to the file descriptor currently in use by |bio|.
- * It returns one on success and zero on error. */
+/* BIO_get_fd returns the file descriptor currently in use by |bio| or -1 if
+ * |bio| does not wrap a file descriptor. If there is a file descriptor and
+ * |out_fd| is not NULL, it also sets |*out_fd| to the file descriptor. */
 OPENSSL_EXPORT int BIO_get_fd(BIO *bio, int *out_fd);
 
 
diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c
index 25d65c1..66867ba 100644
--- a/ssl/ssl_lib.c
+++ b/ssl/ssl_lib.c
@@ -1121,7 +1121,7 @@
   BIO *bio = NULL;
 
   if (s->rbio == NULL || BIO_method_type(s->rbio) != BIO_TYPE_FD ||
-      (int)BIO_get_fd(s->rbio, NULL) != fd) {
+      BIO_get_fd(s->rbio, NULL) != fd) {
     bio = BIO_new(BIO_s_fd());
 
     if (bio == NULL) {
@@ -1145,7 +1145,7 @@
   BIO *bio = NULL;
 
   if (s->wbio == NULL || BIO_method_type(s->wbio) != BIO_TYPE_FD ||
-      (int)BIO_get_fd(s->wbio, NULL) != fd) {
+      BIO_get_fd(s->wbio, NULL) != fd) {
     bio = BIO_new(BIO_s_fd());
 
     if (bio == NULL) {