Index: main/glib/atoi.c
===================================================================
--- main/glib/atoi.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/atoi.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -31,5 +31,13 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * Modified (removed locale) for use in Micromonitor
  */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)atoi.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
 #include <stdlib.h>
Index: main/glib/bcopy.c
===================================================================
--- main/glib/bcopy.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
+++ main/glib/bcopy.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -0,0 +1,140 @@
+/*-
+ * Copyright (c) 1990, 1993
+ *  The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)bcopy.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+
+/*
+ * sizeof(word) MUST BE A POWER OF TWO
+ * SO THAT wmask BELOW IS ALL ONES
+ */
+typedef int word;       /* "word" used for optimal copy speed */
+
+#define wsize   sizeof(word)
+#define wmask   (wsize - 1)
+
+/*
+ * Copy a block of memory, handling overlap.
+ * This is the routine that actually implements
+ * (the portable versions of) bcopy, memcpy, and memmove.
+ */
+#if defined(MEMCOPY) || defined(MEMMOVE)
+#include <string.h>
+
+void *
+#ifdef MEMCOPY
+memcpy
+#else
+memmove
+#endif
+(void *dst0, const void *src0, size_t length)
+#else
+#include <strings.h>
+
+void
+bcopy(const void *src0, void *dst0, size_t length)
+#endif
+{
+    char *dst = dst0;
+    const char *src = src0;
+    size_t t;
+
+    if(length == 0 || dst == src) {     /* nothing to do */
+        goto done;
+    }
+
+    /*
+     * Macros: loop-t-times; and loop-t-times, t>0
+     */
+#define TLOOP(s) if (t) TLOOP1(s)
+#define TLOOP1(s) do { s; } while (--t)
+
+    if((unsigned long)dst < (unsigned long)src) {
+        /*
+         * Copy forward.
+         */
+        t = (uintptr_t)src; /* only need low bits */
+        if((t | (uintptr_t)dst) & wmask) {
+            /*
+             * Try to align operands.  This cannot be done
+             * unless the low bits match.
+             */
+            if((t ^ (uintptr_t)dst) & wmask || length < wsize) {
+                t = length;
+            } else {
+                t = wsize - (t & wmask);
+            }
+            length -= t;
+            TLOOP1(*dst++ = *src++);
+        }
+        /*
+         * Copy whole words, then mop up any trailing bytes.
+         */
+        t = length / wsize;
+        TLOOP(*(word *)dst = *(word *)src; src += wsize; dst += wsize);
+        t = length & wmask;
+        TLOOP(*dst++ = *src++);
+    } else {
+        /*
+         * Copy backwards.  Otherwise essentially the same.
+         * Alignment works as before, except that it takes
+         * (t&wmask) bytes to align, not wsize-(t&wmask).
+         */
+        src += length;
+        dst += length;
+        t = (uintptr_t)src;
+        if((t | (uintptr_t)dst) & wmask) {
+            if((t ^ (uintptr_t)dst) & wmask || length <= wsize) {
+                t = length;
+            } else {
+                t &= wmask;
+            }
+            length -= t;
+            TLOOP1(*--dst = *--src);
+        }
+        t = length / wsize;
+        TLOOP(src -= wsize; dst -= wsize; *(word *)dst = *(word *)src);
+        t = length & wmask;
+        TLOOP(*--dst = *--src);
+    }
+done:
+#if defined(MEMCOPY) || defined(MEMMOVE)
+    return (dst0);
+#else
+    return;
+#endif
+}
Index: main/glib/crc16.c
===================================================================
--- main/glib/crc16.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/crc16.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -1,60 +1,89 @@
+/*
+ * Copyright 2001-2010 Georges Menie (www.menie.org)
+ * All rights reserved.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above copyright
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
+ *     * Neither the name of the University of California, Berkeley nor the
+ *       names of its contributors may be used to endorse or promote products
+ *       derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Adapted for use in Micromonitor
+ */
+
 #include "config.h"
-#include <ctype.h>
-#include "genlib.h"
-#include "stddefs.h"
 
