VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/string/memcmp.cpp@ 21337

Last change on this file since 21337 was 8245, checked in by vboxsync, 17 years ago

rebranding: IPRT files again.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1/* $Id: memcmp.cpp 8245 2008-04-21 17:24:28Z vboxsync $ */
2/** @file
3 * IPRT - CRT Strings, memcmp().
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <iprt/string.h>
36#include <iprt/types.h>
37
38
39/**
40 * Copies a memory.
41 *
42 * @returns 0 if pvDst and pvSrc are equal
43 * @returns <0 if pvDst is 'smaller' than pvSrc.
44 * @returns >0 if pvDst is 'larger' than pvSrc.
45 *
46 * @param pvDst Pointer to the target block.
47 * @param pvSrc Pointer to the source block.
48 * @param cb The size of the block.
49 */
50#ifdef _MSC_VER
51# if _MSC_VER >= 1400
52__checkReturn int __cdecl memcmp(__in_bcount_opt(_Size) const void * pvDst, __in_bcount_opt(_Size) const void * pvSrc, __in size_t cb)
53# else
54int __cdecl memcmp(const void *pvDst, const void *pvSrc, size_t cb)
55# endif
56#else
57int memcmp(const void *pvDst, const void *pvSrc, size_t cb)
58#endif
59{
60 register union
61 {
62 uint8_t const *pu8;
63 uint32_t const *pu32;
64 void const *pv;
65 } uDst, uSrc;
66 uDst.pv = pvDst;
67 uSrc.pv = pvSrc;
68
69 /* 32-bit word compare. */
70 register size_t c = cb >> 2;
71 while (c-- > 0)
72 {
73 /* ASSUMES int is at least 32-bit! */
74 register int32_t iDiff = *uDst.pu32++ - *uSrc.pu32++;
75 if (iDiff)
76 return iDiff;
77 }
78
79 /* Remaining byte moves. */
80 c = cb & 3;
81 while (c-- > 0)
82 {
83 register int8_t iDiff = *uDst.pu8++ - *uSrc.pu8++;
84 if (iDiff)
85 return iDiff;
86 }
87
88 return 0;
89}
90
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette