VirtualBox

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

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1/* $Id: memcmp.cpp 1 1970-01-01 00:00:00Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime - CRT Strings, memcmp().
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung 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 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#include <iprt/string.h>
27#include <iprt/types.h>
28
29
30/**
31 * Copies a memory.
32 *
33 * @returns 0 if pvDst and pvSrc are equal
34 * @returns <0 if pvDst is 'smaller' than pvSrc.
35 * @returns >0 if pvDst is 'larger' than pvSrc.
36 *
37 * @param pvDst Pointer to the target block.
38 * @param pvSrc Pointer to the source block.
39 * @param cb The size of the block.
40 */
41#ifdef _MSC_VER
42# if _MSC_VER >= 1400
43__checkReturn int __cdecl memcmp(__in_bcount_opt(_Size) const void * pvDst, __in_bcount_opt(_Size) const void * pvSrc, __in size_t cb)
44# else
45int memcmp(const void *pvDst, const void *pvSrc, size_t cb)
46# endif
47#else
48int memcmp(const void *pvDst, const void *pvSrc, size_t cb)
49#endif
50{
51 register union
52 {
53 uint8_t const *pu8;
54 uint32_t const *pu32;
55 void const *pv;
56 } uDst, uSrc;
57 uDst.pv = pvDst;
58 uSrc.pv = pvSrc;
59
60 /* 32-bit word compare. */
61 register size_t c = cb >> 2;
62 while (c-- > 0)
63 {
64 /* ASSUMES int is at least 32-bit! */
65 register int32_t iDiff = *uDst.pu32++ - *uSrc.pu32++;
66 if (iDiff)
67 return iDiff;
68 }
69
70 /* Remaining byte moves. */
71 c = cb & 3;
72 while (c-- > 0)
73 {
74 register int8_t iDiff = *uDst.pu8++ - *uSrc.pu8++;
75 if (iDiff)
76 return iDiff;
77 }
78
79 return 0;
80}
81
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