Last change
on this file since 948 was
850,
checked in by cfuguet, 10 years ago
|
reconf: introducing a softs directory in the reconfiguration branch
- This softs directory contains a minimalistic (giet-like) library
of drivers and some utility functions.
- Introducing a simple unit test in the vci_cc_vcache_wrapper
component to test the newly introduced watchdog timer mechanism.
This unit test uses the minimalistic library.
|
File size:
1.1 KB
|
Line | |
---|
1 | /** |
---|
2 | * \file string.c |
---|
3 | * \date July 8, 2014 |
---|
4 | * \author Cesar Fuguet |
---|
5 | * |
---|
6 | * \brief string utility functions |
---|
7 | */ |
---|
8 | #include <string.h> |
---|
9 | |
---|
10 | void *memset(void *_dst, int c, size_t len) |
---|
11 | { |
---|
12 | const char val = (char)c; |
---|
13 | |
---|
14 | /* |
---|
15 | * Write 12 bytes when destination buffer is aligned to 4 bytes and length |
---|
16 | * is greater or equal to 12 |
---|
17 | */ |
---|
18 | int *dst = _dst; |
---|
19 | if (!((int)dst & 0x3)) { |
---|
20 | const int word = (val << 24) | (val << 16) | (val << 8) | val; |
---|
21 | while (len > 11) { |
---|
22 | dst[0] = word; |
---|
23 | dst[1] = word; |
---|
24 | dst[2] = word; |
---|
25 | len -= 12; |
---|
26 | dst += 3; |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | /* |
---|
31 | * Write 1 byte when destination buffer is not aligned to 4 bytes or length |
---|
32 | * is smaller than 4 |
---|
33 | */ |
---|
34 | char *cdst = (char *)dst; |
---|
35 | while (len--) { |
---|
36 | *cdst++ = val; |
---|
37 | } |
---|
38 | |
---|
39 | return _dst; |
---|
40 | } |
---|
41 | |
---|
42 | void *memcpy(void *_dst, const void *_src, size_t n) |
---|
43 | { |
---|
44 | uint8_t *cdst = (uint8_t *)_dst; |
---|
45 | uint8_t *csrc = (uint8_t *)_src; |
---|
46 | while (n--) { |
---|
47 | *cdst++ = *csrc++; |
---|
48 | } |
---|
49 | return _dst; |
---|
50 | }; |
---|
51 | |
---|
52 | /* |
---|
53 | * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
---|
54 | */ |
---|
Note: See
TracBrowser
for help on using the repository browser.