Work around Travis "virtual memory exhausted" error
[openssl.git] / crypto / bio / bss_null.c
1 /*
2  * Copyright 1995-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 <stdio.h>
11 #include <errno.h>
12 #include "bio_lcl.h"
13 #include "internal/cryptlib.h"
14
15 static int null_write(BIO *h, const char *buf, int num);
16 static int null_read(BIO *h, char *buf, int size);
17 static int null_puts(BIO *h, const char *str);
18 static int null_gets(BIO *h, char *str, int size);
19 static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2);
20 static int null_new(BIO *h);
21 static int null_free(BIO *data);
22 static const BIO_METHOD null_method = {
23     BIO_TYPE_NULL,
24     "NULL",
25     /* TODO: Convert to new style write function */
26     bwrite_conv,
27     null_write,
28     /* TODO: Convert to new style read function */
29     bread_conv,
30     null_read,
31     null_puts,
32     null_gets,
33     null_ctrl,
34     null_new,
35     null_free,
36     NULL,
37 };
38
39 const BIO_METHOD *BIO_s_null(void)
40 {
41     return (&null_method);
42 }
43
44 static int null_new(BIO *bi)
45 {
46     bi->init = 1;
47     bi->num = 0;
48     bi->ptr = (NULL);
49     return (1);
50 }
51
52 static int null_free(BIO *a)
53 {
54     if (a == NULL)
55         return (0);
56     return (1);
57 }
58
59 static int null_read(BIO *b, char *out, int outl)
60 {
61     return (0);
62 }
63
64 static int null_write(BIO *b, const char *in, int inl)
65 {
66     return (inl);
67 }
68
69 static long null_ctrl(BIO *b, int cmd, long num, void *ptr)
70 {
71     long ret = 1;
72
73     switch (cmd) {
74     case BIO_CTRL_RESET:
75     case BIO_CTRL_EOF:
76     case BIO_CTRL_SET:
77     case BIO_CTRL_SET_CLOSE:
78     case BIO_CTRL_FLUSH:
79     case BIO_CTRL_DUP:
80         ret = 1;
81         break;
82     case BIO_CTRL_GET_CLOSE:
83     case BIO_CTRL_INFO:
84     case BIO_CTRL_GET:
85     case BIO_CTRL_PENDING:
86     case BIO_CTRL_WPENDING:
87     default:
88         ret = 0;
89         break;
90     }
91     return (ret);
92 }
93
94 static int null_gets(BIO *bp, char *buf, int size)
95 {
96     return (0);
97 }
98
99 static int null_puts(BIO *bp, const char *str)
100 {
101     if (str == NULL)
102         return (0);
103     return (strlen(str));
104 }