| 2 |
theseven |
1 |
//
|
|
|
2 |
//
|
|
|
3 |
// Copyright 2010 TheSeven
|
|
|
4 |
//
|
|
|
5 |
//
|
|
|
6 |
// This file is part of emBIOS.
|
|
|
7 |
//
|
|
|
8 |
// emBIOS is free software: you can redistribute it and/or
|
|
|
9 |
// modify it under the terms of the GNU General Public License as
|
|
|
10 |
// published by the Free Software Foundation, either version 2 of the
|
|
|
11 |
// License, or (at your option) any later version.
|
|
|
12 |
//
|
|
|
13 |
// emBIOS is distributed in the hope that it will be useful,
|
|
|
14 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
16 |
// See the GNU General Public License for more details.
|
|
|
17 |
//
|
|
|
18 |
// You should have received a copy of the GNU General Public License along
|
|
|
19 |
// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
//
|
|
|
21 |
//
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
#include "global.h"
|
|
|
25 |
#include "util.h"
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
void* memcpy(void* destination, const void* source, size_t num)
|
|
|
29 |
{
|
|
|
30 |
unsigned char* dest = (unsigned char*)destination;
|
|
|
31 |
unsigned char* src = (unsigned char*)source;
|
|
|
32 |
while (num--) *dest++ = *src++;
|
|
|
33 |
return destination;
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
void* memset(void* ptr, int value, size_t num)
|
|
|
37 |
{
|
|
|
38 |
unsigned char* dest = (unsigned char*)ptr;
|
|
|
39 |
while (num--) *dest++ = (unsigned char)value;
|
|
|
40 |
return ptr;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
int memcmp(const void* ptr1, const void* ptr2, size_t num)
|
|
|
44 |
{
|
|
|
45 |
unsigned char* src1 = (unsigned char*)ptr1;
|
|
|
46 |
unsigned char* src2 = (unsigned char*)ptr2;
|
|
|
47 |
int diff;
|
|
|
48 |
while (num--)
|
|
|
49 |
if (diff = *src1++ - *src2++)
|
|
|
50 |
return diff;
|
|
|
51 |
return 0;
|
|
|
52 |
}
|
| 58 |
theseven |
53 |
|
|
|
54 |
void* memchr(const void* ptr, int value, size_t num)
|
|
|
55 |
{
|
|
|
56 |
unsigned char val = (unsigned char)value;
|
|
|
57 |
while (num-- > 0)
|
|
|
58 |
{
|
|
|
59 |
if (*((unsigned char*)ptr) == val)
|
|
|
60 |
return (void*)ptr;
|
|
|
61 |
ptr++;
|
|
|
62 |
}
|
|
|
63 |
return NULL;
|
|
|
64 |
}
|