Strnlen does not exist in gcc-4.2.1 on Mac OS X 10.6.8 - how to define it?

I am creating a cross-platform version of OS X with the latest version of dcraw.c I am doing this on OS X 10.6.8 until I have PPC compatibility. Now my problem is that strnlen seems to be used in the latest version of the program, and it is not in 10.6.8, and gcc gives me these messages:

Undefined symbols for architecture i386: "_strnlen", referenced from: ... Undefined symbols for architecture ppc: "_strnlen", referenced from: ... 

So, I would just like to define strnlen, but don't know how to do it.

Q: Is it possible to provide a working strnlen definition for use in dcraw.c?

My gcc compilation command is btw:

 gcc -o dcraw -O4 -Wall -force_cpusubtype_ALL -mmacosx-version-min=10.4 -arch i386 -arch ppc dcraw.c -lm -DNODEPS 
+5
source share
1 answer

strnlen is a GNU extension and is also specified in POSIX (IEEE Std 1003.1-2008). If strnlen unavailable (starting at 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; } 
+8
source

All Articles