Add BIO_tell and BIO_seek wrappers.

Change-Id: Ia5db220d13cf42fac6958a2c7416743ca2991479
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/50745
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
diff --git a/crypto/bio/file.c b/crypto/bio/file.c
index 835d661..66278e5 100644
--- a/crypto/bio/file.c
+++ b/crypto/bio/file.c
@@ -308,4 +308,10 @@
                   BIO_CLOSE | BIO_FP_READ | BIO_FP_WRITE, (char *)filename);
 }
 
+long BIO_tell(BIO *bio) { return BIO_ctrl(bio, BIO_C_FILE_TELL, 0, NULL); }
+
+long BIO_seek(BIO *bio, long offset) {
+  return BIO_ctrl(bio, BIO_C_FILE_SEEK, offset, NULL);
+}
+
 #endif  // OPENSSL_TRUSTY
diff --git a/include/openssl/bio.h b/include/openssl/bio.h
index 18bc893..1658ff2 100644
--- a/include/openssl/bio.h
+++ b/include/openssl/bio.h
@@ -508,6 +508,25 @@
 // |FILE| will be closed when |bio| is freed.
 OPENSSL_EXPORT int BIO_rw_filename(BIO *bio, const char *filename);
 
+// BIO_tell returns the file offset of |bio|, or a negative number on error or
+// if |bio| does not support the operation.
+//
+// TODO(https://crbug.com/boringssl/465): On platforms where |long| is 32-bit,
+// this function cannot report 64-bit offsets.
+OPENSSL_EXPORT long BIO_tell(BIO *bio);
+
+// BIO_seek sets the file offset of |bio| to |offset|. It returns a non-negative
+// number on success and a negative number on error. If |bio| is a file
+// descriptor |BIO|, it returns the resulting file offset on success. If |bio|
+// is a file |BIO|, it returns zero on success.
+//
+// WARNING: This function's return value conventions differs from most functions
+// in this library.
+//
+// TODO(https://crbug.com/boringssl/465): On platforms where |long| is 32-bit,
+// this function cannot handle 64-bit offsets.
+OPENSSL_EXPORT long BIO_seek(BIO *bio, long offset);
+
 
 // Socket BIOs.
 //