2 * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include <internal/thread_once.h>
13 CRYPTO_RWLOCK *bio_type_lock = NULL;
14 static CRYPTO_ONCE bio_type_init = CRYPTO_ONCE_STATIC_INIT;
16 DEFINE_RUN_ONCE_STATIC(do_bio_type_init)
18 bio_type_lock = CRYPTO_THREAD_lock_new();
19 return bio_type_lock != NULL;
22 int BIO_get_new_index()
24 static int bio_count = BIO_TYPE_START;
27 if (!RUN_ONCE(&bio_type_init, do_bio_type_init)) {
28 BIOerr(BIO_F_BIO_GET_NEW_INDEX, ERR_R_MALLOC_FAILURE);
31 if (!CRYPTO_atomic_add(&bio_count, 1, &newval, bio_type_lock))
36 BIO_METHOD *BIO_meth_new(int type, const char *name)
38 BIO_METHOD *biom = OPENSSL_zalloc(sizeof(BIO_METHOD));
41 || (biom->name = OPENSSL_strdup(name)) == NULL) {
43 BIOerr(BIO_F_BIO_METH_NEW, ERR_R_MALLOC_FAILURE);
49 void BIO_meth_free(BIO_METHOD *biom)
52 OPENSSL_free(biom->name);
57 int (*BIO_meth_get_write(BIO_METHOD *biom)) (BIO *, const char *, int)
62 int BIO_meth_set_write(BIO_METHOD *biom,
63 int (*bwrite) (BIO *, const char *, int))
65 biom->bwrite = bwrite;
69 int (*BIO_meth_get_read(BIO_METHOD *biom)) (BIO *, char *, int)
74 int BIO_meth_set_read(BIO_METHOD *biom,
75 int (*bread) (BIO *, char *, int))
81 int (*BIO_meth_get_puts(BIO_METHOD *biom)) (BIO *, const char *)
86 int BIO_meth_set_puts(BIO_METHOD *biom,
87 int (*bputs) (BIO *, const char *))
93 int (*BIO_meth_get_gets(BIO_METHOD *biom)) (BIO *, char *, int)
98 int BIO_meth_set_gets(BIO_METHOD *biom,
99 int (*bgets) (BIO *, char *, int))
105 long (*BIO_meth_get_ctrl(BIO_METHOD *biom)) (BIO *, int, long, void *)
110 int BIO_meth_set_ctrl(BIO_METHOD *biom,
111 long (*ctrl) (BIO *, int, long, void *))
117 int (*BIO_meth_get_create(BIO_METHOD *biom)) (BIO *)
122 int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *))
124 biom->create = create;
128 int (*BIO_meth_get_destroy(BIO_METHOD *biom)) (BIO *)
130 return biom->destroy;
133 int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *))
135 biom->destroy = destroy;
139 long (*BIO_meth_get_callback_ctrl(BIO_METHOD *biom)) (BIO *, int, BIO_info_cb *)
141 return biom->callback_ctrl;
144 int BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
145 long (*callback_ctrl) (BIO *, int,
148 biom->callback_ctrl = callback_ctrl;