os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/compat/memcmp.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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
     9  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
    10  *
    11  * SCCS: @(#) memcmp.c 1.2 98/01/19 10:48:58
    12  */
    13 
    14 #include "tcl.h"
    15 #include "tclPort.h"
    16 
    17 /*
    18  * Here is the prototype just in case it is not included
    19  * in tclPort.h.
    20  */
    21 
    22 int		memcmp _ANSI_ARGS_((CONST VOID *s1,
    23 			    CONST VOID *s2, size_t n));
    24 
    25 /*
    26  *----------------------------------------------------------------------
    27  *
    28  * memcmp --
    29  *
    30  *	Compares two bytes sequences.
    31  *
    32  * Results:
    33  *     compares  its  arguments, looking at the first n
    34  *     bytes (each interpreted as an unsigned char), and  returns
    35  *     an integer less than, equal to, or greater than 0, accord-
    36  *     ing as s1 is less  than,  equal  to,  or
    37  *     greater than s2 when taken to be unsigned 8 bit numbers.
    38  *
    39  * Side effects:
    40  *	None.
    41  *
    42  *----------------------------------------------------------------------
    43  */
    44 
    45 int
    46 memcmp(s1, s2, n)
    47     CONST VOID *s1;			/* First string. */
    48     CONST VOID *s2;			/* Second string. */
    49     size_t      n;                      /* Length to compare. */
    50 {
    51     CONST unsigned char *ptr1 = (CONST unsigned char *) s1;
    52     CONST unsigned char *ptr2 = (CONST unsigned char *) s2;
    53 
    54     for ( ; n-- ; ptr1++, ptr2++) {
    55 	unsigned char u1 = *s1, u2 = *s2;
    56 
    57 	if ( u1 != u2) {
    58 	    return (u1-u2);
    59 	}
    60     }
    61     return 0;
    62 }