Commit 7028259a authored by Michael Niedermayer's avatar Michael Niedermayer

simplify b64_encode()

maybe this should be moved to libavutil ...

Originally committed as revision 5782 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 4b45de0e
...@@ -285,6 +285,7 @@ URLProtocol http_protocol = { ...@@ -285,6 +285,7 @@ URLProtocol http_protocol = {
/***************************************************************************** /*****************************************************************************
* b64_encode: stolen from VLC's http.c * b64_encode: stolen from VLC's http.c
* simplified by michael
*****************************************************************************/ *****************************************************************************/
static char *b64_encode( const unsigned char *src ) static char *b64_encode( const unsigned char *src )
...@@ -300,32 +301,17 @@ static char *b64_encode( const unsigned char *src ) ...@@ -300,32 +301,17 @@ static char *b64_encode( const unsigned char *src )
}else }else
return NULL; return NULL;
for( ;; ) while(*src){
{ i_bits = (i_bits << 8) + *src++;
if( *src ) i_shift += 8;
{
i_bits = ( i_bits << 8 )|( *src++ );
i_shift += 8;
}
else if( i_shift > 0 )
{
i_bits <<= 6 - i_shift;
i_shift = 6;
}
else
{
*dst++ = '=';
break;
}
while( i_shift >= 6 ) do{
{ *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f];
i_shift -= 6; i_shift -= 6;
*dst++ = b64[(i_bits >> i_shift)&0x3f]; }while( i_shift > 6 || (*src == 0 && i_shift>0));
}
} }
*dst++ = '=';
*dst++ = '\0'; *dst = '\0';
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment