str: provide checks for ctype.h char functions, and strstr and strchr functions.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 17 Mar 2011 11:42:22 +0000 (22:12 +1030)
commitecea073699c60fd5aab9e3955f59a7042d637b68
tree69442a501f597fa57f1902105e60f03660bf18e3
parent3f4e83d8ac847d6bf0c20e88cdbca535e842a97b
str: provide checks for ctype.h char functions, and strstr and strchr functions.

In the former case, we were bitten by the fact that you don't pass a char
to isalpha() et al: you pass an int.  This means on most platforms you want
to do:

   if (isalpha((unsigned char)c)) ...

Insane?  Yes, but I assure you I'm not making this up.

Similarly, I've always wanted strstr, strchr and strrchr to return
const char * when given a const char * argument to search, to avoid
constness leak.

In both cases, the actual versions from the headers may be macros, so
we need to be very careful overriding them.  The result is that they
become out-of-line functions which is unacceptable for general
performance.

So we only activate these when CCAN_STR_DEBUG is defined.
20 files changed:
ccan/str/_info
ccan/str/debug.c [new file with mode: 0644]
ccan/str/str.h
ccan/str/str_debug.h [new file with mode: 0644]
ccan/str/test/compile_fail-isalnum.c [new file with mode: 0644]
ccan/str/test/compile_fail-isalpha.c [new file with mode: 0644]
ccan/str/test/compile_fail-isascii.c [new file with mode: 0644]
ccan/str/test/compile_fail-isblank.c [new file with mode: 0644]
ccan/str/test/compile_fail-iscntrl.c [new file with mode: 0644]
ccan/str/test/compile_fail-isdigit.c [new file with mode: 0644]
ccan/str/test/compile_fail-islower.c [new file with mode: 0644]
ccan/str/test/compile_fail-isprint.c [new file with mode: 0644]
ccan/str/test/compile_fail-ispunct.c [new file with mode: 0644]
ccan/str/test/compile_fail-isspace.c [new file with mode: 0644]
ccan/str/test/compile_fail-isupper.c [new file with mode: 0644]
ccan/str/test/compile_fail-isxdigit.c [new file with mode: 0644]
ccan/str/test/compile_fail-strchr.c [new file with mode: 0644]
ccan/str/test/compile_fail-strrchr.c [new file with mode: 0644]
ccan/str/test/compile_fail-strstr.c [new file with mode: 0644]
ccan/str/test/debug.c [new file with mode: 0644]