chiark / gitweb /
Fix up more warnings. Actually read from connections
[inn-innduct.git] / lib / memcmp.c
1 /*  $Id: memcmp.c 5049 2001-12-12 09:06:00Z rra $
2 **
3 **  Replacement for a missing or broken memcmp.
4 **
5 **  Written by Russ Allbery <rra@stanford.edu>
6 **  This work is hereby placed in the public domain by its author.
7 **
8 **  Provides the same functionality as the standard library routine memcmp
9 **  for those platforms that don't have it or where it doesn't work right
10 **  (such as on SunOS where it can't deal with eight-bit characters).
11 */
12
13 #include "config.h"
14 #include <sys/types.h>
15
16 /* If we're running the test suite, rename memcmp to avoid conflicts with
17    the system version. */
18 #if TESTING
19 # define memcmp test_memcmp
20 int test_memcmp(const void *, const void *, size_t);
21 #endif
22
23 int
24 memcmp(const void *s1, const void *s2, size_t n)
25 {
26     size_t i;
27     const unsigned char *p1, *p2;
28
29     /* It's technically illegal to call memcmp with NULL pointers, but we
30        may as well check anyway. */
31     if (!s1)
32         return !s2 ? 0 : -1;
33     if (!s2)
34         return 1;
35
36     p1 = (const unsigned char *) s1;
37     p2 = (const unsigned char *) s2;
38     for (i = 0; i < n; i++, p1++, p2++)
39         if (*p1 != *p2)
40             return (int) *p1 - (int) *p2;
41     return 0;
42 }