BIO_clear_retry_flags(b);
blen=bm->length;
- if (BUF_MEM_grow(bm,blen+inl) != (blen+inl))
+ if (BUF_MEM_grow_clean(bm,blen+inl) != (blen+inl))
goto end;
memcpy(&(bm->data[blen]),in,inl);
ret=inl;
BIO_clear_retry_flags(bp);
j=bm->length;
- if (j <= 0) return(0);
- p=bm->data;
- for (i=0; i<j; i++)
+ if ((size-1) < j) j=size-1;
+ if (j <= 0)
{
- if (p[i] == '\n') break;
+ *buf='\0';
+ return 0;
}
- if (i == j)
+ p=bm->data;
+ for (i=0; i<j; i++)
{
- BIO_set_retry_read(bp);
- /* return(-1); change the semantics 0.6.6a */
+ if (p[i] == '\n')
+ {
+ i++;
+ break;
+ }
}
- else
- i++;
- /* i is the max to copy */
- if ((size-1) < i) i=size-1;
+
+ /*
+ * i is now the max num of bytes to copy, either j or up to
+ * and including the first newline
+ */
+
i=mem_read(bp,buf,i);
if (i > 0) buf[i]='\0';
ret=i;