- Timestamp:
- 2013-03-31T19:46:19Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a5057cc
- Parents:
- 582f4d28
- Location:
- uspace/lib
- Files:
-
- 3 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/arch/amd64/Makefile.inc
r582f4d28 r45f7449 28 28 29 29 ARCH_SOURCES = \ 30 arch/$(UARCH)/src/asm.S \31 30 arch/$(UARCH)/src/entry.s \ 32 31 arch/$(UARCH)/src/entryjmp.s \ -
uspace/lib/c/arch/ia32/Makefile.inc
r582f4d28 r45f7449 28 28 29 29 ARCH_SOURCES = \ 30 arch/$(UARCH)/src/asm.S \31 30 arch/$(UARCH)/src/entry.S \ 32 31 arch/$(UARCH)/src/entryjmp.s \ -
uspace/lib/c/arch/mips32/Makefile.inc
r582f4d28 r45f7449 28 28 29 29 ARCH_SOURCES = \ 30 arch/$(UARCH)/src/asm.S \31 30 arch/$(UARCH)/src/entry.S \ 32 31 arch/$(UARCH)/src/entryjmp.S \ -
uspace/lib/c/arch/mips32eb/Makefile.inc
r582f4d28 r45f7449 28 28 29 29 ARCH_SOURCES = \ 30 arch/$(UARCH)/src/asm.S \31 30 arch/$(UARCH)/src/entry.S \ 32 31 arch/$(UARCH)/src/entryjmp.S \ -
uspace/lib/c/generic/mem.c
r582f4d28 r45f7449 38 38 #include <sys/types.h> 39 39 40 /** Fill memory block with a constant value. */ 41 void *memset(void *dest, int b, size_t n) 42 { 43 char *pb; 44 unsigned long *pw; 45 size_t word_size; 46 size_t n_words; 47 48 unsigned long pattern; 49 size_t i; 50 size_t fill; 51 52 /* Fill initial segment. */ 53 word_size = sizeof(unsigned long); 54 fill = word_size - ((uintptr_t) dest & (word_size - 1)); 55 if (fill > n) fill = n; 56 57 pb = dest; 58 59 i = fill; 60 while (i-- != 0) 61 *pb++ = b; 62 63 /* Compute remaining size. */ 64 n -= fill; 65 if (n == 0) return dest; 66 67 n_words = n / word_size; 68 n = n % word_size; 69 pw = (unsigned long *) pb; 70 71 /* Create word-sized pattern for aligned segment. */ 72 pattern = 0; 73 i = word_size; 74 while (i-- != 0) 75 pattern = (pattern << 8) | (uint8_t) b; 76 77 /* Fill aligned segment. */ 78 i = n_words; 79 while (i-- != 0) 80 *pw++ = pattern; 81 82 pb = (char *) pw; 83 84 /* Fill final segment. */ 85 i = n; 86 while (i-- != 0) 87 *pb++ = b; 88 89 return dest; 90 } 91 92 struct along { 93 unsigned long n; 94 } __attribute__ ((packed)); 95 96 static void *unaligned_memcpy(void *dst, const void *src, size_t n) 97 { 98 size_t i, j; 99 struct along *adst = dst; 100 const struct along *asrc = src; 101 102 for (i = 0; i < n / sizeof(unsigned long); i++) 103 adst[i].n = asrc[i].n; 104 105 for (j = 0; j < n % sizeof(unsigned long); j++) 106 ((unsigned char *) (((unsigned long *) dst) + i))[j] = 107 ((unsigned char *) (((unsigned long *) src) + i))[j]; 108 109 return (char *) dst; 110 } 111 112 /** Copy memory block. */ 113 void *memcpy(void *dst, const void *src, size_t n) 114 { 115 size_t i; 116 size_t mod, fill; 117 size_t word_size; 118 size_t n_words; 119 120 const unsigned long *srcw; 121 unsigned long *dstw; 122 const uint8_t *srcb; 123 uint8_t *dstb; 124 125 word_size = sizeof(unsigned long); 126 127 /* 128 * Are source and destination addresses congruent modulo word_size? 129 * If not, use unaligned_memcpy(). 130 */ 131 132 if (((uintptr_t) dst & (word_size - 1)) != 133 ((uintptr_t) src & (word_size - 1))) 134 return unaligned_memcpy(dst, src, n); 135 136 /* 137 * mod is the address modulo word size. fill is the length of the 138 * initial buffer segment before the first word boundary. 139 * If the buffer is very short, use unaligned_memcpy(), too. 140 */ 141 142 mod = (uintptr_t) dst & (word_size - 1); 143 fill = word_size - mod; 144 if (fill > n) fill = n; 145 146 /* Copy the initial segment. */ 147 148 srcb = src; 149 dstb = dst; 150 151 i = fill; 152 while (i-- != 0) 153 *dstb++ = *srcb++; 154 155 /* Compute remaining length. */ 156 157 n -= fill; 158 if (n == 0) return dst; 159 160 /* Pointers to aligned segment. */ 161 162 dstw = (unsigned long *) dstb; 163 srcw = (const unsigned long *) srcb; 164 165 n_words = n / word_size; /* Number of whole words to copy. */ 166 n -= n_words * word_size; /* Remaining bytes at the end. */ 167 168 /* "Fast" copy. */ 169 i = n_words; 170 while (i-- != 0) 171 *dstw++ = *srcw++; 172 173 /* 174 * Copy the rest. 175 */ 176 177 srcb = (const uint8_t *) srcw; 178 dstb = (uint8_t *) dstw; 179 180 i = n; 181 while (i-- != 0) 182 *dstb++ = *srcb++; 183 184 return dst; 185 } 186 40 187 /** Move memory block with possible overlapping. */ 41 188 void *memmove(void *dst, const void *src, size_t n) -
uspace/lib/c/include/mem.h
r582f4d28 r45f7449 38 38 #include <sys/types.h> 39 39 40 #define memset(dst, val, cnt) __builtin_memset((dst), (val), (cnt))41 #define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt))42 43 40 #define bzero(ptr, len) memset((ptr), 0, (len)) 44 41 42 extern void *memset(void *, int, size_t); 43 extern void *memcpy(void *, const void *, size_t); 45 44 extern void *memmove(void *, const void *, size_t); 45 46 46 extern int bcmp(const void *, const void *, size_t); 47 47 -
uspace/lib/posix/include/posix/string.h
r582f4d28 r45f7449 60 60 * forward declarations ought to be enough. 61 61 */ 62 63 62 /* From str.h. */ 64 65 extern char *strtok_r(char *, const char *, char **); 66 extern char *strtok(char *, const char *); 63 extern char * strtok_r(char *, const char *, char **); 64 extern char * strtok(char *, const char *); 67 65 68 66 /* From mem.h */ 67 #define bzero(ptr, len) memset((ptr), 0, (len)) 68 extern void *memset(void *, int, size_t); 69 extern void *memcpy(void *, const void *, size_t); 70 extern void *memmove(void *, const void *, size_t); 69 71 70 #define memset(dst, val, cnt) __builtin_memset((dst), (val), (cnt))71 #define memcpy(dst, src, cnt) __builtin_memcpy((dst), (src), (cnt))72 73 #define bzero(ptr, len) memset((ptr), 0, (len))74 75 extern void *memmove(void *, const void *, size_t);76 extern int bcmp(const void *, const void *, size_t);77 72 78 73 /* Copying and Concatenation */
Note:
See TracChangeset
for help on using the changeset viewer.