summaryrefslogtreecommitdiffstats
path: root/main/glib/smemset.c
blob: 9216b50b196af2188463b1696a0bc4ba6762925b (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
61
62
63
64
65
66
67
68
69
70
71
#include "config.h"
#include <ctype.h>
#include "genlib.h"
#include "stddefs.h"

/* s_memset():
 *	Superset of memset() (used to be tfsmemset()).
 *  Includes verbose option, test to make sure the destination is not
 *	within MicroMonitor's own space, plus verification after set.
 */
int
s_memset(uchar *to,uchar val,int count,int verbose,int verifyonly)
{
	int		failed;
	uchar	*end;

	failed = 0;

#ifndef MONAPP
	if (inUmonBssSpace((char *)to,(char *)to+count))
		return(-1);
#endif

	if (verbose) {
		printf("%s %7d bytes  at  0x%08lx to 0x%02x",
			verifyonly ? "vrfy" : "set ",count,(ulong)to,val);
	}

	if ((count == 0) || (verbose > 1))
		goto done;

	end = to+count;

	if (verifyonly) {
		while(to < end) {
#ifdef WATCHDOG_ENABLED
			if (((ulong)to & 0xff) == 0)
				WATCHDOG_MACRO;
#endif
			if (*to++ != val) {
				failed = 1;
				break;
			}
		}
	}
	else {
		while(to < end) {
#ifdef WATCHDOG_ENABLED
			if (((ulong)to & 0xff) == 0)
				WATCHDOG_MACRO;
#endif
			*to = val;
			if (*to++ != val) {
				failed = 1;
				break;
			}
		}
	}
done:
	if (verbose) {
		if (failed)
			printf(" failed");
		else if (verifyonly)
			printf(" OK");
		printf("\n");
	}
	if (failed)
		return(-1);
	else
		return(0);
}