#include
#include
#define ENCODE_OUTPUT_SIZE(len) \
(len*4)
#define ENCODE_EXTRA_SIZE(len) \
(((len/3 + 1)*4 + 4)/72 + 1)
#define INPUT_SIZE 32
int main(int argc,char** argv){
FILE* fp = NULL;
FILE* output_file = NULL;
guint i = 0;
guchar in_buffer[INPUT_SIZE];
guchar out_buffer[ENCODE_OUTPUT_SIZE(INPUT_SIZE) + ENCODE_EXTRA_SIZE(INPUT_SIZE)];
gint state,save;
gsize out_len = 0,len = 0;
output_file = fopen("./008_encode.txt","wb");
if(output_file == NULL){
g_print("open 008_encode.txt error!\n");
return -1;
}
fp = fopen("./008.app","rb");
if(fp == NULL) return -1;
while((len = fread(in_buffer,1,INPUT_SIZE,fp)) == INPUT_SIZE){
out_len = g_base64_encode_step(in_buffer,
INPUT_SIZE,
FALSE,
out_buffer,
&state,
&save);
fwrite(out_buffer,1,out_len,output_file);
}
if(len > 0){
out_len = g_base64_encode_step(in_buffer,
len,
FALSE,
out_buffer,
&state,
&save);
fwrite(out_buffer,1,out_len,output_file);
}
out_len = g_base64_encode_close(FALSE,out_buffer,&state,&save);
fwrite(out_buffer,1,out_len,output_file);
fclose(output_file);
fclose(fp);
return 0;
}
阅读(1864) | 评论(0) | 转发(0) |