I found the following code from bstrlib, in bstrlib.c
(e.g. line 193) :
bstring bfromcstr (const char * str) {
bstring b;
int i;
size_t j;
if (str == NULL) return NULL;
j = (strlen) (str);
i = snapUpSize ((int) (j + (2 - (j != 0))));
if (i <= (int) j) return NULL;
b = (bstring) bstr__alloc (sizeof (struct tagbstring));
if (NULL == b) return NULL;
b->slen = (int) j;
if (NULL == (b->data = (unsigned char *) bstr__alloc (b->mlen = i))) {
bstr__free (b);
return NULL;
}
bstr__memcpy (b->data, str, j+1);
return b;
}
What does the line (strlen) (str)
mean? This kind of code using strlen
is quite common in the bstrlib.c
.
I did some test code on a OSX machine, but I can't either understand nor explain what it means.