31 cout <<
"b64codec: A base 64 encoder/decoder based on MCS" << endl;
32 cout <<
"Giorgio Calderone <gcalderone@ifc.inaf.it>" << endl;
34 cout <<
"Usage: b64codec [-e|-d] [FILEIN [FILEOUT]]" << endl;
35 cout <<
"Options:" << endl;
36 cout <<
" -e, --encode Encode data (default)" << endl;
37 cout <<
" -d, --decode Decode data" << endl;
38 cout <<
" -h, --help Shows this help" << endl;
40 cout <<
"If no file name is given stdin and stdout will be used." << endl;
41 cout <<
"If one file name is given it will be used for input and stdout for output." << endl;
42 cout <<
"If two file names are given they will be used respectively for input and output." << endl;
43 cout <<
"If FILEIN is - stdin will be used for input." << endl;
50 int main(
int argc,
char* argv[])
59 for (ret=1; ret<(
unsigned int) argc; ret++) {
60 if ((strcmp(argv[ret],
"-e") == 0) ||
61 (strcmp(argv[ret],
"--encode") == 0) )
64 else if ((strcmp(argv[ret],
"-d") == 0) ||
65 (strcmp(argv[ret],
"--decode") == 0) )
68 else if ((strcmp(argv[ret],
"-h") == 0) ||
69 (strcmp(argv[ret],
"--help") == 0) ) {
98 fdin = open(fin.c_str(), O_RDONLY);
100 cerr <<
"Can't open file " << fin <<
" for input." << endl;
110 fdout = open(fout.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0);
112 cerr <<
"Can't open file " << fout <<
" for output." << endl;
113 cerr << strerror(errno) << endl;
116 fchmod(fdout, S_IREAD | S_IWRITE | S_IRGRP | S_IROTH);
123 while ((ret = read(fdin, buf, BUFSIZE)) > 0) {
125 ret = b64.
encode(buf, ret);
127 ret = b64.
decode(buf, ret);
129 ret = write(fdout, b64.buffer(), b64.bufUsed());
131 if (ret != b64.bufUsed()) {
132 cerr <<
"Can't write on output file." << endl;
140 ret = write(fdout, b64.buffer(), b64.bufUsed());
unsigned int decode(char *buf_in, int Length, char *par_buf_out=NULL)
Decode a block of data.
unsigned int encode(char *buf_in, int Length, char *par_buf_out=NULL, unsigned int linesize=72)
Encode a block of data.
A Base 64 encoder/decoder.
Main include file for all MCS based applications.
Namespace for MCS library.