public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: Wilco Dijkstra via Libc-alpha <libc-alpha@sourceware.org>,
	Noah Goldstein <goldstein.w.n@gmail.com>
Subject: Re: [PATCH v2 3/7] string/test-str*cmp: remove stupid_[strcmp, strncmp, wcscmp, wcsncmp].
Date: Mon, 10 Jan 2022 13:56:35 +0000	[thread overview]
Message-ID: <AS8PR08MB65349E404E48248BE5DE042F83509@AS8PR08MB6534.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <87mtk3yblz.fsf@oldenburg.str.redhat.com>

Hi Florian,

> strncmp is commonly used as a starts-with-prefix function, as in:
>
>   strncmp (s, "prefix", 6)
>
> This would be the second case: stopping at NUL before the number of
> specified bytes are read.

Indeed, such usage is both common and natural. There is only one size parameter,
so you couldn't ever use strncmp on strings you didn't know the buffer size of,
making it useless. Compilers don't optimize this to memcmp eventhough the C
standard seems to allow that, so the accepted standard is that strn* functions
must stop at the first NUL character.

Cheers,
Wilco

  reply	other threads:[~2022-01-10 13:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-10 11:42 Wilco Dijkstra
2022-01-10 12:42 ` Florian Weimer
2022-01-10 13:09   ` Wilco Dijkstra
2022-01-10 13:16     ` Florian Weimer
2022-01-10 13:56       ` Wilco Dijkstra [this message]
2022-01-10 18:39 ` Noah Goldstein
2022-01-10 21:38 ` Noah Goldstein
  -- strict thread matches above, loose matches on Subject: below --
2022-01-09 12:29 [PATCH v1 1/5] x86: Optimize strcmp-avx2.S and fix for [BZ# 28755] Noah Goldstein
2022-01-10  0:27 ` [PATCH v2 1/7] x86: Fix __wcsncmp_avx2 in strcmp-avx2.S " Noah Goldstein
2022-01-10  0:27   ` [PATCH v2 3/7] string/test-str*cmp: remove stupid_[strcmp, strncmp, wcscmp, wcsncmp] Noah Goldstein
2022-01-10  0:37     ` H.J. Lu

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=AS8PR08MB65349E404E48248BE5DE042F83509@AS8PR08MB6534.eurprd08.prod.outlook.com \
    --to=wilco.dijkstra@arm.com \
    --cc=fweimer@redhat.com \
    --cc=goldstein.w.n@gmail.com \
    --cc=libc-alpha@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).