The deserialization library (messagepack) I am using does not provide null-terminated strings. Instead, I get a pointer to the beginning of the string and a length. What is the
int compare(char *one, size_t onelen, char *two, size_t twolen)
{
int dif;
dif = memcmp(one, two, onelen < twolen ? onelen : twolen);
if (dif) return dif;
if (onelen == twolen) return 0;
return onelen > twolen? 1 : -1;
}
usage:
...
int result;
char einz[4] = "einz"; // not terminated
char *zwei = "einz"; // terminated
result = compare(einz, sizeof einz, zwei, strlen(zwei));
...