Subject: Re: [PATCH 1/3] add strnncmp() function

From: Jonathan Nieder <[email-masked]>
Date: Mon, 16 Jun 2014 13:16:44 -0700

Jeremiah Mahler wrote:

> Add a strnncmp() function which behaves like strncmp() except it uses
> the length of both strings instead of just one.

The above description isn't very clear to me.  Problems:

 - strncmp compares prefixes of \0-terminated strings.  This function
   compares two binary buffers which can contain \0

 - strncmp is a comparison function and can even be used with functions
   like qsort (for operations like "sort on the first two characters").
   This function returns 0 or nonzero.

Would something like

  /* true if buffers have the same length and are byte-for-byte identical */
  int bufeq(const char *, int, const char *, int);

(or buf_equal, array_equal etc) make sense?