-/* CRC-CCITT crc16 used primarily by Xmodem...
- */
-ushort xcrc16tab[] = {
-    0x0000,  0x1021,  0x2042,  0x3063,  0x4084,  0x50a5,  0x60c6,  0x70e7,
-    0x8108,  0x9129,  0xa14a,  0xb16b,  0xc18c,  0xd1ad,  0xe1ce,  0xf1ef,
-    0x1231,  0x0210,  0x3273,  0x2252,  0x52b5,  0x4294,  0x72f7,  0x62d6,
-    0x9339,  0x8318,  0xb37b,  0xa35a,  0xd3bd,  0xc39c,  0xf3ff,  0xe3de,
-    0x2462,  0x3443,  0x0420,  0x1401,  0x64e6,  0x74c7,  0x44a4,  0x5485,
-    0xa56a,  0xb54b,  0x8528,  0x9509,  0xe5ee,  0xf5cf,  0xc5ac,  0xd58d,
-    0x3653,  0x2672,  0x1611,  0x0630,  0x76d7,  0x66f6,  0x5695,  0x46b4,
-    0xb75b,  0xa77a,  0x9719,  0x8738,  0xf7df,  0xe7fe,  0xd79d,  0xc7bc,
-    0x48c4,  0x58e5,  0x6886,  0x78a7,  0x0840,  0x1861,  0x2802,  0x3823,
-    0xc9cc,  0xd9ed,  0xe98e,  0xf9af,  0x8948,  0x9969,  0xa90a,  0xb92b,
-    0x5af5,  0x4ad4,  0x7ab7,  0x6a96,  0x1a71,  0x0a50,  0x3a33,  0x2a12,
-    0xdbfd,  0xcbdc,  0xfbbf,  0xeb9e,  0x9b79,  0x8b58,  0xbb3b,  0xab1a,
-    0x6ca6,  0x7c87,  0x4ce4,  0x5cc5,  0x2c22,  0x3c03,  0x0c60,  0x1c41,
-    0xedae,  0xfd8f,  0xcdec,  0xddcd,  0xad2a,  0xbd0b,  0x8d68,  0x9d49,
-    0x7e97,  0x6eb6,  0x5ed5,  0x4ef4,  0x3e13,  0x2e32,  0x1e51,  0x0e70,
-    0xff9f,  0xefbe,  0xdfdd,  0xcffc,  0xbf1b,  0xaf3a,  0x9f59,  0x8f78,
-    0x9188,  0x81a9,  0xb1ca,  0xa1eb,  0xd10c,  0xc12d,  0xf14e,  0xe16f,
-    0x1080,  0x00a1,  0x30c2,  0x20e3,  0x5004,  0x4025,  0x7046,  0x6067,
-    0x83b9,  0x9398,  0xa3fb,  0xb3da,  0xc33d,  0xd31c,  0xe37f,  0xf35e,
-    0x02b1,  0x1290,  0x22f3,  0x32d2,  0x4235,  0x5214,  0x6277,  0x7256,
-    0xb5ea,  0xa5cb,  0x95a8,  0x8589,  0xf56e,  0xe54f,  0xd52c,  0xc50d,
-    0x34e2,  0x24c3,  0x14a0,  0x0481,  0x7466,  0x6447,  0x5424,  0x4405,
-    0xa7db,  0xb7fa,  0x8799,  0x97b8,  0xe75f,  0xf77e,  0xc71d,  0xd73c,
-    0x26d3,  0x36f2,  0x0691,  0x16b0,  0x6657,  0x7676,  0x4615,  0x5634,
-    0xd94c,  0xc96d,  0xf90e,  0xe92f,  0x99c8,  0x89e9,  0xb98a,  0xa9ab,
-    0x5844,  0x4865,  0x7806,  0x6827,  0x18c0,  0x08e1,  0x3882,  0x28a3,
-    0xcb7d,  0xdb5c,  0xeb3f,  0xfb1e,  0x8bf9,  0x9bd8,  0xabbb,  0xbb9a,
-    0x4a75,  0x5a54,  0x6a37,  0x7a16,  0x0af1,  0x1ad0,  0x2ab3,  0x3a92,
-    0xfd2e,  0xed0f,  0xdd6c,  0xcd4d,  0xbdaa,  0xad8b,  0x9de8,  0x8dc9,
-    0x7c26,  0x6c07,  0x5c64,  0x4c45,  0x3ca2,  0x2c83,  0x1ce0,  0x0cc1,
-    0xef1f,  0xff3e,  0xcf5d,  0xdf7c,  0xaf9b,  0xbfba,  0x8fd9,  0x9ff8,
-    0x6e17,  0x7e36,  0x4e55,  0x5e74,  0x2e93,  0x3eb2,  0x0ed1,  0x1ef0
+/* CRC16 implementation acording to CCITT standards */
+
+const unsigned short xcrc16tab[256]= {
+    0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
+    0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef,
+    0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6,
+    0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3de,
+    0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485,
+    0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58d,
+    0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4,
+    0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bc,
+    0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823,
+    0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92b,
+    0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12,
+    0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1a,
+    0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41,
+    0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49,
+    0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70,
+    0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78,
+    0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16f,
+    0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067,
+    0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35e,
+    0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256,
+    0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50d,
+    0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405,
+    0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73c,
+    0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634,
+    0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9ab,
+    0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3,
+    0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9a,
+    0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92,
+    0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9,
+    0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1,
+    0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8,
+    0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0
 };
 
-ushort
-xcrc16(uchar *buffer,ulong nbytes)
+unsigned short crc16_ccitt(const void *buf, int len)
 {
-    ulong   i;
-    ushort  crc;
-
-    crc = 0;
-    for(i=0; i<nbytes; i++) {
-        crc = (ushort)((crc << 8) ^ xcrc16tab[(crc>>8) ^ buffer[i]]);
+    register int counter;
+    register unsigned short crc = 0;
+    for(counter = 0; counter < len; counter++) {
+        crc = (crc<<8) ^ xcrc16tab[((crc>>8) ^ *(char *)buf++)&0x00FF];
 #ifdef WATCHDOG_ENABLED
         /* Every 256 bytes call the watchdog macro... */
-        if((nbytes & 0xff) == 0) {
+        if((counter & 0xff) == 0) {
             WATCHDOG_MACRO;
         }
 #endif
     }
-    return(crc);
+    return crc;
 }
+
+unsigned short
+xcrc16(unsigned char *buffer,unsigned long nbytes)
+{
+    return(crc16_ccitt((const void *)buffer,(int)nbytes));
+}
Index: main/glib/getglib
===================================================================
--- main/glib/getglib	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/getglib	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -1,49 +1,98 @@
+
+#####
 #
-# This is the original script I used to pull in files from the FreeBsd project:
+# Where did this code come from?
+# Some is home grown, most is straight out of freebsd untouched,
+# some freebsd is touched, and a few are from external sources
+# slightly modified...
+# Note that all files that are untouched are pulled in and assigned
+# the filename;  if they are touched, then the file is pulled in
+# with a different name (to avoid overwriting the modified file).
+
+#####
 #
-export GLIBFILES="abs.c atoi.c crc16.c crc32.c ctypetbl.c div.c getopt.c gmtime.c inrange.c lceil.c ldiv.c little_print.c memccpy.c memchr.c memcmp.c memcpy.c memset.c pollconsole.c prascii.c printmem.c smemcpy.c smemset.c sprnfloat.c strcasecmp.c strcat.c strchr.c strcmp.c strcpy.c strcspn.c strlen.c strncat.c strncmp.c strncpy.c strnlen.c strpbrk.c strrchr.c strspn.c strstr.c strtod.c strtok.c strtol.c strtoul.c strtolower.c strtoupper.c swap.c ticktock.c ulceil.c"
+# libc/string (untouched):
+# bcopy.c:
+wget -O bcopy.c https://svnweb.freebsd.org/base/head/lib/libc/string/bcopy.c?revision=251069&view=co
+# memccpy.c:
+wget -O memccpy.c https://svnweb.freebsd.org/base/head/lib/libc/string/memccpy.c?revision=251069&view=co
+# memchr.c:
+wget -O memchr.c https://svnweb.freebsd.org/base/head/lib/libc/string/memchr.c?revision=251069&view=co
+# memcmp.c:
+wget -O memcmp.chttps://svnweb.freebsd.org/base/head/lib/libc/string/memcmp.c?revision=251069&view=co
+# memcpy.c:
+wget -O memcpy.c https://svnweb.freebsd.org/base/head/lib/libc/string/memcpy.c?revision=92986&view=co
+# memset.c:
+wget -O memset.c https://svnweb.freebsd.org/base/head/lib/libc/string/memset.c?revision=251069&view=co
+# strcat.c:
+wget -O strcat.c https://svnweb.freebsd.org/base/head/lib/libc/string/strcat.c?revision=251069&view=co
+# strchr.c:
+wget -O strchr.c https://svnweb.freebsd.org/base/head/lib/libc/string/strchr.c?revision=251069&view=co
+# strcmp.c:
+wget -O strcmp.c https://svnweb.freebsd.org/base/head/lib/libc/string/strcmp.c?revision=251069&view=co
+# strcpy.c:
+wget -O strcpy.c https://svnweb.freebsd.org/base/head/lib/libc/string/strcpy.c?revision=251069&view=co
+# strlen.c:
+wget -O strlen.c https://svnweb.freebsd.org/base/head/lib/libc/string/strlen.c?revision=92889&view=co
+# strncat.c:
+wget -O strncat.c https://svnweb.freebsd.org/base/head/lib/libc/string/strncat.c?revision=251069&view=co
+# strncmp.c:
+wget -O strncmp.c https://svnweb.freebsd.org/base/head/lib/libc/string/strncmp.c?revision=251069&view=co
+# strncpy.c:
+wget -O strncpy.c https://svnweb.freebsd.org/base/head/lib/libc/string/strncpy.c?revision=251069&view=co
+# strnlen.c:
+wget -O strnlen.c https://svnweb.freebsd.org/base/head/lib/libc/string/strnlen.c?revision=189136&view=co
+# strpbrk.c:
+wget -O strpbrk.c https://svnweb.freebsd.org/base/head/lib/libc/string/strpbrk.c?revision=251069&view=co
+# strrchr.c:
+wget -O strrchr.c https://svnweb.freebsd.org/base/head/lib/libc/string/strrchr.c?revision=251069&view=co
+# strstr.c:
+wget -O strstr.c https://svnweb.freebsd.org/base/head/lib/libc/string/strstr.c?revision=251069&view=co
+# strtok.c:
+wget -O strtok.c https://svnweb.freebsd.org/base/head/lib/libc/string/strtok.c?revision=251069&view=co
 
-export MYFILES="asctime.c inrange.c memcpy.c pollconsole.c prascii.c printmem.c smemcpy.c smemset.c swap.c ticktock.c"
+#####
+#
+# libc/stdlib (untouched):
+# abs.c:
+wget -O abs.c https://svnweb.freebsd.org/base/head/lib/libc/stdlib/abs.c?revision=251069&view=co
+# ldiv.c:
+wget -O ldiv.c https://svnweb.freebsd.org/base/head/lib/libc/stdlib/ldiv.c?revision=251672&view=co
+# div.c:
+wget -O div.c https://svnweb.freebsd.org/base/head/lib/libc/stdlib/div.c?revision=251069&view=co
 
-export BSDPATH=https://raw.githubusercontent.com/freebsd/freebsd/master
+#####
+#
+# Miscellaneous functions modified, but derived from...
+# (we download them here but don't overwrite the active version)
+#
+# crc16.c:
+wget -O base_crc16.c http://www.menie.org/georges/embedded/crc16.c
+# crc32.c:
+wget https://svnweb.freebsd.org/base/stable/10/sys/libkern/crc32.c?revision=256281&view=co
+# atoi.c (removed locale):
+wget  https://svnweb.freebsd.org/base/head/lib/libc/stdlib/atoi.c?revision=251069&view=co
+# strtol.c (removed locale):
+wget https://svnweb.freebsd.org/base/head/lib/libc/stdlib/strtol.c?revision=251672&view=co
+# strtoul.c (removed locale):
+wget https://svnweb.freebsd.org/base/head/lib/libc/stdlib/strtoul.c?revision=251672&view=co
+# strcasecmp.c (removed locale):
+wget https://svnweb.freebsd.org/base/head/lib/libc/string/strcasecmp.c?revision=251069&view=co
+# getopt.c (add getoptinit()):
+wget https://svnweb.freebsd.org/base/head/lib/libc/stdlib/getopt.c?revision=267745&view=co
+# asctime.c:
+# Hand written written, based on http://pubs.opengroup.org/onlinepubs/009695399/functions/asctime.html
 
-export BSD_STRING_FILES="memccpy.c memchr.c memcmp.c memset.c strcasecmp.c strcat.c strchr.c strcmp.c strcpy.c strcspn.c strlen.c strncat.c strncmp.c strncpy.c strnlen.c strpbrk.c strrchr.c strspn.c strstr.c strtok.c"
+#####
+#
+# Homegrown (written by Ed Sutter):
+# inrange.c
+# pollconsole.c
+# prascii.c
+# printmem.c
+# smemcpy.c
+# smemset.c
+# ticktock.c
+# swap.c
+# strtolower.c
 
-export BSD_STDLIB_FILES="abs.c atoi.c div.c getopt.c ldiv.c strtol.c"
-
-rm -f *.c *.1 list
-
-for file in $MYFILES
-do
-  cp orig/$file .
-  echo "myfile: $file" >>list
-done
-
-for file in $BSD_STDLIB_FILES
-do
-  if ! [ -f $file ] 
-  then
-    wget ${BSDPATH}/lib/libc/stdlib/$file
-    if [ $? == 0 ]
-    then
-      echo "stdlib: $file" >>list
-    fi
-  fi
-done
-
-for file in $BSD_STRING_FILES
-do
-  if ! [ -f $file ] 
-  then
-    wget ${BSDPATH}/lib/libc/string/$file
-    if [ $? == 0 ]
-    then
-      echo "string: $file" >>list
-    fi
-  fi
-done
-
-wget ${BSDPATH}/contrib/tzcode/stdtime/asctime.c
-wget https://raw.githubusercontent.com/LADSoft/OrangeC/master/src/clibs/time/gmtime.c
-wget https://raw.githubusercontent.com/freebsd/freebsd-ports/master/converters/ta2as/files/strtolower.c
-wget https://raw.githubusercontent.com/freebsd/freebsd/master/sys/libkern/crc32.c
Index: main/glib/getopt.c
===================================================================
--- main/glib/getopt.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/getopt.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -1,5 +1,3 @@
 /*  $NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $ */
-#include <string.h>
-extern int printf(char *fmt,...);
 
 /*
@@ -30,5 +28,19 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * Modified for use in Micromonitor.
  */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getopt.c	8.3 (Berkeley) 4/27/95";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 
 int opterr = 1,     /* if error message should be printed */
@@ -71,5 +83,5 @@
                if the program (eg su) is looking for it. */
             place = EMSG;
-            if(strchr(ostr, '-') == 0) {
+            if(strchr(ostr, '-') == NULL) {
                 return (-1);
             }
@@ -81,11 +93,11 @@
 
     /* See if option letter is one the caller wanted... */
-    if(optopt == ':' || (oli = strchr(ostr, optopt)) == 0) {
+    if(optopt == ':' || (oli = strchr(ostr, optopt)) == NULL) {
         if(*place == 0) {
             ++optind;
         }
-        if(opterr && *ostr != ':')
-            (void)printf(
-                "illegal option -- %c\n", optopt);
+        if(opterr && *ostr != ':') {
+            (void)printf("illegal option -- %c\n", optopt);
+        }
         return (BADCH);
     }
@@ -94,5 +106,5 @@
     if(oli[1] != ':') {
         /* don't need argument */
-        optarg = 0;
+        optarg = NULL;
         if(*place == 0) {
             ++optind;
@@ -109,5 +121,5 @@
              */
         {
-            optarg = 0;
+            optarg = NULL;
         } else if(nargc > ++optind) {
             optarg = nargv[optind];
@@ -119,7 +131,6 @@
             }
             if(opterr)
-                (void)printf(
-                    "option requires an argument -- %c\n",
-                    optopt);
+                (void)printf("option requires an argument -- %c\n",
+                             optopt);
             return (BADCH);
         }
@@ -130,16 +141,11 @@
 }
 
-/* getoptinit():
- * Since getopt() can be used by every command in the monitor
- * it's variables must be reinitialized prior to each command
- * executed through docommand()...
- */
 void
 getoptinit(void)
 {
+    opterr = 1;
     optind = 1;
-    opterr = 1;
     optopt = 0;
     optreset = 0;
-    optarg = (char *)0;
+    optarg = 0;
 }
Index: main/glib/memccpy.c
===================================================================
--- main/glib/memccpy.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/memccpy.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -35,5 +35,4 @@
 
 #include <string.h>
-#include <stdlib.h>
 
 void *
Index: main/glib/memchr.c
===================================================================
--- main/glib/memchr.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/memchr.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -38,5 +38,4 @@
 
 #include <string.h>
-#include <stdlib.h>
 
 void *
Index: main/glib/memcpy.c
===================================================================
--- main/glib/memcpy.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/memcpy.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -1,108 +1,5 @@
-#include "config.h"
-#include <ctype.h>
-#include "genlib.h"
-#include "stddefs.h"
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
 
-#ifndef MEMCPY_CHUNK
-#define MEMCPY_CHUNK (256*1024)
-#endif
-
-/* memcpy():
- *  Copy n bytes from 'from' to 'to'; return 'to'.
- *  This version of memcpy() tries to take advantage of address alignment.
- *  The goal is to do as many of the copies on 4-byte aligned addresses,
- *  falling back to 2-byte alignment, and finally, if there is no other
- *  way, simple byte-by-byte copy.
- *  Note that there is some point where the amount of overhead may exceed
- *  the byte count; hence, this will take longer for small byte counts.
- *  The assumption here is that small byte count memcpy() calls don't really
- *  care.
- */
-char *
-memcpy(char *to,char *from,int count)
-{
-    char    *to_copy, *end;
-#if INCLUDE_QUICKMEMCPY
-    char    *tend;
-#endif
-
-    to_copy = to;
-
-#if INCLUDE_QUICKMEMCPY
-    /* If count is greater than 8, get fancy, else just do byte-copy... */
-    if(count > 8) {
-        /* Attempt to optimize the transfer here... */
-        if(((int)to & 3) && ((int)from & 3)) {
-            /* If from and to pointers are both unaligned to the
-             * same degree then we can do a few char copies to get them
-             * 4-byte aligned and then do a lot of 4-byte aligned copies.
-             */
-            if(((int)to & 3) == ((int)from & 3)) {
-                while((int)to & 3) {
-                    *to++ = *from++;
-                    count--;
-                }
-            }
-            /* If from and to pointers are both odd, but different, then
-             * we can increment them both by 1 and do a bunch of 2-byte
-             * aligned copies...
-             */
-            else if(((int)to & 1) && ((int)from & 1)) {
-                *to++ = *from++;
-                count--;
-            }
-        }
-
-        /* If both pointers are now 4-byte aligned or 2-byte aligned,
-         * take advantage of that here...
-         */
-        if(!((int)to & 3) && !((int)from & 3)) {
-            tend = end = to + (count & ~3);
-            count = count & 3;
-#ifdef WATCHDOG_ENABLED
-            do {
-                tend = (end - to <= MEMCPY_CHUNK) ? end : to + MEMCPY_CHUNK;
-#endif
-                while(to < tend) {
-                    *(ulong *)to = *(ulong *)from;
-                    from += 4;
-                    to += 4;
-                }
-#ifdef WATCHDOG_ENABLED
-                WATCHDOG_MACRO;
-            } while(tend != end);
-#endif
-        } else if(!((int)to & 1) && !((int)from & 1)) {
-            tend = end = to + (count & ~1);
-            count = count & 1;
-#ifdef WATCHDOG_ENABLED
-            do {
-                tend = (end - to <= MEMCPY_CHUNK) ? end : to + MEMCPY_CHUNK;
-#endif
-                while(to < tend) {
-                    *(ushort *)to = *(ushort *)from;
-                    from += 2;
-                    to += 2;
-                }
-#ifdef WATCHDOG_ENABLED
-                WATCHDOG_MACRO;
-            } while(tend != end);
-#endif
-        }
-    }
-#endif
-
-    if(count) {
-        end = to + count;
-        while(to < end) {
-            *to++ = *from++;
-        }
-    }
-    return(to_copy);
-}
-
-void
-bcopy(char *from, char *to, int size)
-{
-    memcpy(to,from,size);
-}
+#define MEMCOPY
+#include "bcopy.c"
Index: main/glib/strcasecmp.c
===================================================================
--- main/glib/strcasecmp.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/strcasecmp.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -31,15 +31,23 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * Modified (removed locale) for use in Micromonitor.
  */
 
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)strcasecmp.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <strings.h>
 #include <ctype.h>
-#include <stdlib.h>
 
 int
 strcasecmp(const char *s1, const char *s2)
 {
-    const unsigned char
-    *us1 = (const unsigned char *)s1,
-     *us2 = (const unsigned char *)s2;
+    const u_char
+    *us1 = (const u_char *)s1,
+     *us2 = (const u_char *)s2;
 
     while(tolower(*us1) == tolower(*us2++))
@@ -54,7 +62,7 @@
 {
     if(n != 0) {
-        const unsigned char
-        *us1 = (const unsigned char *)s1,
-         *us2 = (const unsigned char *)s2;
+        const u_char
+        *us1 = (const u_char *)s1,
+         *us2 = (const u_char *)s2;
 
         do {
Index: main/glib/strlen.c
===================================================================
--- main/glib/strlen.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/strlen.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -1,18 +1,51 @@
-#include "config.h"
-#include <ctype.h>
-#include "genlib.h"
-#include "stddefs.h"
+/*-
+ * Copyright (c) 1990, 1993
+ *  The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *  This product includes software developed by the University of
+ *  California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 
-/* strlen():
- * Returns the number of
- * non-NULL bytes in string argument.
- */
-int
-strlen(register char *s)
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)strlen.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <string.h>
+
+size_t
+strlen(str)
+const char *str;
 {
-    register char *s0 = s + 1;
+    const char *s;
 
-    while(*s++ != '\0')
-        ;
-    return (s - s0);
+    for(s = str; *s; ++s);
+    return(s - str);
 }
+
Index: main/glib/strncat.c
===================================================================
--- main/glib/strncat.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/strncat.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -38,5 +38,4 @@
 
 #include <string.h>
-#include <stdlib.h>
 
 /*
Index: main/glib/strncmp.c
===================================================================
--- main/glib/strncmp.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/strncmp.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -35,5 +35,4 @@
 
 #include <string.h>
-#include <stdlib.h>
 
 int
Index: main/glib/strncpy.c
===================================================================
--- main/glib/strncpy.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/strncpy.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -38,5 +38,4 @@
 
 #include <string.h>
-#include <stdlib.h>
 
 /*
Index: main/glib/strpbrk.c
===================================================================
--- main/glib/strpbrk.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/strpbrk.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -35,5 +35,4 @@
 
 #include <string.h>
-#include <stdlib.h>
 
 /*
Index: main/glib/strstr.c
===================================================================
--- main/glib/strstr.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/strstr.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -38,5 +38,4 @@
 
 #include <string.h>
-#include <stdlib.h>
 
 /*
Index: main/glib/strtol.c
===================================================================
--- main/glib/strtol.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/strtol.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -31,4 +31,6 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * Modified (removed locale) for use in Micromonitor
  */
 
@@ -41,6 +43,8 @@
 #include <limits.h>
 #include <ctype.h>
+#include <errno.h>
 #include <stdlib.h>
 
+#define HAVE_ERRNO 0
 
 /*
@@ -138,10 +142,18 @@
     if(any < 0) {
         acc = neg ? LONG_MIN : LONG_MAX;
+#if HAVE_ERRNO
+        errno = ERANGE;
+#endif
     } else if(!any) {
+#if HAVE_ERRNO
+noconv:
+        errno = EINVAL;
+#endif
     } else if(neg) {
         acc = -acc;
     }
-
+#if !HAVE_ERRNO
 noconv:
+#endif
     if(endptr != NULL) {
         *endptr = (char *)(any ? s - 1 : nptr);
Index: main/glib/strtoul.c
===================================================================
--- main/glib/strtoul.c	(revision ad2518444afe191e3d2e704790707140c57c2958)
+++ main/glib/strtoul.c	(revision 40ec7e1c159930609b06156219615059874c5b03)
@@ -31,4 +31,6 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * Modified (removed locale) for use in Micromonitor
  */
 
@@ -41,5 +43,8 @@
 #include <limits.h>
 #include <ctype.h>
+#include <errno.h>
 #include <stdlib.h>
+
+#define HAVE_ERRNO 0
 
 /*
@@ -116,9 +121,18 @@
     if(any < 0) {
         acc = ULONG_MAX;
+#if HAVE_ERRNO
+        errno = ERANGE;
+#endif
     } else if(!any) {
+#if HAVE_ERRNO
+noconv:
+        errno = EINVAL;
+#endif
     } else if(neg) {
         acc = -acc;
     }
+#if !HAVE_ERRNO
 noconv:
+#endif
     if(endptr != NULL) {
         *endptr = (char *)(any ? s - 1 : nptr);
