Re: Platform device matching, & weird strncmp usage

From: Benjamin Herrenschmidt
Date: Sat Jan 07 2006 - 17:12:51 EST



> I can't speak to the correctness of that code but your understanding of
> strncmp() is incorrect. From "GNU C Library Application Fundamentals":
>
> This function is the [sic] similar to strcmp, except that no more
> than size wide characters are compared. In other words, if the two
> strings are the same in their first size wide characters, the return
> value is zero.
>
> And this has been may experience for the past 20 years and is confirmed by
> this trivial program which prints zero in both cases:
>
> #include <string.h>
> #include <stdio.h>
> int main() {
> printf("%d\n", strncmp("abc","abcd",3));
> printf("%d\n", strncmp("abcd","abc",3));
> }

Except that in my example, the count was larger than both strings...

Anyway, it happens to not be a problem as the string I was comparing was
not in fact different.

Ben.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/