1 | /* |
---|
2 | This file is part of MutekP. |
---|
3 | |
---|
4 | MutekP is free software; you can redistribute it and/or modify it |
---|
5 | under the terms of the GNU General Public License as published by |
---|
6 | the Free Software Foundation; either version 2 of the License, or |
---|
7 | (at your option) any later version. |
---|
8 | |
---|
9 | MutekP is distributed in the hope that it will be useful, but |
---|
10 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
12 | General Public License for more details. |
---|
13 | |
---|
14 | You should have received a copy of the GNU General Public License |
---|
15 | along with MutekP; if not, write to the Free Software Foundation, |
---|
16 | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
17 | |
---|
18 | UPMC / LIP6 / SOC (c) 2008 |
---|
19 | Copyright Ghassan Almaless <ghassan.almaless@gmail.com> |
---|
20 | */ |
---|
21 | |
---|
22 | #include <string.h> |
---|
23 | |
---|
24 | void *memset (void *s, int c, unsigned int size) |
---|
25 | { |
---|
26 | register char *ptr = s; |
---|
27 | register unsigned int *iptr; |
---|
28 | register unsigned int val; |
---|
29 | register unsigned int isize; |
---|
30 | register unsigned int iamount; |
---|
31 | |
---|
32 | while(((uint32_t) ptr & 0x3) && size && size--) |
---|
33 | *(ptr++) = (char) c; |
---|
34 | |
---|
35 | if(!size) return s; |
---|
36 | |
---|
37 | val = c << 24 | c << 16 | c << 8 | (c & 0xFF); |
---|
38 | isize = size >> 2; |
---|
39 | iamount = isize << 2; |
---|
40 | iptr = (unsigned int*) ptr; |
---|
41 | |
---|
42 | while(isize--) |
---|
43 | *(iptr++) = val; |
---|
44 | |
---|
45 | size = size - iamount; |
---|
46 | ptr = (char*) iptr; |
---|
47 | |
---|
48 | while(size--) |
---|
49 | *(ptr++) = (char) c; |
---|
50 | |
---|
51 | return s; |
---|
52 | } |
---|