[3574] | 1 | /* $Id: kHlpMemPComp.c 3608 2007-10-29 00:49:05Z bird $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * kHlpString - kHlpMemPComp.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[3608] | 7 | * Copyright (c) 2006-2007 knut st. osmundsen <bird-kStuff-spam@anduin.net>
|
---|
[3574] | 8 | *
|
---|
| 9 | * This file is part of kStuff.
|
---|
| 10 | *
|
---|
| 11 | * kStuff is free software; you can redistribute it and/or
|
---|
| 12 | * modify it under the terms of the GNU Lesser General Public
|
---|
| 13 | * License as published by the Free Software Foundation; either
|
---|
| 14 | * version 2.1 of the License, or (at your option) any later version.
|
---|
| 15 | *
|
---|
[3608] | 16 | * In addition to the permissions in the GNU Lesser General Public
|
---|
| 17 | * License, you are granted unlimited permission to link the compiled
|
---|
| 18 | * version of this file into combinations with other programs, and to
|
---|
| 19 | * distribute those combinations without any restriction coming from
|
---|
| 20 | * the use of this file.
|
---|
| 21 | *
|
---|
[3574] | 22 | * kStuff is distributed in the hope that it will be useful,
|
---|
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 25 | * Lesser General Public License for more details.
|
---|
| 26 | *
|
---|
| 27 | * You should have received a copy of the GNU Lesser General Public
|
---|
| 28 | * License along with kStuff; if not, write to the Free Software
|
---|
[3608] | 29 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
---|
| 30 | * 02110-1301, USA
|
---|
[3574] | 31 | */
|
---|
| 32 |
|
---|
| 33 | /*******************************************************************************
|
---|
| 34 | * Header Files *
|
---|
| 35 | *******************************************************************************/
|
---|
| 36 | #include <k/kHlpString.h>
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | KHLP_DECL(void *) kHlpMemPComp(const void *pv1, const void *pv2, KSIZE cb)
|
---|
| 40 | {
|
---|
| 41 | union
|
---|
| 42 | {
|
---|
| 43 | const void *pv;
|
---|
| 44 | const KU8 *pb;
|
---|
| 45 | const KUPTR *pu;
|
---|
| 46 | } u1, u2;
|
---|
| 47 |
|
---|
| 48 | u1.pv = pv1;
|
---|
| 49 | u2.pv = pv2;
|
---|
| 50 |
|
---|
| 51 | if (cb >= 32)
|
---|
| 52 | {
|
---|
| 53 | while (cb > sizeof(KUPTR))
|
---|
| 54 | {
|
---|
| 55 | if (*u1.pu != *u2.pu)
|
---|
| 56 | break; /* over to mr. byte-by-byte */
|
---|
| 57 | u1.pu++;
|
---|
| 58 | u2.pu++;
|
---|
| 59 | cb -= sizeof(KUPTR);
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | while (cb-- > 0)
|
---|
| 64 | {
|
---|
| 65 | if (u1.pb != u2.pb)
|
---|
| 66 | return (void *)u1.pb;
|
---|
| 67 | u1.pb++;
|
---|
| 68 | u2.pb++;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | return NULL;
|
---|
| 72 | }
|
---|
| 73 |
|
---|