if (buf) OPENSSL_free(buf);
int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,	     long len)	{	int nlen,n,i,j,outl;	unsigned char *buf;	EVP_ENCODE_CTX ctx;	int reason=ERR_R_BUF_LIB;		EVP_EncodeInit(&ctx);	nlen=strlen(name);	if (	(BIO_write(bp,"-----BEGIN ",11) != 11) ||		(BIO_write(bp,name,nlen) != nlen) ||		(BIO_write(bp,"-----\n",6) != 6))		goto err;			i=strlen(header);	if (i > 0)		{		if (	(BIO_write(bp,header,i) != i) ||			(BIO_write(bp,"\n",1) != 1))			goto err;		}	buf=(unsigned char *)OPENSSL_malloc(PEM_BUFSIZE*8);	if (buf == NULL)		{		reason=ERR_R_MALLOC_FAILURE;		goto err;		}	i=j=0;	while (len > 0)		{		n=(int)((len>(PEM_BUFSIZE*5))?(PEM_BUFSIZE*5):len);		EVP_EncodeUpdate(&ctx,buf,&outl,&(data[j]),n);		if ((outl) && (BIO_write(bp,(char *)buf,outl) != outl))			goto err;		i+=outl;		len-=n;		j+=n;		}	EVP_EncodeFinal(&ctx,buf,&outl);	if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err;	OPENSSL_free(buf);	if (	(BIO_write(bp,"-----END ",9) != 9) ||		(BIO_write(bp,name,nlen) != nlen) ||		(BIO_write(bp,"-----\n",6) != 6))		goto err;	return(i+outl);err:	PEMerr(PEM_F_PEM_WRITE_BIO,reason);	return(0);	}