mirror of
https://github.com/fluencelabs/musl
synced 2025-06-21 18:51:52 +00:00
initial check-in, version 0.5.0
This commit is contained in:
21
src/string/memset.c
Normal file
21
src/string/memset.c
Normal file
@ -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;
|
||||
}
|
Reference in New Issue
Block a user