Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/compat/memcmp.c @ 37

Last change on this file since 37 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 1.5 KB
Line 
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 * RCS: @(#) $Id: memcmp.c,v 1.4 2007/01/22 09:15:50 dkf Exp $
12 */
13
14#include "tclPort.h"
15
16/*
17 * Here is the prototype just in case it is not included in tclPort.h.
18 */
19
20int             memcmp(CONST VOID *s1, CONST VOID *s2, size_t n);
21
22/*
23 *----------------------------------------------------------------------
24 *
25 * memcmp --
26 *
27 *      Compares two bytes sequences.
28 *
29 * Results:
30 *      Compares its arguments, looking at the first n bytes (each interpreted
31 *      as an unsigned char), and returns an integer less than, equal to, or
32 *      greater than 0, according as s1 is less than, equal to, or greater
33 *      than s2 when taken to be unsigned 8 bit numbers.
34 *
35 * Side effects:
36 *      None.
37 *
38 *----------------------------------------------------------------------
39 */
40
41int
42memcmp(
43    CONST VOID *s1,             /* First string. */
44    CONST VOID *s2,             /* Second string. */
45    size_t n)                   /* Length to compare. */
46{
47    CONST unsigned char *ptr1 = (CONST unsigned char *) s1;
48    CONST unsigned char *ptr2 = (CONST unsigned char *) s2;
49
50    for ( ; n-- ; ptr1++, ptr2++) {
51        unsigned char u1 = *ptr1, u2 = *ptr2;
52
53        if (u1 != u2) {
54            return (u1-u2);
55        }
56    }
57    return 0;
58}
59
60/*
61 * Local Variables:
62 * mode: c
63 * c-basic-offset: 4
64 * fill-column: 78
65 * End:
66 */
Note: See TracBrowser for help on using the repository browser.