if_iwm - Recognize IWM_FW_PAGING_BLOCK_CMD wide cmd response correctly.
[dragonfly.git] / crypto / openssl / crypto / bio / bss_bio.c
blob4d8727f8f890cc512d625c86ee0256daa59bc9a0
1 /* crypto/bio/bss_bio.c */
2 /* ====================================================================
3 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
57 * Special method for a BIO where the other endpoint is also a BIO of this
58 * kind, handled by the same thread (i.e. the "peer" is actually ourselves,
59 * wearing a different hat). Such "BIO pairs" are mainly for using the SSL
60 * library with I/O interfaces for which no specific BIO method is available.
61 * See ssl/ssltest.c for some hints on how this can be used.
64 /* BIO_DEBUG implies BIO_PAIR_DEBUG */
65 #ifdef BIO_DEBUG
66 # ifndef BIO_PAIR_DEBUG
67 # define BIO_PAIR_DEBUG
68 # endif
69 #endif
71 /* disable assert() unless BIO_PAIR_DEBUG has been defined */
72 #ifndef BIO_PAIR_DEBUG
73 # ifndef NDEBUG
74 # define NDEBUG
75 # endif
76 #endif
78 #include <assert.h>
79 #include <limits.h>
80 #include <stdlib.h>
81 #include <string.h>
83 #include <openssl/bio.h>
84 #include <openssl/err.h>
85 #include <openssl/crypto.h>
87 #include "e_os.h"
89 /* VxWorks defines SSIZE_MAX with an empty value causing compile errors */
90 #if defined(OPENSSL_SYS_VXWORKS)
91 # undef SSIZE_MAX
92 #endif
93 #ifndef SSIZE_MAX
94 # define SSIZE_MAX INT_MAX
95 #endif
97 static int bio_new(BIO *bio);
98 static int bio_free(BIO *bio);
99 static int bio_read(BIO *bio, char *buf, int size);
100 static int bio_write(BIO *bio, const char *buf, int num);
101 static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr);
102 static int bio_puts(BIO *bio, const char *str);
104 static int bio_make_pair(BIO *bio1, BIO *bio2);
105 static void bio_destroy_pair(BIO *bio);
107 static BIO_METHOD methods_biop = {
108 BIO_TYPE_BIO,
109 "BIO pair",
110 bio_write,
111 bio_read,
112 bio_puts,
113 NULL /* no bio_gets */ ,
114 bio_ctrl,
115 bio_new,
116 bio_free,
117 NULL /* no bio_callback_ctrl */
120 BIO_METHOD *BIO_s_bio(void)
122 return &methods_biop;
125 struct bio_bio_st {
126 BIO *peer; /* NULL if buf == NULL. If peer != NULL, then
127 * peer->ptr is also a bio_bio_st, and its
128 * "peer" member points back to us. peer !=
129 * NULL iff init != 0 in the BIO. */
130 /* This is for what we write (i.e. reading uses peer's struct): */
131 int closed; /* valid iff peer != NULL */
132 size_t len; /* valid iff buf != NULL; 0 if peer == NULL */
133 size_t offset; /* valid iff buf != NULL; 0 if len == 0 */
134 size_t size;
135 char *buf; /* "size" elements (if != NULL) */
136 size_t request; /* valid iff peer != NULL; 0 if len != 0,
137 * otherwise set by peer to number of bytes
138 * it (unsuccessfully) tried to read, never
139 * more than buffer space (size-len)
140 * warrants. */
143 static int bio_new(BIO *bio)
145 struct bio_bio_st *b;
147 b = OPENSSL_malloc(sizeof *b);
148 if (b == NULL)
149 return 0;
151 b->peer = NULL;
152 /* enough for one TLS record (just a default) */
153 b->size = 17 * 1024;
154 b->buf = NULL;
156 bio->ptr = b;
157 return 1;
160 static int bio_free(BIO *bio)
162 struct bio_bio_st *b;
164 if (bio == NULL)
165 return 0;
166 b = bio->ptr;
168 assert(b != NULL);
170 if (b->peer)
171 bio_destroy_pair(bio);
173 if (b->buf != NULL) {
174 OPENSSL_free(b->buf);
177 OPENSSL_free(b);
179 return 1;
182 static int bio_read(BIO *bio, char *buf, int size_)
184 size_t size = size_;
185 size_t rest;
186 struct bio_bio_st *b, *peer_b;
188 BIO_clear_retry_flags(bio);
190 if (!bio->init)
191 return 0;
193 b = bio->ptr;
194 assert(b != NULL);
195 assert(b->peer != NULL);
196 peer_b = b->peer->ptr;
197 assert(peer_b != NULL);
198 assert(peer_b->buf != NULL);
200 peer_b->request = 0; /* will be set in "retry_read" situation */
202 if (buf == NULL || size == 0)
203 return 0;
205 if (peer_b->len == 0) {
206 if (peer_b->closed)
207 return 0; /* writer has closed, and no data is left */
208 else {
209 BIO_set_retry_read(bio); /* buffer is empty */
210 if (size <= peer_b->size)
211 peer_b->request = size;
212 else
214 * don't ask for more than the peer can deliver in one write
216 peer_b->request = peer_b->size;
217 return -1;
221 /* we can read */
222 if (peer_b->len < size)
223 size = peer_b->len;
225 /* now read "size" bytes */
227 rest = size;
229 assert(rest > 0);
230 do { /* one or two iterations */
231 size_t chunk;
233 assert(rest <= peer_b->len);
234 if (peer_b->offset + rest <= peer_b->size)
235 chunk = rest;
236 else
237 /* wrap around ring buffer */
238 chunk = peer_b->size - peer_b->offset;
239 assert(peer_b->offset + chunk <= peer_b->size);
241 memcpy(buf, peer_b->buf + peer_b->offset, chunk);
243 peer_b->len -= chunk;
244 if (peer_b->len) {
245 peer_b->offset += chunk;
246 assert(peer_b->offset <= peer_b->size);
247 if (peer_b->offset == peer_b->size)
248 peer_b->offset = 0;
249 buf += chunk;
250 } else {
251 /* buffer now empty, no need to advance "buf" */
252 assert(chunk == rest);
253 peer_b->offset = 0;
255 rest -= chunk;
257 while (rest);
259 return size;
263 * non-copying interface: provide pointer to available data in buffer
264 * bio_nread0: return number of available bytes
265 * bio_nread: also advance index
266 * (example usage: bio_nread0(), read from buffer, bio_nread()
267 * or just bio_nread(), read from buffer)
270 * WARNING: The non-copying interface is largely untested as of yet and may
271 * contain bugs.
273 static ossl_ssize_t bio_nread0(BIO *bio, char **buf)
275 struct bio_bio_st *b, *peer_b;
276 ossl_ssize_t num;
278 BIO_clear_retry_flags(bio);
280 if (!bio->init)
281 return 0;
283 b = bio->ptr;
284 assert(b != NULL);
285 assert(b->peer != NULL);
286 peer_b = b->peer->ptr;
287 assert(peer_b != NULL);
288 assert(peer_b->buf != NULL);
290 peer_b->request = 0;
292 if (peer_b->len == 0) {
293 char dummy;
295 /* avoid code duplication -- nothing available for reading */
296 return bio_read(bio, &dummy, 1); /* returns 0 or -1 */
299 num = peer_b->len;
300 if (peer_b->size < peer_b->offset + num)
301 /* no ring buffer wrap-around for non-copying interface */
302 num = peer_b->size - peer_b->offset;
303 assert(num > 0);
305 if (buf != NULL)
306 *buf = peer_b->buf + peer_b->offset;
307 return num;
310 static ossl_ssize_t bio_nread(BIO *bio, char **buf, size_t num_)
312 struct bio_bio_st *b, *peer_b;
313 ossl_ssize_t num, available;
315 if (num_ > SSIZE_MAX)
316 num = SSIZE_MAX;
317 else
318 num = (ossl_ssize_t) num_;
320 available = bio_nread0(bio, buf);
321 if (num > available)
322 num = available;
323 if (num <= 0)
324 return num;
326 b = bio->ptr;
327 peer_b = b->peer->ptr;
329 peer_b->len -= num;
330 if (peer_b->len) {
331 peer_b->offset += num;
332 assert(peer_b->offset <= peer_b->size);
333 if (peer_b->offset == peer_b->size)
334 peer_b->offset = 0;
335 } else
336 peer_b->offset = 0;
338 return num;
341 static int bio_write(BIO *bio, const char *buf, int num_)
343 size_t num = num_;
344 size_t rest;
345 struct bio_bio_st *b;
347 BIO_clear_retry_flags(bio);
349 if (!bio->init || buf == NULL || num == 0)
350 return 0;
352 b = bio->ptr;
353 assert(b != NULL);
354 assert(b->peer != NULL);
355 assert(b->buf != NULL);
357 b->request = 0;
358 if (b->closed) {
359 /* we already closed */
360 BIOerr(BIO_F_BIO_WRITE, BIO_R_BROKEN_PIPE);
361 return -1;
364 assert(b->len <= b->size);
366 if (b->len == b->size) {
367 BIO_set_retry_write(bio); /* buffer is full */
368 return -1;
371 /* we can write */
372 if (num > b->size - b->len)
373 num = b->size - b->len;
375 /* now write "num" bytes */
377 rest = num;
379 assert(rest > 0);
380 do { /* one or two iterations */
381 size_t write_offset;
382 size_t chunk;
384 assert(b->len + rest <= b->size);
386 write_offset = b->offset + b->len;
387 if (write_offset >= b->size)
388 write_offset -= b->size;
389 /* b->buf[write_offset] is the first byte we can write to. */
391 if (write_offset + rest <= b->size)
392 chunk = rest;
393 else
394 /* wrap around ring buffer */
395 chunk = b->size - write_offset;
397 memcpy(b->buf + write_offset, buf, chunk);
399 b->len += chunk;
401 assert(b->len <= b->size);
403 rest -= chunk;
404 buf += chunk;
406 while (rest);
408 return num;
412 * non-copying interface: provide pointer to region to write to
413 * bio_nwrite0: check how much space is available
414 * bio_nwrite: also increase length
415 * (example usage: bio_nwrite0(), write to buffer, bio_nwrite()
416 * or just bio_nwrite(), write to buffer)
418 static ossl_ssize_t bio_nwrite0(BIO *bio, char **buf)
420 struct bio_bio_st *b;
421 size_t num;
422 size_t write_offset;
424 BIO_clear_retry_flags(bio);
426 if (!bio->init)
427 return 0;
429 b = bio->ptr;
430 assert(b != NULL);
431 assert(b->peer != NULL);
432 assert(b->buf != NULL);
434 b->request = 0;
435 if (b->closed) {
436 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_BROKEN_PIPE);
437 return -1;
440 assert(b->len <= b->size);
442 if (b->len == b->size) {
443 BIO_set_retry_write(bio);
444 return -1;
447 num = b->size - b->len;
448 write_offset = b->offset + b->len;
449 if (write_offset >= b->size)
450 write_offset -= b->size;
451 if (write_offset + num > b->size)
453 * no ring buffer wrap-around for non-copying interface (to fulfil
454 * the promise by BIO_ctrl_get_write_guarantee, BIO_nwrite may have
455 * to be called twice)
457 num = b->size - write_offset;
459 if (buf != NULL)
460 *buf = b->buf + write_offset;
461 assert(write_offset + num <= b->size);
463 return num;
466 static ossl_ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_)
468 struct bio_bio_st *b;
469 ossl_ssize_t num, space;
471 if (num_ > SSIZE_MAX)
472 num = SSIZE_MAX;
473 else
474 num = (ossl_ssize_t) num_;
476 space = bio_nwrite0(bio, buf);
477 if (num > space)
478 num = space;
479 if (num <= 0)
480 return num;
481 b = bio->ptr;
482 assert(b != NULL);
483 b->len += num;
484 assert(b->len <= b->size);
486 return num;
489 static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
491 long ret;
492 struct bio_bio_st *b = bio->ptr;
494 assert(b != NULL);
496 switch (cmd) {
497 /* specific CTRL codes */
499 case BIO_C_SET_WRITE_BUF_SIZE:
500 if (b->peer) {
501 BIOerr(BIO_F_BIO_CTRL, BIO_R_IN_USE);
502 ret = 0;
503 } else if (num == 0) {
504 BIOerr(BIO_F_BIO_CTRL, BIO_R_INVALID_ARGUMENT);
505 ret = 0;
506 } else {
507 size_t new_size = num;
509 if (b->size != new_size) {
510 if (b->buf) {
511 OPENSSL_free(b->buf);
512 b->buf = NULL;
514 b->size = new_size;
516 ret = 1;
518 break;
520 case BIO_C_GET_WRITE_BUF_SIZE:
521 ret = (long)b->size;
522 break;
524 case BIO_C_MAKE_BIO_PAIR:
526 BIO *other_bio = ptr;
528 if (bio_make_pair(bio, other_bio))
529 ret = 1;
530 else
531 ret = 0;
533 break;
535 case BIO_C_DESTROY_BIO_PAIR:
537 * Affects both BIOs in the pair -- call just once! Or let
538 * BIO_free(bio1); BIO_free(bio2); do the job.
540 bio_destroy_pair(bio);
541 ret = 1;
542 break;
544 case BIO_C_GET_WRITE_GUARANTEE:
546 * How many bytes can the caller feed to the next write without
547 * having to keep any?
549 if (b->peer == NULL || b->closed)
550 ret = 0;
551 else
552 ret = (long)b->size - b->len;
553 break;
555 case BIO_C_GET_READ_REQUEST:
557 * If the peer unsuccessfully tried to read, how many bytes were
558 * requested? (As with BIO_CTRL_PENDING, that number can usually be
559 * treated as boolean.)
561 ret = (long)b->request;
562 break;
564 case BIO_C_RESET_READ_REQUEST:
566 * Reset request. (Can be useful after read attempts at the other
567 * side that are meant to be non-blocking, e.g. when probing SSL_read
568 * to see if any data is available.)
570 b->request = 0;
571 ret = 1;
572 break;
574 case BIO_C_SHUTDOWN_WR:
575 /* similar to shutdown(..., SHUT_WR) */
576 b->closed = 1;
577 ret = 1;
578 break;
580 case BIO_C_NREAD0:
581 /* prepare for non-copying read */
582 ret = (long)bio_nread0(bio, ptr);
583 break;
585 case BIO_C_NREAD:
586 /* non-copying read */
587 ret = (long)bio_nread(bio, ptr, (size_t)num);
588 break;
590 case BIO_C_NWRITE0:
591 /* prepare for non-copying write */
592 ret = (long)bio_nwrite0(bio, ptr);
593 break;
595 case BIO_C_NWRITE:
596 /* non-copying write */
597 ret = (long)bio_nwrite(bio, ptr, (size_t)num);
598 break;
600 /* standard CTRL codes follow */
602 case BIO_CTRL_RESET:
603 if (b->buf != NULL) {
604 b->len = 0;
605 b->offset = 0;
607 ret = 0;
608 break;
610 case BIO_CTRL_GET_CLOSE:
611 ret = bio->shutdown;
612 break;
614 case BIO_CTRL_SET_CLOSE:
615 bio->shutdown = (int)num;
616 ret = 1;
617 break;
619 case BIO_CTRL_PENDING:
620 if (b->peer != NULL) {
621 struct bio_bio_st *peer_b = b->peer->ptr;
623 ret = (long)peer_b->len;
624 } else
625 ret = 0;
626 break;
628 case BIO_CTRL_WPENDING:
629 if (b->buf != NULL)
630 ret = (long)b->len;
631 else
632 ret = 0;
633 break;
635 case BIO_CTRL_DUP:
636 /* See BIO_dup_chain for circumstances we have to expect. */
638 BIO *other_bio = ptr;
639 struct bio_bio_st *other_b;
641 assert(other_bio != NULL);
642 other_b = other_bio->ptr;
643 assert(other_b != NULL);
645 assert(other_b->buf == NULL); /* other_bio is always fresh */
647 other_b->size = b->size;
650 ret = 1;
651 break;
653 case BIO_CTRL_FLUSH:
654 ret = 1;
655 break;
657 case BIO_CTRL_EOF:
659 BIO *other_bio = ptr;
661 if (other_bio) {
662 struct bio_bio_st *other_b = other_bio->ptr;
664 assert(other_b != NULL);
665 ret = other_b->len == 0 && other_b->closed;
666 } else
667 ret = 1;
669 break;
671 default:
672 ret = 0;
674 return ret;
677 static int bio_puts(BIO *bio, const char *str)
679 return bio_write(bio, str, strlen(str));
682 static int bio_make_pair(BIO *bio1, BIO *bio2)
684 struct bio_bio_st *b1, *b2;
686 assert(bio1 != NULL);
687 assert(bio2 != NULL);
689 b1 = bio1->ptr;
690 b2 = bio2->ptr;
692 if (b1->peer != NULL || b2->peer != NULL) {
693 BIOerr(BIO_F_BIO_MAKE_PAIR, BIO_R_IN_USE);
694 return 0;
697 if (b1->buf == NULL) {
698 b1->buf = OPENSSL_malloc(b1->size);
699 if (b1->buf == NULL) {
700 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
701 return 0;
703 b1->len = 0;
704 b1->offset = 0;
707 if (b2->buf == NULL) {
708 b2->buf = OPENSSL_malloc(b2->size);
709 if (b2->buf == NULL) {
710 BIOerr(BIO_F_BIO_MAKE_PAIR, ERR_R_MALLOC_FAILURE);
711 return 0;
713 b2->len = 0;
714 b2->offset = 0;
717 b1->peer = bio2;
718 b1->closed = 0;
719 b1->request = 0;
720 b2->peer = bio1;
721 b2->closed = 0;
722 b2->request = 0;
724 bio1->init = 1;
725 bio2->init = 1;
727 return 1;
730 static void bio_destroy_pair(BIO *bio)
732 struct bio_bio_st *b = bio->ptr;
734 if (b != NULL) {
735 BIO *peer_bio = b->peer;
737 if (peer_bio != NULL) {
738 struct bio_bio_st *peer_b = peer_bio->ptr;
740 assert(peer_b != NULL);
741 assert(peer_b->peer == bio);
743 peer_b->peer = NULL;
744 peer_bio->init = 0;
745 assert(peer_b->buf != NULL);
746 peer_b->len = 0;
747 peer_b->offset = 0;
749 b->peer = NULL;
750 bio->init = 0;
751 assert(b->buf != NULL);
752 b->len = 0;
753 b->offset = 0;
758 /* Exported convenience functions */
759 int BIO_new_bio_pair(BIO **bio1_p, size_t writebuf1,
760 BIO **bio2_p, size_t writebuf2)
762 BIO *bio1 = NULL, *bio2 = NULL;
763 long r;
764 int ret = 0;
766 bio1 = BIO_new(BIO_s_bio());
767 if (bio1 == NULL)
768 goto err;
769 bio2 = BIO_new(BIO_s_bio());
770 if (bio2 == NULL)
771 goto err;
773 if (writebuf1) {
774 r = BIO_set_write_buf_size(bio1, writebuf1);
775 if (!r)
776 goto err;
778 if (writebuf2) {
779 r = BIO_set_write_buf_size(bio2, writebuf2);
780 if (!r)
781 goto err;
784 r = BIO_make_bio_pair(bio1, bio2);
785 if (!r)
786 goto err;
787 ret = 1;
789 err:
790 if (ret == 0) {
791 if (bio1) {
792 BIO_free(bio1);
793 bio1 = NULL;
795 if (bio2) {
796 BIO_free(bio2);
797 bio2 = NULL;
801 *bio1_p = bio1;
802 *bio2_p = bio2;
803 return ret;
806 size_t BIO_ctrl_get_write_guarantee(BIO *bio)
808 return BIO_ctrl(bio, BIO_C_GET_WRITE_GUARANTEE, 0, NULL);
811 size_t BIO_ctrl_get_read_request(BIO *bio)
813 return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
816 int BIO_ctrl_reset_read_request(BIO *bio)
818 return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0);
822 * BIO_nread0/nread/nwrite0/nwrite are available only for BIO pairs for now
823 * (conceivably some other BIOs could allow non-copying reads and writes
824 * too.)
826 int BIO_nread0(BIO *bio, char **buf)
828 long ret;
830 if (!bio->init) {
831 BIOerr(BIO_F_BIO_NREAD0, BIO_R_UNINITIALIZED);
832 return -2;
835 ret = BIO_ctrl(bio, BIO_C_NREAD0, 0, buf);
836 if (ret > INT_MAX)
837 return INT_MAX;
838 else
839 return (int)ret;
842 int BIO_nread(BIO *bio, char **buf, int num)
844 int ret;
846 if (!bio->init) {
847 BIOerr(BIO_F_BIO_NREAD, BIO_R_UNINITIALIZED);
848 return -2;
851 ret = (int)BIO_ctrl(bio, BIO_C_NREAD, num, buf);
852 if (ret > 0)
853 bio->num_read += ret;
854 return ret;
857 int BIO_nwrite0(BIO *bio, char **buf)
859 long ret;
861 if (!bio->init) {
862 BIOerr(BIO_F_BIO_NWRITE0, BIO_R_UNINITIALIZED);
863 return -2;
866 ret = BIO_ctrl(bio, BIO_C_NWRITE0, 0, buf);
867 if (ret > INT_MAX)
868 return INT_MAX;
869 else
870 return (int)ret;
873 int BIO_nwrite(BIO *bio, char **buf, int num)
875 int ret;
877 if (!bio->init) {
878 BIOerr(BIO_F_BIO_NWRITE, BIO_R_UNINITIALIZED);
879 return -2;
882 ret = BIO_ctrl(bio, BIO_C_NWRITE, num, buf);
883 if (ret > 0)
884 bio->num_write += ret;
885 return ret;