diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-02-12 00:22:29 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-02-12 00:22:29 -0500 |
commit | 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 (patch) | |
tree | 6eaef0d8a720fa3da580de87b647fff796fe80b3 /src/string/memset.c | |
download | musl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.tar.gz musl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.tar.bz2 musl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.tar.xz musl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.zip |
initial check-in, version 0.5.0v0.5.0
Diffstat (limited to 'src/string/memset.c')
-rw-r--r-- | src/string/memset.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/string/memset.c b/src/string/memset.c new file mode 100644 index 00000000..20e47c45 --- /dev/null +++ b/src/string/memset.c @@ -0,0 +1,21 @@ +#include <string.h> +#include <stdlib.h> +#include <stdint.h> +#include <limits.h> + +#define SS (sizeof(size_t)) +#define ALIGN (sizeof(size_t)-1) +#define ONES ((size_t)-1/UCHAR_MAX) + +void *memset(void *dest, int c, size_t n) +{ + unsigned char *s = dest; + c = (unsigned char)c; + for (; ((uintptr_t)s & ALIGN) && n; n--) *s++ = c; + if (n) { + size_t *w, k = ONES * c; + for (w = (void *)s; n>=SS; n-=SS, w++) *w = k; + for (s = (void *)w; n; n--, s++) *s = c; + } + return dest; +} |