I'm building a cross platform OS X version of the latest dcraw.c I'm doing this on OS X 10.6.8 to have the PPC compatibility. Now my problem is that strnlen seems to get used in the latest version of the program and it does not exist on 10.6.8 and gcc gives me messages like this:
Undefined symbols for architecture i386:
"_strnlen", referenced from:
...
Undefined symbols for architecture ppc:
"_strnlen", referenced from:
...
So, I'd like to just define strnlen but don't quite know how.
Q: Can anyone please provide a working definition of strnlen to use in dcraw.c?
My gcc compilation command is this btw:
gcc -o dcraw -O4 -Wall -force_cpusubtype_ALL -mmacosx-version-min=10.4 -arch i386 -arch ppc dcraw.c -lm -DNODEPS
strnlen is a GNU extension and also specified in POSIX (IEEE Std 1003.1-2008). If strnlen
is not available (it is since 10.7) use the following replacement.
// Use this if strnlen is missing.
size_t strnlen(const char *str, size_t max)
{
const char *end = memchr (str, 0, max);
return end ? (size_t)(end - str) : max;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With