mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: "Kurtis D. Rader" <kdrader@us.ibm.com>
Cc: Linux Kernel list <linux-kernel@vger.kernel.org>
Subject: Re: Platform device matching, & weird strncmp usage
Date: Sun, 08 Jan 2006 09:14:59 +1100	[thread overview]
Message-ID: <1136672100.30123.11.camel@localhost.localdomain> (raw)
In-Reply-To: <20060107192458.GA12409@us.ibm.com>


> 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.



      parent reply	other threads:[~2006-01-07 22:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-06  5:59 Benjamin Herrenschmidt
2006-01-06  6:04 ` Benjamin Herrenschmidt
2006-01-06 18:53 ` Russell King
2006-01-06 21:38   ` Benjamin Herrenschmidt
2006-01-07 19:24 ` Kurtis D. Rader
2006-01-07 19:42   ` Bob Copeland
2006-01-07 22:14   ` Benjamin Herrenschmidt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1136672100.30123.11.camel@localhost.localdomain \
    --to=benh@kernel.crashing.org \
    --cc=kdrader@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®