wrapper: add function to compare strings with different NUL termination
commit14570dc67d2a500dfb9f33a7445bdbd6133af4ac
authorbrian m. carlson <sandals@crustytoothpaste.net>
Mon, 25 May 2020 19:58:50 +0000 (25 19:58 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 May 2020 17:07:06 +0000 (27 10:07 -0700)
treee233933443b76a1833c4b904d9fc0b3c2e296245
parent92315e50b275deee8e84d28ee1ff1ad555a5de36
wrapper: add function to compare strings with different NUL termination

When parsing capabilities for the pack protocol, there are times we'll
want to compare the value of a capability to a NUL-terminated string.
Since the data we're reading will be space-terminated, not
NUL-terminated, we need a function that compares the two strings, but
also checks that they're the same length.  Otherwise, if we used strncmp
to compare these strings, we might accidentally accept a parameter that
was a prefix of the expected value.

Add a function, xstrncmpz, that takes a NUL-terminated string and a
non-NUL-terminated string, plus a length, and compares them, ensuring
that they are the same length.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-compat-util.h
wrapper.c