| 1 |
/* |
| 2 |
* memcmp.c -- |
| 3 |
* |
| 4 |
* Source code for the "memcmp" library routine. |
| 5 |
* |
| 6 |
* Copyright (c) 1998 Sun Microsystems, Inc. |
| 7 |
* |
| 8 |
* See the file "license.terms" for information on usage and redistribution of |
| 9 |
* this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 10 |
*/ |
| 11 |
|
| 12 |
#include "tclPort.h" |
| 13 |
|
| 14 |
/* |
| 15 |
* Here is the prototype just in case it is not included in tclPort.h. |
| 16 |
*/ |
| 17 |
|
| 18 |
int memcmp(const void *s1, const void *s2, size_t n); |
| 19 |
|
| 20 |
/* |
| 21 |
*---------------------------------------------------------------------- |
| 22 |
* |
| 23 |
* memcmp -- |
| 24 |
* |
| 25 |
* Compares two bytes sequences. |
| 26 |
* |
| 27 |
* Results: |
| 28 |
* Compares its arguments, looking at the first n bytes (each interpreted |
| 29 |
* as an unsigned char), and returns an integer less than, equal to, or |
| 30 |
* greater than 0, according as s1 is less than, equal to, or greater |
| 31 |
* than s2 when taken to be unsigned 8 bit numbers. |
| 32 |
* |
| 33 |
* Side effects: |
| 34 |
* None. |
| 35 |
* |
| 36 |
*---------------------------------------------------------------------- |
| 37 |
*/ |
| 38 |
|
| 39 |
int |
| 40 |
memcmp( |
| 41 |
const void *s1, /* First string. */ |
| 42 |
const void *s2, /* Second string. */ |
| 43 |
size_t n) /* Length to compare. */ |
| 44 |
{ |
| 45 |
const unsigned char *ptr1 = (const unsigned char *) s1; |
| 46 |
const unsigned char *ptr2 = (const unsigned char *) s2; |
| 47 |
|
| 48 |
for ( ; n-- ; ptr1++, ptr2++) { |
| 49 |
unsigned char u1 = *ptr1, u2 = *ptr2; |
| 50 |
|
| 51 |
if (u1 != u2) { |
| 52 |
return (u1-u2); |
| 53 |
} |
| 54 |
} |
| 55 |
return 0; |
| 56 |
} |
| 57 |
|
| 58 |
/* |
| 59 |
* Local Variables: |
| 60 |
* mode: c |
| 61 |
* c-basic-offset: 4 |
| 62 |
* fill-column: 78 |
| 63 |
* End: |
| 64 |
*/ |