summaryrefslogtreecommitdiffstats
path: root/main/glib/smemset.c
diff options
context:
space:
mode:
Diffstat (limited to 'main/glib/smemset.c')
-rwxr-xr-xmain/glib/smemset.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/main/glib/smemset.c b/main/glib/smemset.c
new file mode 100755
index 0000000..9216b50
--- /dev/null
+++ b/main/glib/smemset.c
@@ -0,0 +1,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);
+}