VirtualBox

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

Last change on this file since 4953 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1/* $Id: memcmp.cpp 4071 2007-08-07 17:07:59Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - CRT Strings, memcmp().
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include <iprt/string.h>
23#include <iprt/types.h>
24
25
26/**
27 * Copies a memory.
28 *
29 * @returns 0 if pvDst and pvSrc are equal
30 * @returns <0 if pvDst is 'smaller' than pvSrc.
31 * @returns >0 if pvDst is 'larger' than pvSrc.
32 *
33 * @param pvDst Pointer to the target block.
34 * @param pvSrc Pointer to the source block.
35 * @param cb The size of the block.
36 */
37#ifdef _MSC_VER
38# if _MSC_VER >= 1400
39__checkReturn int __cdecl memcmp(__in_bcount_opt(_Size) const void * pvDst, __in_bcount_opt(_Size) const void * pvSrc, __in size_t cb)
40# else
41int memcmp(const void *pvDst, const void *pvSrc, size_t cb)
42# endif
43#else
44int memcmp(const void *pvDst, const void *pvSrc, size_t cb)
45#endif
46{
47 register union
48 {
49 uint8_t const *pu8;
50 uint32_t const *pu32;
51 void const *pv;
52 } uDst, uSrc;
53 uDst.pv = pvDst;
54 uSrc.pv = pvSrc;
55
56 /* 32-bit word compare. */
57 register size_t c = cb >> 2;
58 while (c-- > 0)
59 {
60 /* ASSUMES int is at least 32-bit! */
61 register int32_t iDiff = *uDst.pu32++ - *uSrc.pu32++;
62 if (iDiff)
63 return iDiff;
64 }
65
66 /* Remaining byte moves. */
67 c = cb & 3;
68 while (c-- > 0)
69 {
70 register int8_t iDiff = *uDst.pu8++ - *uSrc.pu8++;
71 if (iDiff)
72 return iDiff;
73 }
74
75 return 0;
76}
77
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