Fix some issues in b_print.c code
[openssl.git] / crypto / bio / bio_meth.c
1 /*
2  * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
3  *
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
8  */
9
10 #include "bio_lcl.h"
11
12 BIO_METHOD *BIO_meth_new(int type, const char *name)
13 {
14     BIO_METHOD *biom = OPENSSL_zalloc(sizeof(BIO_METHOD));
15
16     if (biom != NULL) {
17         biom->type = type;
18         biom->name = name;
19     }
20     return biom;
21 }
22
23 void BIO_meth_free(BIO_METHOD *biom)
24 {
25     OPENSSL_free(biom);
26 }
27
28 int (*BIO_meth_get_write(BIO_METHOD *biom)) (BIO *, const char *, int)
29 {
30     return biom->bwrite;
31 }
32
33 int BIO_meth_set_write(BIO_METHOD *biom,
34                        int (*bwrite) (BIO *, const char *, int))
35 {
36     biom->bwrite = bwrite;
37     return 1;
38 }
39
40 int (*BIO_meth_get_read(BIO_METHOD *biom)) (BIO *, char *, int)
41 {
42     return biom->bread;
43 }
44
45 int BIO_meth_set_read(BIO_METHOD *biom,
46                       int (*bread) (BIO *, char *, int))
47 {
48     biom->bread = bread;
49     return 1;
50 }
51
52 int (*BIO_meth_get_puts(BIO_METHOD *biom)) (BIO *, const char *)
53 {
54     return biom->bputs;
55 }
56
57 int BIO_meth_set_puts(BIO_METHOD *biom,
58                       int (*bputs) (BIO *, const char *))
59 {
60     biom->bputs = bputs;
61     return 1;
62 }
63
64 int (*BIO_meth_get_gets(BIO_METHOD *biom)) (BIO *, char *, int)
65 {
66     return biom->bgets;
67 }
68
69 int BIO_meth_set_gets(BIO_METHOD *biom,
70                       int (*bgets) (BIO *, char *, int))
71 {
72     biom->bgets = bgets;
73     return 1;
74 }
75
76 long (*BIO_meth_get_ctrl(BIO_METHOD *biom)) (BIO *, int, long, void *)
77 {
78     return biom->ctrl;
79 }
80
81 int BIO_meth_set_ctrl(BIO_METHOD *biom,
82                       long (*ctrl) (BIO *, int, long, void *))
83 {
84     biom->ctrl = ctrl;
85     return 1;
86 }
87
88 int (*BIO_meth_get_create(BIO_METHOD *biom)) (BIO *)
89 {
90     return biom->create;
91 }
92
93 int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *))
94 {
95     biom->create = create;
96     return 1;
97 }
98
99 int (*BIO_meth_get_destroy(BIO_METHOD *biom)) (BIO *)
100 {
101     return biom->destroy;
102 }
103
104 int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *))
105 {
106     biom->destroy = destroy;
107     return 1;
108 }
109
110 long (*BIO_meth_get_callback_ctrl(BIO_METHOD *biom)) (BIO *, int, bio_info_cb *)
111 {
112     return biom->callback_ctrl;
113 }
114
115 int BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
116                                long (*callback_ctrl) (BIO *, int,
117                                                       bio_info_cb *))
118 {
119     biom->callback_ctrl = callback_ctrl;
120     return 1;
121 }