From 40ec7e1c159930609b06156219615059874c5b03 Mon Sep 17 00:00:00 2001 From: Ed Sutter Date: Wed, 5 Aug 2015 20:42:07 -0400 Subject: update to glib with clean indication of where the files (that I didn't create) came from --- main/glib/atoi.c | 8 +++ main/glib/bcopy.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++ main/glib/crc16.c | 125 ++++++++++++++++++++++++++----------------- main/glib/getglib | 135 ++++++++++++++++++++++++++++++++--------------- main/glib/getopt.c | 44 +++++++++------- main/glib/memccpy.c | 1 - main/glib/memchr.c | 1 - main/glib/memcpy.c | 111 ++------------------------------------- main/glib/strcasecmp.c | 22 +++++--- main/glib/strlen.c | 61 ++++++++++++++++----- main/glib/strncat.c | 1 - main/glib/strncmp.c | 1 - main/glib/strncpy.c | 1 - main/glib/strpbrk.c | 1 - main/glib/strstr.c | 1 - main/glib/strtol.c | 14 ++++- main/glib/strtoul.c | 14 +++++ 17 files changed, 435 insertions(+), 246 deletions(-) create mode 100644 main/glib/bcopy.c diff --git a/main/glib/atoi.c b/main/glib/atoi.c index d3ecc0a..9588539 100644 --- a/main/glib/atoi.c +++ b/main/glib/atoi.c @@ -30,8 +30,16 @@ * 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. + * + * 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 +__FBSDID("$FreeBSD$"); + #include int diff --git a/main/glib/bcopy.c b/main/glib/bcopy.c new file mode 100644 index 0000000..98b5332 --- /dev/null +++ b/main/glib/bcopy.c @@ -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 +__FBSDID("$FreeBSD$"); + +#include + +/* + * 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 + +void * +#ifdef MEMCOPY +memcpy +#else +memmove +#endif +(void *dst0, const void *src0, size_t length) +#else +#include + +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 +} diff --git a/main/glib/crc16.c b/main/glib/crc16.c index cf708c7..2aafe38 100644 --- a/main/glib/crc16.c +++ b/main/glib/crc16.c @@ -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 -#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>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)); } diff --git a/main/glib/getglib b/main/glib/getglib index 4c963b2..e9295fb 100644 --- a/main/glib/getglib +++ b/main/glib/getglib @@ -1,49 +1,98 @@ -# -# This is the original script I used to pull in files from the FreeBsd project: -# -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" - -export MYFILES="asctime.c inrange.c memcpy.c pollconsole.c prascii.c printmem.c smemcpy.c smemset.c swap.c ticktock.c" -export BSDPATH=https://raw.githubusercontent.com/freebsd/freebsd/master - -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" - -export BSD_STDLIB_FILES="abs.c atoi.c div.c getopt.c ldiv.c strtol.c" +##### +# +# 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). -rm -f *.c *.1 list +##### +# +# 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 -for file in $MYFILES -do - cp orig/$file . - echo "myfile: $file" >>list -done +##### +# +# 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 -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 +##### +# +# 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 -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 +##### +# +# Homegrown (written by Ed Sutter): +# inrange.c +# pollconsole.c +# prascii.c +# printmem.c +# smemcpy.c +# smemset.c +# ticktock.c +# swap.c +# strtolower.c -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 diff --git a/main/glib/getopt.c b/main/glib/getopt.c index 84d695a..d6705d9 100644 --- a/main/glib/getopt.c +++ b/main/glib/getopt.c @@ -1,6 +1,4 @@ /* $NetBSD: getopt.c,v 1.29 2014/06/05 22:00:22 christos Exp $ */ -#include -extern int printf(char *fmt,...); /* * Copyright (c) 1987, 1993, 1994 @@ -29,8 +27,22 @@ extern int printf(char *fmt,...); * 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. + * + * 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + + int opterr = 1, /* if error message should be printed */ optind = 1, /* index into parent argv vector */ optopt, /* character checked for validity */ @@ -70,7 +82,7 @@ getopt(int nargc, char *const nargv[], const char *ostr) /* Solitary '-', treat as a '-' option if the program (eg su) is looking for it. */ place = EMSG; - if(strchr(ostr, '-') == 0) { + if(strchr(ostr, '-') == NULL) { return (-1); } optopt = '-'; @@ -80,20 +92,20 @@ getopt(int nargc, char *const nargv[], const char *ostr) } /* 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); } /* Does this option need an argument? */ if(oli[1] != ':') { /* don't need argument */ - optarg = 0; + optarg = NULL; if(*place == 0) { ++optind; } @@ -108,7 +120,7 @@ getopt(int nargc, char *const nargv[], const char *ostr) * the argument is empty, we return NULL */ { - optarg = 0; + optarg = NULL; } else if(nargc > ++optind) { optarg = nargv[optind]; } else { @@ -118,9 +130,8 @@ getopt(int nargc, char *const nargv[], const char *ostr) return (BADARG); } if(opterr) - (void)printf( - "option requires an argument -- %c\n", - optopt); + (void)printf("option requires an argument -- %c\n", + optopt); return (BADCH); } place = EMSG; @@ -129,17 +140,12 @@ getopt(int nargc, char *const nargv[], const char *ostr) return (optopt); /* return option letter */ } -/* 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) { - optind = 1; opterr = 1; + optind = 1; optopt = 0; optreset = 0; - optarg = (char *)0; + optarg = 0; } diff --git a/main/glib/memccpy.c b/main/glib/memccpy.c index d98dc3c..027a0e6 100644 --- a/main/glib/memccpy.c +++ b/main/glib/memccpy.c @@ -34,7 +34,6 @@ static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD$"); #include -#include void * memccpy(void *t, const void *f, int c, size_t n) diff --git a/main/glib/memchr.c b/main/glib/memchr.c index ded3450..41ecd3e 100644 --- a/main/glib/memchr.c +++ b/main/glib/memchr.c @@ -37,7 +37,6 @@ static char sccsid[] = "@(#)memchr.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD$"); #include -#include void * memchr(const void *s, int c, size_t n) diff --git a/main/glib/memcpy.c b/main/glib/memcpy.c index 633a63f..7682bf5 100644 --- a/main/glib/memcpy.c +++ b/main/glib/memcpy.c @@ -1,108 +1,5 @@ -#include "config.h" -#include -#include "genlib.h" -#include "stddefs.h" +#include +__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" diff --git a/main/glib/strcasecmp.c b/main/glib/strcasecmp.c index f149158..5b5393f 100644 --- a/main/glib/strcasecmp.c +++ b/main/glib/strcasecmp.c @@ -30,17 +30,25 @@ * 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. + * + * 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 +__FBSDID("$FreeBSD$"); + +#include #include -#include 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++)) if(*us1++ == '\0') { @@ -53,9 +61,9 @@ int strncasecmp(const char *s1, const char *s2, size_t n) { 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 { if(tolower(*us1) != tolower(*us2++)) { diff --git a/main/glib/strlen.c b/main/glib/strlen.c index 5a01a15..54c28fc 100644 --- a/main/glib/strlen.c +++ b/main/glib/strlen.c @@ -1,18 +1,51 @@ -#include "config.h" -#include -#include "genlib.h" -#include "stddefs.h" - -/* strlen(): - * Returns the number of - * non-NULL bytes in string argument. +/*- + * 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. */ -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 +__FBSDID("$FreeBSD$"); + +#include + +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); } + diff --git a/main/glib/strncat.c b/main/glib/strncat.c index c6d6eb4..e94f20a 100644 --- a/main/glib/strncat.c +++ b/main/glib/strncat.c @@ -37,7 +37,6 @@ static char sccsid[] = "@(#)strncat.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD$"); #include -#include /* * Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes diff --git a/main/glib/strncmp.c b/main/glib/strncmp.c index eca1520..5736f24 100644 --- a/main/glib/strncmp.c +++ b/main/glib/strncmp.c @@ -34,7 +34,6 @@ static char sccsid[] = "@(#)strncmp.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD$"); #include -#include int strncmp(const char *s1, const char *s2, size_t n) diff --git a/main/glib/strncpy.c b/main/glib/strncpy.c index 3eabc1a..5975470 100644 --- a/main/glib/strncpy.c +++ b/main/glib/strncpy.c @@ -37,7 +37,6 @@ static char sccsid[] = "@(#)strncpy.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD$"); #include -#include /* * Copy src to dst, truncating or null-padding to always copy n bytes. diff --git a/main/glib/strpbrk.c b/main/glib/strpbrk.c index d1518d7..1fed7b2 100644 --- a/main/glib/strpbrk.c +++ b/main/glib/strpbrk.c @@ -34,7 +34,6 @@ static char sccsid[] = "@(#)strpbrk.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD$"); #include -#include /* * Find the first occurrence in s1 of a character in s2 (excluding NUL). diff --git a/main/glib/strstr.c b/main/glib/strstr.c index cd3922f..0d586ee 100644 --- a/main/glib/strstr.c +++ b/main/glib/strstr.c @@ -37,7 +37,6 @@ static char sccsid[] = "@(#)strstr.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD$"); #include -#include /* * Find the first occurrence of find in s. diff --git a/main/glib/strtol.c b/main/glib/strtol.c index ce18845..1890c5a 100644 --- a/main/glib/strtol.c +++ b/main/glib/strtol.c @@ -30,6 +30,8 @@ * 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. + * + * Modified (removed locale) for use in Micromonitor */ #if defined(LIBC_SCCS) && !defined(lint) @@ -40,8 +42,10 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include +#define HAVE_ERRNO 0 /* * Convert a string to a long integer. @@ -137,12 +141,20 @@ strtol(const char *__restrict nptr, char **__restrict endptr, int base) } 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); } diff --git a/main/glib/strtoul.c b/main/glib/strtoul.c index 7ca41b6..61b37d7 100644 --- a/main/glib/strtoul.c +++ b/main/glib/strtoul.c @@ -30,6 +30,8 @@ * 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. + * + * Modified (removed locale) for use in Micromonitor */ #if defined(LIBC_SCCS) && !defined(lint) @@ -40,8 +42,11 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include +#define HAVE_ERRNO 0 + /* * Convert a string to an unsigned long integer. * @@ -115,11 +120,20 @@ strtoul(const char *__restrict nptr, char **__restrict endptr, int base) } 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); } -- cgit v1.2.3