static int bio_write_intern(BIO *b, const void *data, size_t dlen,
size_t *written)
{
+ size_t local_written;
int ret;
+ if (written != NULL)
+ *written = 0;
/*
* b == NULL is not an error but just means that zero bytes are written.
* Do not raise an error here.
return -1;
}
- ret = b->method->bwrite(b, data, dlen, written);
+ ret = b->method->bwrite(b, data, dlen, &local_written);
if (ret > 0)
- b->num_write += (uint64_t)*written;
+ b->num_write += (uint64_t)local_written;
if (HAS_CALLBACK(b))
ret = (int)bio_call_callback(b, BIO_CB_WRITE | BIO_CB_RETURN, data,
- dlen, 0, 0L, ret, written);
+ dlen, 0, 0L, ret, &local_written);
+ if (written != NULL)
+ *written = local_written;
return ret;
}
size_t written;
int ret;
- if (dlen < 0)
+ if (dlen <= 0)
return 0;
ret = bio_write_intern(b, data, (size_t)dlen, &written);
if (ret > 0) {
- /* *written should always be <= dlen */
+ /* written should always be <= dlen */
ret = (int)written;
}
int BIO_write_ex(BIO *b, const void *data, size_t dlen, size_t *written)
{
- return bio_write_intern(b, data, dlen, written) > 0;
+ return bio_write_intern(b, data, dlen, written) >= 0;
}
int BIO_puts(BIO *b, const char *buf)
in I<data>. If any bytes were successfully read then the number of bytes read is
stored in I<*readbytes>.
-BIO_write_ex() attempts to write I<dlen> bytes from I<data> to BIO I<b>. If
-successful then the number of bytes written is stored in I<*written>.
+BIO_write_ex() attempts to write I<dlen> bytes from I<data> to BIO I<b>.
+If successful then the number of bytes written is stored in I<*written>
+unless I<written> is NULL. No data is written if I<b> is NULL.
BIO_read() attempts to read I<len> bytes from BIO I<b> and places
the data in I<buf>.
=head1 RETURN VALUES
-BIO_read_ex() and BIO_write_ex() return 1 if data was successfully read or
-written, and 0 otherwise.
+BIO_read_ex() returns 1 if data was successfully read, and 0 otherwise.
-BIO_write() and BIO_write_ex() return 0 if the BIO I<b> is NULL.
+BIO_write_ex() returns 1 if no error was encountered writing data, 0 otherwise.
+Write to NULL B<BIO> is not considered as an error.
+
+BIO_write() returns -2 if the "write" operation is not implemented by the BIO
+or -1 on other errors.
+Otherwise it returns the number of bytes written.
+This may be 0 if the BIO I<b> is NULL or I<dlen <= 0>.
BIO_gets() returns -2 if the "gets" operation is not implemented by the BIO
or -1 on other errors.