Re: Platform device matching, & weird strncmp usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux