Changeset 6b080e54 in mainline
- Timestamp:
- 2008-12-23T16:35:31Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7a817d00
- Parents:
- 47acd58
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/string.c
r47acd58 r6b080e54 43 43 #include <malloc.h> 44 44 45 /* Dummy implementation of mem/ functions */ 46 47 void *memset(void *s, int c, size_t n) 48 { 49 char *os = s; 50 51 while (n--) 52 *(os++) = c; 53 54 return s; 45 /** Fill memory block with a constant value. */ 46 void *memset(void *dest, int b, size_t n) 47 { 48 char *pb; 49 unsigned long *pw; 50 size_t word_size; 51 size_t n_words; 52 53 unsigned long pattern; 54 size_t i; 55 size_t fill; 56 57 /* Fill initial segment. */ 58 word_size = sizeof(unsigned long); 59 fill = word_size - ((uintptr_t) dest & (word_size - 1)); 60 if (fill > n) fill = n; 61 62 pb = dest; 63 64 i = fill; 65 while (i-- != 0) 66 *pb++ = b; 67 68 /* Compute remaining size. */ 69 n -= fill; 70 if (n == 0) return dest; 71 72 n_words = n / word_size; 73 n = n % word_size; 74 pw = (unsigned long *) pb; 75 76 /* Create word-sized pattern for aligned segment. */ 77 pattern = 0; 78 i = word_size; 79 while (i-- != 0) 80 pattern = (pattern << 8) | (uint8_t) b; 81 82 /* Fill aligned segment. */ 83 i = n_words; 84 while (i-- != 0) 85 *pw++ = pattern; 86 87 pb = (char *) pw; 88 89 /* Fill final segment. */ 90 i = n; 91 while (i-- != 0) 92 *pb++ = b; 93 94 return dest; 55 95 } 56 96 … … 115 155 116 156 i = fill; 117 while (i-- >0)157 while (i-- != 0) 118 158 *dstb++ = *srcb++; 119 159 … … 133 173 /* "Fast" copy. */ 134 174 i = n_words; 135 while (i-- >0)175 while (i-- != 0) 136 176 *dstw++ = *srcw++; 137 177 … … 144 184 145 185 i = n; 146 while (i-- >0)186 while (i-- != 0) 147 187 *dstb++ = *srcb++; 148 188
Note:
See TracChangeset
for help on using the changeset viewer.