aboutsummaryrefslogtreecommitdiffstats
path: root/mempsetelem.c
blob: c8990ede4335cdcca3eef8e634027bdaaebfb2ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* See LICENSE file for copyright and license details. */
#include "libsimple.h"
#ifndef TEST


void *
libsimple_mempsetelem(void *buf_, const void *item, size_t size, size_t nitems) /* TODO test */
{
	switch (size) {
	case 0:
		return buf_;
	case 1:
		return &((char *)memset(buf_, *(char *)item, nitems))[nitems];
	case 2:
		{
			uint16_t *buf = buf_, e = *(uint16_t *)item;
			uint16_t *end = &buf[nitems];
			for (; buf != end; buf++)
				*buf = e;
			return buf;
		}
	case 4:
		{
			uint32_t *buf = buf_, e = *(uint32_t *)item;
			uint32_t *end = &buf[nitems];
			for (; buf != end; buf++)
				*buf = e;
			return buf;
		}
	case 8:
		{
			uint64_t *buf = buf_, e = *(uint64_t *)item;
			uint64_t *end = &buf[nitems];
			for (; buf != end; buf++)
				*buf = e;
			return buf;
		}
	default:
		{
			char *buf = buf_;
			size_t i;
			for (; nitems--; buf += size)
				for (i = 0; i < size; i++)
					buf[i] = ((const char *)item)[i];
			return buf;
		}
	}
}


#else
#include "test.h"

int
main(void)
{
	return 0;
}

#endif