Update dependencies.
[openssl.git] / crypto / bio / bss_mem.c
index 40c4e39f025ef1afa056e63136b13d716dff2338..7e749a503ef370913b87c8675a062374470d5ad2 100644 (file)
@@ -59,9 +59,8 @@
 #include <stdio.h>
 #include <errno.h>
 #include "cryptlib.h"
-#include "bio.h"
+#include <openssl/bio.h>
 
-#ifndef NOPROTO
 static int mem_write(BIO *h,char *buf,int num);
 static int mem_read(BIO *h,char *buf,int size);
 static int mem_puts(BIO *h,char *str);
@@ -69,16 +68,6 @@ static int mem_gets(BIO *h,char *str,int size);
 static long mem_ctrl(BIO *h,int cmd,long arg1,char *arg2);
 static int mem_new(BIO *h);
 static int mem_free(BIO *data);
-#else
-static int mem_write();
-static int mem_read();
-static int mem_puts();
-static int mem_gets();
-static long mem_ctrl();
-static int mem_new();
-static int mem_free();
-#endif
-
 static BIO_METHOD mem_method=
        {
        BIO_TYPE_MEM,
@@ -92,13 +81,15 @@ static BIO_METHOD mem_method=
        mem_free,
        };
 
-BIO_METHOD *BIO_s_mem()
+/* bio->num is used to hold the value to return on 'empty', if it is
+ * 0, should_retry is not set */
+
+BIO_METHOD *BIO_s_mem(void)
        {
        return(&mem_method);
        }
 
-static int mem_new(bi)
-BIO *bi;
+static int mem_new(BIO *bi)
        {
        BUF_MEM *b;
 
@@ -106,13 +97,12 @@ BIO *bi;
                return(0);
        bi->shutdown=1;
        bi->init=1;
-       bi->num=0;
+       bi->num= -1;
        bi->ptr=(char *)b;
        return(1);
        }
 
-static int mem_free(a)
-BIO *a;
+static int mem_free(BIO *a)
        {
        if (a == NULL) return(0);
        if (a->shutdown)
@@ -126,10 +116,7 @@ BIO *a;
        return(1);
        }
        
-static int mem_read(b,out,outl)
-BIO *b;
-char *out;
-int outl;
+static int mem_read(BIO *b, char *out, int outl)
        {
        int ret= -1;
        BUF_MEM *bm;
@@ -151,16 +138,14 @@ int outl;
                }
        else if (bm->length == 0)
                {
-               BIO_set_retry_read(b);
-               ret= -1;
+               if (b->num != 0)
+                       BIO_set_retry_read(b);
+               ret= b->num;
                }
        return(ret);
        }
 
-static int mem_write(b,in,inl)
-BIO *b;
-char *in;
-int inl;
+static int mem_write(BIO *b, char *in, int inl)
        {
        int ret= -1;
        int blen;
@@ -183,11 +168,7 @@ end:
        return(ret);
        }
 
-static long mem_ctrl(b,cmd,num,ptr)
-BIO *b;
-int cmd;
-long num;
-char *ptr;
+static long mem_ctrl(BIO *b, int cmd, long num, char *ptr)
        {
        long ret=1;
        char **pptr;
@@ -204,6 +185,9 @@ char *ptr;
        case BIO_CTRL_EOF:
                ret=(long)(bm->length == 0);
                break;
+       case BIO_C_SET_BUF_MEM_EOF_RETURN:
+               b->num=(int)num;
+               break;
        case BIO_CTRL_INFO:
                ret=(long)bm->length;
                if (ptr != NULL)
@@ -250,10 +234,7 @@ char *ptr;
        return(ret);
        }
 
-static int mem_gets(bp,buf,size)
-BIO *bp;
-char *buf;
-int size;
+static int mem_gets(BIO *bp, char *buf, int size)
        {
        int i,j;
        int ret= -1;
@@ -283,9 +264,7 @@ int size;
        return(ret);
        }
 
-static int mem_puts(bp,str)
-BIO *bp;
-char *str;
+static int mem_puts(BIO *bp, char *str)
        {
        int n,ret;