os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/compat/memcmp.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* 
sl@0
     2
 * memcmp.c --
sl@0
     3
 *
sl@0
     4
 *	Source code for the "memcmp" library routine.
sl@0
     5
 *
sl@0
     6
 * Copyright (c) 1998 Sun Microsystems, Inc.
sl@0
     7
 *
sl@0
     8
 * See the file "license.terms" for information on usage and redistribution
sl@0
     9
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
sl@0
    10
 *
sl@0
    11
 * SCCS: @(#) memcmp.c 1.2 98/01/19 10:48:58
sl@0
    12
 */
sl@0
    13
sl@0
    14
#include "tcl.h"
sl@0
    15
#include "tclPort.h"
sl@0
    16
sl@0
    17
/*
sl@0
    18
 * Here is the prototype just in case it is not included
sl@0
    19
 * in tclPort.h.
sl@0
    20
 */
sl@0
    21
sl@0
    22
int		memcmp _ANSI_ARGS_((CONST VOID *s1,
sl@0
    23
			    CONST VOID *s2, size_t n));
sl@0
    24

sl@0
    25
/*
sl@0
    26
 *----------------------------------------------------------------------
sl@0
    27
 *
sl@0
    28
 * memcmp --
sl@0
    29
 *
sl@0
    30
 *	Compares two bytes sequences.
sl@0
    31
 *
sl@0
    32
 * Results:
sl@0
    33
 *     compares  its  arguments, looking at the first n
sl@0
    34
 *     bytes (each interpreted as an unsigned char), and  returns
sl@0
    35
 *     an integer less than, equal to, or greater than 0, accord-
sl@0
    36
 *     ing as s1 is less  than,  equal  to,  or
sl@0
    37
 *     greater than s2 when taken to be unsigned 8 bit numbers.
sl@0
    38
 *
sl@0
    39
 * Side effects:
sl@0
    40
 *	None.
sl@0
    41
 *
sl@0
    42
 *----------------------------------------------------------------------
sl@0
    43
 */
sl@0
    44
sl@0
    45
int
sl@0
    46
memcmp(s1, s2, n)
sl@0
    47
    CONST VOID *s1;			/* First string. */
sl@0
    48
    CONST VOID *s2;			/* Second string. */
sl@0
    49
    size_t      n;                      /* Length to compare. */
sl@0
    50
{
sl@0
    51
    CONST unsigned char *ptr1 = (CONST unsigned char *) s1;
sl@0
    52
    CONST unsigned char *ptr2 = (CONST unsigned char *) s2;
sl@0
    53
sl@0
    54
    for ( ; n-- ; ptr1++, ptr2++) {
sl@0
    55
	unsigned char u1 = *s1, u2 = *s2;
sl@0
    56
sl@0
    57
	if ( u1 != u2) {
sl@0
    58
	    return (u1-u2);
sl@0
    59
	}
sl@0
    60
    }
sl@0
    61
    return 0;
sl@0
    62
}