sl@0: /* sl@0: * memcmp.c -- sl@0: * sl@0: * Source code for the "memcmp" library routine. sl@0: * sl@0: * Copyright (c) 1998 Sun Microsystems, Inc. sl@0: * sl@0: * See the file "license.terms" for information on usage and redistribution sl@0: * of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: * sl@0: * SCCS: @(#) memcmp.c 1.2 98/01/19 10:48:58 sl@0: */ sl@0: sl@0: #include "tcl.h" sl@0: #include "tclPort.h" sl@0: sl@0: /* sl@0: * Here is the prototype just in case it is not included sl@0: * in tclPort.h. sl@0: */ sl@0: sl@0: int memcmp _ANSI_ARGS_((CONST VOID *s1, sl@0: CONST VOID *s2, size_t n)); sl@0: sl@0: /* sl@0: *---------------------------------------------------------------------- sl@0: * sl@0: * memcmp -- sl@0: * sl@0: * Compares two bytes sequences. sl@0: * sl@0: * Results: sl@0: * compares its arguments, looking at the first n sl@0: * bytes (each interpreted as an unsigned char), and returns sl@0: * an integer less than, equal to, or greater than 0, accord- sl@0: * ing as s1 is less than, equal to, or sl@0: * greater than s2 when taken to be unsigned 8 bit numbers. sl@0: * sl@0: * Side effects: sl@0: * None. sl@0: * sl@0: *---------------------------------------------------------------------- sl@0: */ sl@0: sl@0: int sl@0: memcmp(s1, s2, n) sl@0: CONST VOID *s1; /* First string. */ sl@0: CONST VOID *s2; /* Second string. */ sl@0: size_t n; /* Length to compare. */ sl@0: { sl@0: CONST unsigned char *ptr1 = (CONST unsigned char *) s1; sl@0: CONST unsigned char *ptr2 = (CONST unsigned char *) s2; sl@0: sl@0: for ( ; n-- ; ptr1++, ptr2++) { sl@0: unsigned char u1 = *s1, u2 = *s2; sl@0: sl@0: if ( u1 != u2) { sl@0: return (u1-u2); sl@0: } sl@0: } sl@0: return 0; sl@0: }