My C++ knowledge stinks and I need to convert a C++ function the correct way.
This is the code I have (extracted from http://www.sky.franken.de/doxy/xmlstorage/c++/base64_8cpp_source.html).
void* base64_decode(const char* s, size_t& data_len)
{
size_t len = strlen(s);
if (len % 4)
throw Exception("invalid BASE64 string length");
unsigned char* data = (unsigned char*) malloc(len/4*3);
int n[4];
unsigned char* q = (unsigned char*) data;
for(const char*p=s; *p; ) {
n[0] = POS(*p++);
n[1] = POS(*p++);
n[2] = POS(*p++);
n[3] = POS(*p++);
if (n[0]==-1 || n[1]==-1)
throw Exception("invalid BASE64 encoding");
if (n[2]==-1 && n[3]!=-1)
throw Exception("invalid BASE64 encoding");
q[0] = (n[0] << 2) + (n[1] >> 4);
if (n[2] != -1) q[1] = ((n[1] & 15) << 4) + (n[2] >> 2);
if (n[3] != -1) q[2] = ((n[2] & 3) << 6) + n[3];
q += 3;
}
data_len = q-data - (n[2]==-1) - (n[3]==-1);
return data;
}
I need this previous function to have this header
void * base64_decode(const char* s, size_t * data_len)
so, you see that is a matter of a “&” and a “*” on the header. As you see, the first function has this
size_t& data_len
in the header, but I need it to accept the data length in the form
size_t * data_len
I don’t know how to convert the first in the second, or in other words, what kind of changes I will have to perform on the method to make it work with a data_len provided as “size_t *”
Calling the function would look like this: