VirtualBox

source: vbox/trunk/src/VBox/Runtime/string/memset.cpp@ 331

Last change on this file since 331 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: 1.9 KB
Line 
1/* $Id: memset.cpp 1 1970-01-01 00:00:00Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime - CRT Strings, memset().
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
28
29/**
30 * Fill a memory block with specific byte.
31 *
32 * @returns pvDst.
33 * @param pvDst Pointer to the block.
34 * @param ch The filler char.
35 * @param cb The size of the block.
36 */
37#ifdef _MSC_VER
38# if _MSC_VER >= 1400
39void * __cdecl memset(__out_bcount_full_opt(_Size) void *pvDst, __in int ch, __in size_t cb)
40# else
41void *memset(void *pvDst, int ch, size_t cb)
42# endif
43#else
44void *memset(void *pvDst, int ch, size_t cb)
45#endif
46{
47 register union
48 {
49 uint8_t *pu8;
50 uint32_t *pu32;
51 void *pvDst;
52 } u;
53 u.pvDst = pvDst;
54
55 /* 32-bit word moves. */
56 register uint32_t u32 = ch | (ch << 8);
57 u32 |= u32 << 16;
58 register size_t c = cb >> 2;
59 while (c-- > 0)
60 *u.pu32++ = u32;
61
62 /* Remaining byte moves. */
63 c = cb & 3;
64 while (c-- > 0)
65 *u.pu8++ = (uint8_t)u32;
66
67 return pvDst;
68}
69
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