You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2015/11/24 01:54:47 UTC

[2/5] incubator-mynewt-larva git commit: BaseLibc as an egg.

BaseLibc as an egg.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/b32abb57
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/b32abb57
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/b32abb57

Branch: refs/heads/master
Commit: b32abb577f9de23d7018132958a3341f4ca2c5f1
Parents: 9601758
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Mon Nov 23 14:45:37 2015 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 23 14:45:37 2015 -0800

----------------------------------------------------------------------
 libs/baselibc/LICENSE                         | 133 +++++++
 libs/baselibc/Makefile                        |  46 +++
 libs/baselibc/README.md                       |   6 +
 libs/baselibc/egg.yml                         |   6 +
 libs/baselibc/include/assert.h                |  26 ++
 libs/baselibc/include/ctype.h                 |  86 +++++
 libs/baselibc/include/inttypes.h              | 226 ++++++++++++
 libs/baselibc/include/klibc/extern.h          |  16 +
 libs/baselibc/include/klibc/inline.h          |  12 +
 libs/baselibc/include/stdio.h                 | 124 +++++++
 libs/baselibc/include/stdlib.h                |  98 +++++
 libs/baselibc/include/string.h                |  59 +++
 libs/baselibc/src/asprintf.c                  |  30 ++
 libs/baselibc/src/atoi.c                      |   3 +
 libs/baselibc/src/atol.c                      |   3 +
 libs/baselibc/src/atoll.c                     |   3 +
 libs/baselibc/src/bsearch.c                   |  26 ++
 libs/baselibc/src/bzero.c                     |   6 +
 libs/baselibc/src/calloc.c                    |  20 ++
 libs/baselibc/src/fgets.c                     |  31 ++
 libs/baselibc/src/inline.c                    |   5 +
 libs/baselibc/src/jrand48.c                   |  24 ++
 libs/baselibc/src/lrand48.c                   |  13 +
 libs/baselibc/src/malloc.c                    | 274 ++++++++++++++
 libs/baselibc/src/malloc.h                    |  43 +++
 libs/baselibc/src/memccpy.c                   |  23 ++
 libs/baselibc/src/memchr.c                    |  19 +
 libs/baselibc/src/memcmp.c                    |  19 +
 libs/baselibc/src/memcpy.c                    |  29 ++
 libs/baselibc/src/memfile.c                   |  33 ++
 libs/baselibc/src/memmem.c                    |  52 +++
 libs/baselibc/src/memmove.c                   |  36 ++
 libs/baselibc/src/memrchr.c                   |  19 +
 libs/baselibc/src/memset.c                    |  30 ++
 libs/baselibc/src/memswap.c                   |  24 ++
 libs/baselibc/src/mrand48.c                   |  13 +
 libs/baselibc/src/mynewt.c                    |  44 +++
 libs/baselibc/src/nrand48.c                   |  11 +
 libs/baselibc/src/qsort.c                     |  46 +++
 libs/baselibc/src/realloc.c                   |  48 +++
 libs/baselibc/src/sprintf.c                   |  18 +
 libs/baselibc/src/srand48.c                   |  15 +
 libs/baselibc/src/sscanf.c                    |  17 +
 libs/baselibc/src/strcasecmp.c                |  24 ++
 libs/baselibc/src/strcat.c                    |  11 +
 libs/baselibc/src/strchr.c                    |  17 +
 libs/baselibc/src/strcmp.c                    |  21 ++
 libs/baselibc/src/strcpy.c                    |  20 ++
 libs/baselibc/src/strcspn.c                   |  51 +++
 libs/baselibc/src/strdup.c                    |  17 +
 libs/baselibc/src/strlcat.c                   |  30 ++
 libs/baselibc/src/strlcpy.c                   |  26 ++
 libs/baselibc/src/strlen.c                    |  13 +
 libs/baselibc/src/strncasecmp.c               |  24 ++
 libs/baselibc/src/strncat.c                   |  21 ++
 libs/baselibc/src/strncmp.c                   |  21 ++
 libs/baselibc/src/strncpy.c                   |  24 ++
 libs/baselibc/src/strndup.c                   |  19 +
 libs/baselibc/src/strnlen.c                   |  18 +
 libs/baselibc/src/strntoimax.c                |  13 +
 libs/baselibc/src/strntoumax.c                |  77 ++++
 libs/baselibc/src/strpbrk.c                   |  55 +++
 libs/baselibc/src/strrchr.c                   |  19 +
 libs/baselibc/src/strsep.c                    |  21 ++
 libs/baselibc/src/strspn.c                    |  56 +++
 libs/baselibc/src/strstr.c                    |  11 +
 libs/baselibc/src/strtoimax.c                 |   3 +
 libs/baselibc/src/strtok.c                    |  12 +
 libs/baselibc/src/strtok_r.c                  |  13 +
 libs/baselibc/src/strtol.c                    |   3 +
 libs/baselibc/src/strtoll.c                   |   3 +
 libs/baselibc/src/strtoul.c                   |   3 +
 libs/baselibc/src/strtoull.c                  |   3 +
 libs/baselibc/src/strtoumax.c                 |   3 +
 libs/baselibc/src/templates/atox.c.template   |  14 +
 libs/baselibc/src/templates/strtox.c.template |  14 +
 libs/baselibc/src/test/printf_tests.c         |  22 ++
 libs/baselibc/src/test/tests_glue.c           |  33 ++
 libs/baselibc/src/test/unittests.h            |  14 +
 libs/baselibc/src/tinyprintf.c                | 371 +++++++++++++++++++
 libs/baselibc/src/vasprintf.c                 |  25 ++
 libs/baselibc/src/vprintf.c                   |  11 +
 libs/baselibc/src/vsprintf.c                  |  11 +
 libs/baselibc/src/vsscanf.c                   | 400 +++++++++++++++++++++
 84 files changed, 3382 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/LICENSE
----------------------------------------------------------------------
diff --git a/libs/baselibc/LICENSE b/libs/baselibc/LICENSE
new file mode 100644
index 0000000..b791574
--- /dev/null
+++ b/libs/baselibc/LICENSE
@@ -0,0 +1,133 @@
+Baselibc is based on klibc 1.5.23 and tinyprintf modules.
+None of the GPL-licensed parts of klibc are used.
+
+Baselibc is licensed under the BSD license:
+
+Copyright (c) 2012 Petteri Aimonen <jpa at blc.mail.kapsi.fi>
+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 Kustaa Nyholm or SpareTimeLabs 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+
+The original licenses of the modules are included below:
+
+------------------ Tinyprintf license ------------------
+
+Copyright (c) 2004,2012 Kustaa Nyholm / SpareTimeLabs
+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 Kustaa Nyholm or SpareTimeLabs 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+
+------------------- klibc license -------------------------
+This license applies to all files in directory and its subdirectories,
+unless otherwise noted in individual files.
+
+
+Some files are derived from files derived from the include/ directory
+of the Linux kernel, and are licensed under the terms of the GNU
+General Public License, version 2, as released by the Free Software
+Foundation, Inc.; incorporated herein by reference.
+[These files are not included in the baselibc.]
+
+                                -----
+
+Some files are derived from files copyrighted by the Regents of The
+University of California, and are available under the following
+license:
+
+Note: The advertising clause in the license appearing on BSD Unix
+files was officially rescinded by the Director of the Office of
+Technology Licensing of the University of California on July 22
+1999. He states that clause 3 is "hereby deleted in its entirety."
+
+ * Copyright (c)
+ *      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.
+
+For all remaining files [of klibc], the following license applies:
+
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * Any copyright notice(s) and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/Makefile
----------------------------------------------------------------------
diff --git a/libs/baselibc/Makefile b/libs/baselibc/Makefile
new file mode 100644
index 0000000..88c8987
--- /dev/null
+++ b/libs/baselibc/Makefile
@@ -0,0 +1,46 @@
+# You can override the CFLAGS and C compiler externally,
+# e.g. make PLATFORM=cortex-m3
+CFLAGS += -g -Wall -Werror -I include
+
+ifeq ($(PLATFORM),cortex-m3)
+  CC      = arm-none-eabi-gcc
+  AR      = arm-none-eabi-ar
+  CFLAGS += -mcpu=cortex-m3 -mthumb
+  CFLAGS += -fno-common -Os
+  CFLAGS += -ffunction-sections -fdata-sections
+endif
+
+# With this, the makefile should work on Windows also.
+ifdef windir
+  RM = del
+endif
+
+# Just include all the source files in the build.
+CSRC = $(wildcard src/*.c)
+OBJS = $(CSRC:.c=.o)
+
+# And the files for the test suite
+TESTS_CSRC = $(wildcard tests/*_tests.c)
+TESTS_OBJS = $(TESTS_CSRC:.c=)
+
+# Some of the files uses "templates", i.e. common pieces
+# of code included from multiple files.
+CFLAGS += -Isrc/templates
+
+all: libc.a
+
+clean:
+	$(RM) $(OBJS) $(TESTS_OBJS) libc.a
+
+libc.a: $(OBJS)
+	$(RM) $@
+	$(AR) ru $@ $^
+
+run_tests: $(TESTS_OBJS)
+	$(foreach f,$^,$f)
+
+tests/%: tests/%.c tests/tests_glue.c libc.a
+	$(CC) $(CFLAGS) -o $@ $^
+
+%.o: %.c
+	$(CC) $(CFLAGS) -c -o $@ $<

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/README.md
----------------------------------------------------------------------
diff --git a/libs/baselibc/README.md b/libs/baselibc/README.md
new file mode 100644
index 0000000..f7e9e49
--- /dev/null
+++ b/libs/baselibc/README.md
@@ -0,0 +1,6 @@
+Baselibc
+========
+This is a very simple libc for embedded systems. Mainly geared for 32-bit microcontrollers in the 10-100kB memory range.
+The library compiles to less than 5kB total on Cortex-M3, and much less if some functions aren't used.
+
+The code is based on klibc and tinyprintf modules, and licensed under the BSD license.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/egg.yml
----------------------------------------------------------------------
diff --git a/libs/baselibc/egg.yml b/libs/baselibc/egg.yml
new file mode 100644
index 0000000..fc8063c
--- /dev/null
+++ b/libs/baselibc/egg.yml
@@ -0,0 +1,6 @@
+egg.name: libs/baselibc
+egg.vers: 0.1
+egg.req_caps:
+    - console
+egg.identities:
+    - LIBC

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/include/assert.h
----------------------------------------------------------------------
diff --git a/libs/baselibc/include/assert.h b/libs/baselibc/include/assert.h
new file mode 100644
index 0000000..6177190
--- /dev/null
+++ b/libs/baselibc/include/assert.h
@@ -0,0 +1,26 @@
+/*
+ * assert.h
+ */
+
+#ifndef _ASSERT_H
+#define _ASSERT_H
+
+#ifdef NDEBUG
+
+/*
+ * NDEBUG doesn't just suppress the faulting behavior of assert(),
+ * but also all side effects of the assert() argument.  This behavior
+ * is required by the C standard, and allows the argument to reference
+ * variables that are not defined without NDEBUG.
+ */
+#define assert(x) ((void)(0))
+
+#else
+
+extern void __assert_func(const char *, unsigned int, const char *, const char *);
+
+#define assert(x) ((x) ? (void)0 : __assert_func(__FILE__, __LINE__, NULL, NULL))
+
+#endif
+
+#endif				/* _ASSERT_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/include/ctype.h
----------------------------------------------------------------------
diff --git a/libs/baselibc/include/ctype.h b/libs/baselibc/include/ctype.h
new file mode 100644
index 0000000..4670b6a
--- /dev/null
+++ b/libs/baselibc/include/ctype.h
@@ -0,0 +1,86 @@
+/*
+ * ctype.h
+ *
+ * This assumes ASCII.
+ */
+
+#ifndef _CTYPE_H
+#define _CTYPE_H
+
+#include <klibc/extern.h>
+#include <klibc/inline.h>
+
+__extern_inline int isupper(int __c)
+{
+	return __c >= 'A' && __c <= 'Z';
+}
+
+__extern_inline int islower(int __c)
+{
+	return __c >= 'a' && __c <= 'z';
+}
+
+__extern_inline int isalpha(int __c)
+{
+	return islower(__c) || isupper(__c);
+}
+
+__extern_inline int isdigit(int __c)
+{
+	return ((unsigned)__c - '0') <= 9;
+}
+
+__extern_inline int isalnum(int __c)
+{
+	return isalpha(__c) || isdigit(__c);
+}
+
+__extern_inline int isascii(int __c)
+{
+	return !(__c & ~0x7f);
+}
+
+__extern_inline int isblank(int __c)
+{
+	return (__c == '\t') || (__c == ' ');
+}
+
+__extern_inline int iscntrl(int __c)
+{
+	return __c < 0x20;
+}
+
+__extern_inline int isspace(int __c)
+{
+	return __c == ' ' || __c == '\n' || __c == '\t' || __c == '\r';
+}
+
+__extern_inline int isxdigit(int __c)
+{
+	return isdigit(__c) || (__c >= 'a' && __c <= 'f') || (__c >= 'A' && __c <= 'F');
+}
+
+__extern_inline int ispunct(int __c)
+{
+	return (__c >= '!' && __c <= '/') ||
+	    (__c >= ':' && __c <= '@') ||
+	    (__c >= '[' && __c <= '`') ||
+	    (__c >= '{' && __c <= '~');
+}
+
+__extern_inline int isprint(int __c)
+{
+	return (__c >= 0x20 && __c <= 0x7e);
+}
+
+__extern_inline int toupper(int __c)
+{
+	return islower(__c) ? (__c & ~32) : __c;
+}
+
+__extern_inline int tolower(int __c)
+{
+	return isupper(__c) ? (__c | 32) : __c;
+}
+
+#endif				/* _CTYPE_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/include/inttypes.h
----------------------------------------------------------------------
diff --git a/libs/baselibc/include/inttypes.h b/libs/baselibc/include/inttypes.h
new file mode 100644
index 0000000..29311fe
--- /dev/null
+++ b/libs/baselibc/include/inttypes.h
@@ -0,0 +1,226 @@
+/*
+ * inttypes.h
+ */
+
+#ifndef _INTTYPES_H
+#define _INTTYPES_H
+
+#include <klibc/extern.h>
+#include <stdint.h>
+#include <stddef.h>
+
+static __inline__ intmax_t imaxabs(intmax_t __n)
+{
+	return (__n < (intmax_t) 0) ? -__n : __n;
+}
+
+__extern intmax_t strtoimax(const char *, char **, int);
+__extern uintmax_t strtoumax(const char *, char **, int);
+
+/* extensions */
+__extern intmax_t strntoimax(const char *, char **, int, size_t);
+__extern uintmax_t strntoumax(const char *, char **, int, size_t);
+
+#if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS)
+
+#define PRId8	"d"
+#define PRId16	"d"
+#define PRId32	"d"
+#define PRId64	__PRI64_RANK "d"
+
+#define PRIdLEAST8	"d"
+#define PRIdLEAST16	"d"
+#define PRIdLEAST32	"d"
+#define PRIdLEAST64	__PRI64_RANK "d"
+
+#define PRIdFAST8	"d"
+#define PRIdFAST16	__PRIFAST_RANK "d"
+#define PRIdFAST32	__PRIFAST_RANK "d"
+#define PRIdFAST64	__PRI64_RANK "d"
+
+#define PRIdMAX	 __PRI64_RANK "d"
+#define PRIdPTR  __PRIPTR_RANK "d"
+
+#define PRIi8	"i"
+#define PRIi16	"i"
+#define PRIi32	"i"
+#define PRIi64	__PRI64_RANK "i"
+
+#define PRIiLEAST8	"i"
+#define PRIiLEAST16	"i"
+#define PRIiLEAST32	"i"
+#define PRIiLEAST64	__PRI64_RANK "i"
+
+#define PRIiFAST8	"i"
+#define PRIiFAST16	__PRIFAST_RANK "i"
+#define PRIiFAST32	__PRIFAST_RANK "i"
+#define PRIiFAST64	__PRI64_RANK "i"
+
+#define PRIiMAX	 __PRI64_RANK "i"
+#define PRIiPTR  __PRIPTR_RANK "i"
+
+#define PRIo8	"o"
+#define PRIo16	"o"
+#define PRIo32	"o"
+#define PRIo64	__PRI64_RANK "o"
+
+#define PRIoLEAST8	"o"
+#define PRIoLEAST16	"o"
+#define PRIoLEAST32	"o"
+#define PRIoLEAST64	__PRI64_RANK "o"
+
+#define PRIoFAST8	"o"
+#define PRIoFAST16	__PRIFAST_RANK "o"
+#define PRIoFAST32	__PRIFAST_RANK "o"
+#define PRIoFAST64	__PRI64_RANK "o"
+
+#define PRIoMAX	 __PRI64_RANK "o"
+#define PRIoPTR  __PRIPTR_RANK "o"
+
+#define PRIu8	"u"
+#define PRIu16	"u"
+#define PRIu32	"u"
+#define PRIu64	__PRI64_RANK "u"
+
+#define PRIuLEAST8	"u"
+#define PRIuLEAST16	"u"
+#define PRIuLEAST32	"u"
+#define PRIuLEAST64	__PRI64_RANK "u"
+
+#define PRIuFAST8	"u"
+#define PRIuFAST16	__PRIFAST_RANK "u"
+#define PRIuFAST32	__PRIFAST_RANK "u"
+#define PRIuFAST64	__PRI64_RANK "u"
+
+#define PRIuMAX	 __PRI64_RANK "u"
+#define PRIuPTR  __PRIPTR_RANK "u"
+
+#define PRIx8	"x"
+#define PRIx16	"x"
+#define PRIx32	"x"
+#define PRIx64	__PRI64_RANK "x"
+
+#define PRIxLEAST8	"x"
+#define PRIxLEAST16	"x"
+#define PRIxLEAST32	"x"
+#define PRIxLEAST64	__PRI64_RANK "x"
+
+#define PRIxFAST8	"x"
+#define PRIxFAST16	__PRIFAST_RANK "x"
+#define PRIxFAST32	__PRIFAST_RANK "x"
+#define PRIxFAST64	__PRI64_RANK "x"
+
+#define PRIxMAX	 __PRI64_RANK "x"
+#define PRIxPTR  __PRIPTR_RANK "x"
+
+#define PRIX8	"X"
+#define PRIX16	"X"
+#define PRIX32	"X"
+#define PRIX64	__PRI64_RANK "X"
+
+#define PRIXLEAST8	"X"
+#define PRIXLEAST16	"X"
+#define PRIXLEAST32	"X"
+#define PRIXLEAST64	__PRI64_RANK "X"
+
+#define PRIXFAST8	"X"
+#define PRIXFAST16	__PRIFAST_RANK "X"
+#define PRIXFAST32	__PRIFAST_RANK "X"
+#define PRIXFAST64	__PRI64_RANK "X"
+
+#define PRIXMAX	 __PRI64_RANK "X"
+#define PRIXPTR  __PRIPTR_RANK "X"
+
+#define SCNd8	"hhd"
+#define SCNd16	"hd"
+#define SCNd32	"d"
+#define SCNd64	__PRI64_RANK "d"
+
+#define SCNdLEAST8	"hhd"
+#define SCNdLEAST16	"hd"
+#define SCNdLEAST32	"d"
+#define SCNdLEAST64	__PRI64_RANK "d"
+
+#define SCNdFAST8	"hhd"
+#define SCNdFAST16	__PRIFAST_RANK "d"
+#define SCNdFAST32	__PRIFAST_RANK "d"
+#define SCNdFAST64	__PRI64_RANK "d"
+
+#define SCNdMAX	 __PRI64_RANK "d"
+#define SCNdPTR  __PRIPTR_RANK "d"
+
+#define SCNi8	"hhi"
+#define SCNi16	"hi"
+#define SCNi32	"i"
+#define SCNi64	__PRI64_RANK "i"
+
+#define SCNiLEAST8	"hhi"
+#define SCNiLEAST16	"hi"
+#define SCNiLEAST32	"i"
+#define SCNiLEAST64	__PRI64_RANK "i"
+
+#define SCNiFAST8	"hhi"
+#define SCNiFAST16	__PRIFAST_RANK "i"
+#define SCNiFAST32	__PRIFAST_RANK "i"
+#define SCNiFAST64	__PRI64_RANK "i"
+
+#define SCNiMAX	 __PRI64_RANK "i"
+#define SCNiPTR  __PRIPTR_RANK "i"
+
+#define SCNo8	"hho"
+#define SCNo16	"ho"
+#define SCNo32	"o"
+#define SCNo64	__PRI64_RANK "o"
+
+#define SCNoLEAST8	"hho"
+#define SCNoLEAST16	"ho"
+#define SCNoLEAST32	"o"
+#define SCNoLEAST64	__PRI64_RANK "o"
+
+#define SCNoFAST8	"hho"
+#define SCNoFAST16	__PRIFAST_RANK "o"
+#define SCNoFAST32	__PRIFAST_RANK "o"
+#define SCNoFAST64	__PRI64_RANK "o"
+
+#define SCNoMAX	 __PRI64_RANK "o"
+#define SCNoPTR  __PRIPTR_RANK "o"
+
+#define SCNu8	"hhu"
+#define SCNu16	"hu"
+#define SCNu32	"u"
+#define SCNu64	__PRI64_RANK "u"
+
+#define SCNuLEAST8	"hhu"
+#define SCNuLEAST16	"hu"
+#define SCNuLEAST32	"u"
+#define SCNuLEAST64	__PRI64_RANK "u"
+
+#define SCNuFAST8	"hhu"
+#define SCNuFAST16	__PRIFAST_RANK "u"
+#define SCNuFAST32	__PRIFAST_RANK "u"
+#define SCNuFAST64	__PRI64_RANK "u"
+
+#define SCNuMAX	 __PRI64_RANK "u"
+#define SCNuPTR  __PRIPTR_RANK "u"
+
+#define SCNx8	"hhx"
+#define SCNx16	"hx"
+#define SCNx32	"x"
+#define SCNx64	__PRI64_RANK "x"
+
+#define SCNxLEAST8	"hhx"
+#define SCNxLEAST16	"hx"
+#define SCNxLEAST32	"x"
+#define SCNxLEAST64	__PRI64_RANK "x"
+
+#define SCNxFAST8	"hhx"
+#define SCNxFAST16	__PRIFAST_RANK "x"
+#define SCNxFAST32	__PRIFAST_RANK "x"
+#define SCNxFAST64	__PRI64_RANK "x"
+
+#define SCNxMAX	 __PRI64_RANK "x"
+#define SCNxPTR  __PRIPTR_RANK "x"
+
+#endif
+
+#endif				/* _INTTYPES_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/include/klibc/extern.h
----------------------------------------------------------------------
diff --git a/libs/baselibc/include/klibc/extern.h b/libs/baselibc/include/klibc/extern.h
new file mode 100644
index 0000000..7d7c7b8
--- /dev/null
+++ b/libs/baselibc/include/klibc/extern.h
@@ -0,0 +1,16 @@
+/*
+ * klibc/extern.h
+ */
+
+#ifndef _KLIBC_EXTERN_H
+#define _KLIBC_EXTERN_H
+
+#ifdef __cplusplus
+#define __extern extern "C"
+#else
+#define __extern extern
+#endif
+
+#define __alias(x) __attribute__((weak, alias(x)))
+
+#endif				/* _KLIBC_EXTERN_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/include/klibc/inline.h
----------------------------------------------------------------------
diff --git a/libs/baselibc/include/klibc/inline.h b/libs/baselibc/include/klibc/inline.h
new file mode 100644
index 0000000..0e54743
--- /dev/null
+++ b/libs/baselibc/include/klibc/inline.h
@@ -0,0 +1,12 @@
+/*
+ * klibc/inline.h
+ */
+
+#ifndef _KLIBC_INLINE_H
+#define _KLIBC_INLINE_H
+
+#ifndef __extern_inline
+#define __extern_inline extern inline __attribute__((gnu_inline))
+#endif
+
+#endif				/* _KLIBC_INLINE_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/include/stdio.h
----------------------------------------------------------------------
diff --git a/libs/baselibc/include/stdio.h b/libs/baselibc/include/stdio.h
new file mode 100644
index 0000000..3f93340
--- /dev/null
+++ b/libs/baselibc/include/stdio.h
@@ -0,0 +1,124 @@
+/*
+ * stdio.h
+ */
+
+#ifndef _STDIO_H
+#define _STDIO_H
+
+#include <klibc/extern.h>
+#include <klibc/inline.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <string.h>
+
+/* The File structure is designed to be compatible with ChibiOS/RT type
+ * BaseSequentialStream.
+ */
+struct File;
+
+typedef struct File FILE;
+
+struct File_methods
+{
+    size_t (*write)(FILE* instance, const char *bp, size_t n);
+    size_t (*read)(FILE* instance, char *bp, size_t n);
+};
+
+struct File
+{
+    const struct File_methods *vmt;
+};
+
+#ifndef EOF
+# define EOF (-1)
+#endif
+
+#ifndef BUFSIZ
+# define BUFSIZ 1
+#endif
+
+/* Standard file descriptors - implement these globals yourself. */
+extern FILE* const stdin;
+extern FILE* const stdout;
+extern FILE* const stderr;
+
+/* Wrappers around stream write and read */
+__extern_inline size_t fread(void *buf, size_t size, size_t nmemb, FILE *stream)
+{
+    if (stream->vmt->read == NULL) return 0;
+    return stream->vmt->read(stream, buf, size*nmemb) / size;
+}
+
+__extern_inline size_t fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream)
+{
+    if (stream->vmt->write == NULL) return 0;
+    return stream->vmt->write(stream, buf, size*nmemb) / size;
+}
+
+__extern_inline int fputs(const char *s, FILE *f)
+{
+	return fwrite(s, 1, strlen(s), f);
+}
+
+__extern_inline int puts(const char *s)
+{
+	return fwrite(s, 1, strlen(s), stdout) + fwrite("\n", 1, 1, stdout);
+}
+
+__extern_inline int fputc(int c, FILE *f)
+{
+	unsigned char ch = c;
+	return fwrite(&ch, 1, 1, f) == 1 ? ch : EOF;
+}
+
+__extern char *fgets(char *, int, FILE *);
+__extern_inline int fgetc(FILE *f)
+{
+	unsigned char ch;
+	return fread(&ch, 1, 1, f) == 1 ? ch : EOF;
+}
+
+__extern int errno;
+__extern_inline char *strerror(int errnum)
+{
+	return "error_str";
+}
+
+#define putc(c,f)  fputc((c),(f))
+#define putchar(c) fputc((c),stdout)
+#define getc(f) fgetc(f)
+#define getchar() fgetc(stdin)
+
+__extern_inline int fflush(FILE *stream)
+{
+	return 0;
+}
+
+__extern int printf(const char *, ...);
+__extern int vprintf(const char *, va_list);
+__extern int fprintf(FILE *, const char *, ...);
+__extern int vfprintf(FILE *, const char *, va_list);
+__extern int sprintf(char *, const char *, ...);
+__extern int vsprintf(char *, const char *, va_list);
+__extern int snprintf(char *, size_t n, const char *, ...);
+__extern int vsnprintf(char *, size_t n, const char *, va_list);
+__extern int asprintf(char **, const char *, ...);
+__extern int vasprintf(char **, const char *, va_list);
+
+__extern int sscanf(const char *, const char *, ...);
+__extern int vsscanf(const char *, const char *, va_list);
+
+/* Open a memory buffer for writing.
+ Note: Does not write null terminator.*/
+struct MemFile
+{
+    struct File file;
+    char *buffer;
+    size_t bytes_written;
+    size_t size;
+};
+
+FILE *fmemopen_w(struct MemFile* storage, char *buffer, size_t size);
+
+
+#endif				/* _STDIO_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/include/stdlib.h
----------------------------------------------------------------------
diff --git a/libs/baselibc/include/stdlib.h b/libs/baselibc/include/stdlib.h
new file mode 100644
index 0000000..41a3dcf
--- /dev/null
+++ b/libs/baselibc/include/stdlib.h
@@ -0,0 +1,98 @@
+/*
+ * stdlib.h
+ */
+
+#ifndef _STDLIB_H
+#define _STDLIB_H
+
+#include <klibc/extern.h>
+#include <klibc/inline.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+__extern_inline int abs(int __n)
+{
+	return (__n < 0) ? -__n : __n;
+}
+
+__extern int atoi(const char *);
+__extern long atol(const char *);
+__extern long long atoll(const char *);
+
+__extern_inline long labs(long __n)
+{
+	return (__n < 0L) ? -__n : __n;
+}
+
+__extern_inline long long llabs(long long __n)
+{
+	return (__n < 0LL) ? -__n : __n;
+}
+
+__extern void free(void *);
+__extern void *malloc(size_t);
+__extern void *calloc(size_t, size_t);
+__extern void *realloc(void *, size_t);
+
+/* Giving malloc some memory from which to allocate */
+__extern void add_malloc_block(void *, size_t);
+__extern void get_malloc_memory_status(size_t *, size_t *);
+
+/* Malloc locking
+ * Until the callbacks are set, malloc doesn't do any locking.
+ * malloc_lock() *may* timeout, in which case malloc() will return NULL.
+ */
+typedef bool (*malloc_lock_t)();
+typedef void (*malloc_unlock_t)();
+__extern void set_malloc_locking(malloc_lock_t, malloc_unlock_t);
+
+__extern long strtol(const char *, char **, int);
+__extern long long strtoll(const char *, char **, int);
+__extern unsigned long strtoul(const char *, char **, int);
+__extern unsigned long long strtoull(const char *, char **, int);
+
+typedef int (*__comparefunc_t) (const void *, const void *);
+__extern void *bsearch(const void *, const void *, size_t, size_t,
+		       __comparefunc_t);
+__extern void qsort(void *, size_t, size_t, __comparefunc_t);
+
+__extern long jrand48(unsigned short *);
+__extern long mrand48(void);
+__extern long nrand48(unsigned short *);
+__extern long lrand48(void);
+__extern unsigned short *seed48(const unsigned short *);
+__extern void srand48(long);
+
+__extern_inline char *getenv(const char *name)
+{
+	return NULL;
+}
+
+#define EXIT_SUCCESS	0
+#define EXIT_FAILURE	1
+__extern_inline void exit(int err)
+{
+	__extern void _exit(int s);
+
+	_exit(err);
+}
+
+#define RAND_MAX 0x7fffffff
+__extern_inline int rand(void)
+{
+	return (int)lrand48();
+}
+__extern_inline void srand(unsigned int __s)
+{
+	srand48(__s);
+}
+__extern_inline long random(void)
+{
+	return lrand48();
+}
+__extern_inline void srandom(unsigned int __s)
+{
+	srand48(__s);
+}
+
+#endif				/* _STDLIB_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/include/string.h
----------------------------------------------------------------------
diff --git a/libs/baselibc/include/string.h b/libs/baselibc/include/string.h
new file mode 100644
index 0000000..b3c1988
--- /dev/null
+++ b/libs/baselibc/include/string.h
@@ -0,0 +1,59 @@
+/*
+ * string.h
+ */
+
+#ifndef _STRING_H
+#define _STRING_H
+
+#include <klibc/extern.h>
+#include <stddef.h>
+
+__extern void *memccpy(void *, const void *, int, size_t);
+__extern void *memchr(const void *, int, size_t);
+__extern void *memrchr(const void *, int, size_t);
+__extern int memcmp(const void *, const void *, size_t);
+__extern void *memcpy(void *, const void *, size_t);
+__extern void *memmove(void *, const void *, size_t);
+__extern void *memset(void *, int, size_t);
+__extern void *memmem(const void *, size_t, const void *, size_t);
+__extern void memswap(void *, void *, size_t);
+__extern void bzero(void *, size_t);
+__extern int strcasecmp(const char *, const char *);
+__extern int strncasecmp(const char *, const char *, size_t);
+__extern char *strcat(char *, const char *);
+__extern char *strchr(const char *, int);
+__extern char *index(const char *, int);
+__extern char *strrchr(const char *, int);
+__extern char *rindex(const char *, int);
+__extern int strcmp(const char *, const char *);
+__extern char *strcpy(char *, const char *);
+__extern size_t strcspn(const char *, const char *);
+__extern char *strdup(const char *);
+__extern char *strndup(const char *, size_t);
+__extern size_t strlen(const char *);
+__extern size_t strnlen(const char *, size_t);
+__extern char *strncat(char *, const char *, size_t);
+__extern size_t strlcat(char *, const char *, size_t);
+__extern int strncmp(const char *, const char *, size_t);
+__extern char *strncpy(char *, const char *, size_t);
+__extern size_t strlcpy(char *, const char *, size_t);
+__extern char *strpbrk(const char *, const char *);
+__extern char *strsep(char **, const char *);
+__extern size_t strspn(const char *, const char *);
+__extern char *strstr(const char *, const char *);
+__extern char *strtok(char *, const char *);
+__extern char *strtok_r(char *, const char *, char **);
+
+/* Some dummy functions to avoid errors with C++ cstring */
+inline static int strcoll(const char *s1, const char *s2)
+{
+	return strcmp(s1, s2);
+}
+
+inline static size_t strxfrm(char *dest, const char *src, size_t n)
+{
+	strncpy(dest, src, n);
+	return strlen(src);
+}
+
+#endif				/* _STRING_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/asprintf.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/asprintf.c b/libs/baselibc/src/asprintf.c
new file mode 100644
index 0000000..a3f5f00
--- /dev/null
+++ b/libs/baselibc/src/asprintf.c
@@ -0,0 +1,30 @@
+/*
+ * asprintf.c
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+int asprintf(char **bufp, const char *format, ...)
+{
+	va_list ap, ap1;
+	int rv;
+	int bytes;
+	char *p;
+
+	va_start(ap, format);
+	va_copy(ap1, ap);
+
+	bytes = vsnprintf(NULL, 0, format, ap1) + 1;
+	va_end(ap1);
+
+	*bufp = p = malloc(bytes);
+	if (!p)
+		return -1;
+
+	rv = vsnprintf(p, bytes, format, ap);
+	va_end(ap);
+
+	return rv;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/atoi.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/atoi.c b/libs/baselibc/src/atoi.c
new file mode 100644
index 0000000..a26abee
--- /dev/null
+++ b/libs/baselibc/src/atoi.c
@@ -0,0 +1,3 @@
+#define TYPE int
+#define NAME atoi
+#include "templates/atox.c.template"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/atol.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/atol.c b/libs/baselibc/src/atol.c
new file mode 100644
index 0000000..1139c52
--- /dev/null
+++ b/libs/baselibc/src/atol.c
@@ -0,0 +1,3 @@
+#define TYPE long
+#define NAME atol
+#include "templates/atox.c.template"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/atoll.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/atoll.c b/libs/baselibc/src/atoll.c
new file mode 100644
index 0000000..bc8a9fc
--- /dev/null
+++ b/libs/baselibc/src/atoll.c
@@ -0,0 +1,3 @@
+#define TYPE long long
+#define NAME atoll
+#include "templates/atox.c.template"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/bsearch.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/bsearch.c b/libs/baselibc/src/bsearch.c
new file mode 100644
index 0000000..1c8b07f
--- /dev/null
+++ b/libs/baselibc/src/bsearch.c
@@ -0,0 +1,26 @@
+/*
+ * bsearch.c
+ */
+
+#include <stdlib.h>
+
+void *bsearch(const void *key, const void *base, size_t nmemb,
+	      size_t size, int (*cmp) (const void *, const void *))
+{
+	while (nmemb) {
+		size_t mididx = nmemb / 2;
+		const void *midobj = base + mididx * size;
+		int diff = cmp(key, midobj);
+
+		if (diff == 0)
+			return (void *)midobj;
+
+		if (diff > 0) {
+			base = midobj + size;
+			nmemb -= mididx + 1;
+		} else
+			nmemb = mididx;
+	}
+
+	return NULL;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/bzero.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/bzero.c b/libs/baselibc/src/bzero.c
new file mode 100644
index 0000000..aa1c1ff
--- /dev/null
+++ b/libs/baselibc/src/bzero.c
@@ -0,0 +1,6 @@
+#include <string.h>
+
+void bzero(void *dst, size_t n)
+{
+	memset(dst, 0, n);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/calloc.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/calloc.c b/libs/baselibc/src/calloc.c
new file mode 100644
index 0000000..3db7664
--- /dev/null
+++ b/libs/baselibc/src/calloc.c
@@ -0,0 +1,20 @@
+/*
+ * calloc.c
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+/* FIXME: This should look for multiplication overflow */
+
+void *calloc(size_t nmemb, size_t size)
+{
+	void *ptr;
+
+	size *= nmemb;
+	ptr = malloc(size);
+	if (ptr)
+		memset(ptr, 0, size);
+
+	return ptr;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/fgets.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/fgets.c b/libs/baselibc/src/fgets.c
new file mode 100644
index 0000000..4e9cf68
--- /dev/null
+++ b/libs/baselibc/src/fgets.c
@@ -0,0 +1,31 @@
+/*
+ * fgets.c
+ *
+ * This will be very slow due to the implementation of getc(),
+ * but we don't have anywhere to put characters we don't need from
+ * the input.
+ */
+
+#include <stdio.h>
+
+char *fgets(char *s, int n, FILE *f)
+{
+	int ch;
+	char *p = s;
+
+	while (n > 1) {
+		ch = getc(f);
+		if (ch == EOF) {
+			*p = '\0';
+			return NULL;
+		}
+		*p++ = ch;
+		n--;
+		if (ch == '\n')
+			break;
+	}
+	if (n)
+		*p = '\0';
+
+	return s;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/inline.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/inline.c b/libs/baselibc/src/inline.c
new file mode 100644
index 0000000..2d8d013
--- /dev/null
+++ b/libs/baselibc/src/inline.c
@@ -0,0 +1,5 @@
+// Make an externally visible symbol out of inlined functions
+#define __extern_inline
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/jrand48.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/jrand48.c b/libs/baselibc/src/jrand48.c
new file mode 100644
index 0000000..8e2b3ac
--- /dev/null
+++ b/libs/baselibc/src/jrand48.c
@@ -0,0 +1,24 @@
+/*
+ * jrand48.c
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+
+long jrand48(unsigned short xsubi[3])
+{
+	uint64_t x;
+
+	/* The xsubi[] array is littleendian by spec */
+	x = (uint64_t) (uint16_t) xsubi[0] +
+	    ((uint64_t) (uint16_t) xsubi[1] << 16) +
+	    ((uint64_t) (uint16_t) xsubi[2] << 32);
+
+	x = (0x5deece66dULL * x) + 0xb;
+
+	xsubi[0] = (unsigned short)(uint16_t) x;
+	xsubi[1] = (unsigned short)(uint16_t) (x >> 16);
+	xsubi[2] = (unsigned short)(uint16_t) (x >> 32);
+
+	return (long)(int32_t) (x >> 16);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/lrand48.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/lrand48.c b/libs/baselibc/src/lrand48.c
new file mode 100644
index 0000000..a2fc87a
--- /dev/null
+++ b/libs/baselibc/src/lrand48.c
@@ -0,0 +1,13 @@
+/*
+ * lrand48.c
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+
+extern unsigned short __rand48_seed[3];	/* Common with mrand48.c, srand48.c */
+
+long lrand48(void)
+{
+	return (uint32_t) jrand48(__rand48_seed) >> 1;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/malloc.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/malloc.c b/libs/baselibc/src/malloc.c
new file mode 100644
index 0000000..1d56de4
--- /dev/null
+++ b/libs/baselibc/src/malloc.c
@@ -0,0 +1,274 @@
+/*
+ * malloc.c
+ *
+ * Very simple linked-list based malloc()/free().
+ */
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "malloc.h"
+
+/* Both the arena list and the free memory list are double linked
+   list with head node.  This the head node. Note that the arena list
+   is sorted in order of address. */
+static struct free_arena_header __malloc_head = {
+	{
+		ARENA_TYPE_HEAD,
+		0,
+		&__malloc_head,
+		&__malloc_head,
+	},
+	&__malloc_head,
+	&__malloc_head
+};
+
+static bool malloc_lock_nop() {return true;}
+static void malloc_unlock_nop() {}
+
+static malloc_lock_t malloc_lock = &malloc_lock_nop;
+static malloc_unlock_t malloc_unlock = &malloc_unlock_nop;
+
+static inline void mark_block_dead(struct free_arena_header *ah)
+{
+#ifdef DEBUG_MALLOC
+	ah->a.type = ARENA_TYPE_DEAD;
+#endif
+}
+
+static inline void remove_from_main_chain(struct free_arena_header *ah)
+{
+	struct free_arena_header *ap, *an;
+
+	mark_block_dead(ah);
+
+	ap = ah->a.prev;
+	an = ah->a.next;
+	ap->a.next = an;
+	an->a.prev = ap;
+}
+
+static inline void remove_from_free_chain(struct free_arena_header *ah)
+{
+	struct free_arena_header *ap, *an;
+
+	ap = ah->prev_free;
+	an = ah->next_free;
+	ap->next_free = an;
+	an->prev_free = ap;
+}
+
+static inline void remove_from_chains(struct free_arena_header *ah)
+{
+	remove_from_free_chain(ah);
+	remove_from_main_chain(ah);
+}
+
+static void *__malloc_from_block(struct free_arena_header *fp, size_t size)
+{
+	size_t fsize;
+	struct free_arena_header *nfp, *na, *fpn, *fpp;
+
+	fsize = fp->a.size;
+
+	/* We need the 2* to account for the larger requirements of a
+	   free block */
+	if (fsize >= size + 2 * sizeof(struct arena_header)) {
+		/* Bigger block than required -- split block */
+		nfp = (struct free_arena_header *)((char *)fp + size);
+		na = fp->a.next;
+
+		nfp->a.type = ARENA_TYPE_FREE;
+		nfp->a.size = fsize - size;
+		fp->a.type = ARENA_TYPE_USED;
+		fp->a.size = size;
+
+		/* Insert into all-block chain */
+		nfp->a.prev = fp;
+		nfp->a.next = na;
+		na->a.prev = nfp;
+		fp->a.next = nfp;
+
+		/* Replace current block on free chain */
+		nfp->next_free = fpn = fp->next_free;
+		nfp->prev_free = fpp = fp->prev_free;
+		fpn->prev_free = nfp;
+		fpp->next_free = nfp;
+	} else {
+		fp->a.type = ARENA_TYPE_USED; /* Allocate the whole block */
+		remove_from_free_chain(fp);
+	}
+
+	return (void *)(&fp->a + 1);
+}
+
+static struct free_arena_header *__free_block(struct free_arena_header *ah)
+{
+	struct free_arena_header *pah, *nah;
+
+	pah = ah->a.prev;
+	nah = ah->a.next;
+	if (pah->a.type == ARENA_TYPE_FREE &&
+	    (char *)pah + pah->a.size == (char *)ah) {
+		/* Coalesce into the previous block */
+		pah->a.size += ah->a.size;
+		pah->a.next = nah;
+		nah->a.prev = pah;
+		mark_block_dead(ah);
+
+		ah = pah;
+		pah = ah->a.prev;
+	} else {
+		/* Need to add this block to the free chain */
+		ah->a.type = ARENA_TYPE_FREE;
+
+		ah->next_free = __malloc_head.next_free;
+		ah->prev_free = &__malloc_head;
+		__malloc_head.next_free = ah;
+		ah->next_free->prev_free = ah;
+	}
+
+	/* In either of the previous cases, we might be able to merge
+	   with the subsequent block... */
+	if (nah->a.type == ARENA_TYPE_FREE &&
+	    (char *)ah + ah->a.size == (char *)nah) {
+		ah->a.size += nah->a.size;
+
+		/* Remove the old block from the chains */
+		remove_from_chains(nah);
+	}
+
+	/* Return the block that contains the called block */
+	return ah;
+}
+
+void *malloc(size_t size)
+{
+	struct free_arena_header *fp;
+        void *more_mem;
+        extern void *_sbrk(int incr);
+
+	if (size == 0)
+		return NULL;
+
+	/* Add the obligatory arena header, and round up */
+	size = (size + 2 * sizeof(struct arena_header) - 1) & ARENA_SIZE_MASK;
+
+        if (!malloc_lock())
+                return NULL;
+
+        void *result = NULL;
+retry_alloc:
+	for (fp = __malloc_head.next_free; fp->a.type != ARENA_TYPE_HEAD;
+	     fp = fp->next_free) {
+		if (fp->a.size >= size) {
+			/* Found fit -- allocate out of this block */
+			result = __malloc_from_block(fp, size);
+                        break;
+		}
+	}
+        if (result == NULL) {
+            more_mem = _sbrk(size);
+            if (more_mem) {
+                add_malloc_block(more_mem, size);
+                goto retry_alloc;
+            }
+        }
+        malloc_unlock();
+	return result;
+}
+
+/* Call this to give malloc some memory to allocate from */
+void add_malloc_block(void *buf, size_t size)
+{
+	struct free_arena_header *fp = buf;
+	struct free_arena_header *pah;
+
+	if (size < sizeof(struct free_arena_header))
+		return; // Too small.
+
+	/* Insert the block into the management chains.  We need to set
+	   up the size and the main block list pointer, the rest of
+	   the work is logically identical to free(). */
+	fp->a.type = ARENA_TYPE_FREE;
+	fp->a.size = size;
+
+        if (!malloc_lock())
+            return;
+
+	/* We need to insert this into the main block list in the proper
+	   place -- this list is required to be sorted.  Since we most likely
+	   get memory assignments in ascending order, search backwards for
+	   the proper place. */
+	for (pah = __malloc_head.a.prev; pah->a.type != ARENA_TYPE_HEAD;
+	     pah = pah->a.prev) {
+		if (pah < fp)
+			break;
+	}
+
+	/* Now pah points to the node that should be the predecessor of
+	   the new node */
+	fp->a.next = pah->a.next;
+	fp->a.prev = pah;
+	pah->a.next = fp;
+	fp->a.next->a.prev = fp;
+
+	/* Insert into the free chain and coalesce with adjacent blocks */
+	fp = __free_block(fp);
+
+        malloc_unlock();
+}
+
+void free(void *ptr)
+{
+	struct free_arena_header *ah;
+
+	if (!ptr)
+		return;
+
+	ah = (struct free_arena_header *)
+	    ((struct arena_header *)ptr - 1);
+
+#ifdef DEBUG_MALLOC
+	assert(ah->a.type == ARENA_TYPE_USED);
+#endif
+
+        if (!malloc_lock())
+            return;
+
+	/* Merge into adjacent free blocks */
+	ah = __free_block(ah);
+        malloc_unlock();
+}
+
+void get_malloc_memory_status(size_t *free_bytes, size_t *largest_block)
+{
+    struct free_arena_header *fp;
+    *free_bytes = 0;
+    *largest_block = 0;
+
+    if (!malloc_lock())
+            return;
+
+    for (fp = __malloc_head.next_free; fp->a.type != ARENA_TYPE_HEAD; fp = fp->next_free) {
+        *free_bytes += fp->a.size;
+        if (fp->a.size >= *largest_block) {
+            *largest_block = fp->a.size;
+        }
+    }
+
+    malloc_unlock();
+}
+
+void set_malloc_locking(malloc_lock_t lock, malloc_unlock_t unlock)
+{
+    if (lock)
+        malloc_lock = lock;
+    else
+        malloc_lock = &malloc_lock_nop;
+
+    if (unlock)
+        malloc_unlock = unlock;
+    else
+        malloc_unlock = &malloc_unlock_nop;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/malloc.h
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/malloc.h b/libs/baselibc/src/malloc.h
new file mode 100644
index 0000000..2bed2a6
--- /dev/null
+++ b/libs/baselibc/src/malloc.h
@@ -0,0 +1,43 @@
+/*
+ * malloc.h
+ *
+ * Internals for the memory allocator
+ */
+
+#include <stdint.h>
+#include <stddef.h>
+
+/*
+ * This structure should be a power of two.  This becomes the
+ * alignment unit.
+ */
+struct free_arena_header;
+
+struct arena_header {
+	size_t type;
+	size_t size;
+	struct free_arena_header *next, *prev;
+};
+
+#ifdef DEBUG_MALLOC
+#define ARENA_TYPE_USED 0x64e69c70
+#define ARENA_TYPE_FREE 0x012d610a
+#define ARENA_TYPE_HEAD 0x971676b5
+#define ARENA_TYPE_DEAD 0xeeeeeeee
+#else
+#define ARENA_TYPE_USED 0
+#define ARENA_TYPE_FREE 1
+#define ARENA_TYPE_HEAD 2
+#endif
+
+#define ARENA_SIZE_MASK (~(sizeof(struct arena_header)-1))
+
+/*
+ * This structure should be no more than twice the size of the
+ * previous structure.
+ */
+struct free_arena_header {
+	struct arena_header a;
+	struct free_arena_header *next_free, *prev_free;
+};
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/memccpy.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/memccpy.c b/libs/baselibc/src/memccpy.c
new file mode 100644
index 0000000..83d02c9
--- /dev/null
+++ b/libs/baselibc/src/memccpy.c
@@ -0,0 +1,23 @@
+/*
+ * memccpy.c
+ *
+ * memccpy()
+ */
+
+#include <stddef.h>
+#include <string.h>
+
+void *memccpy(void *dst, const void *src, int c, size_t n)
+{
+	char *q = dst;
+	const char *p = src;
+	char ch;
+
+	while (n--) {
+		*q++ = ch = *p++;
+		if (ch == (char)c)
+			return q;
+	}
+
+	return NULL;		/* No instance of "c" found */
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/memchr.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/memchr.c b/libs/baselibc/src/memchr.c
new file mode 100644
index 0000000..f1947fb
--- /dev/null
+++ b/libs/baselibc/src/memchr.c
@@ -0,0 +1,19 @@
+/*
+ * memchr.c
+ */
+
+#include <stddef.h>
+#include <string.h>
+
+void *memchr(const void *s, int c, size_t n)
+{
+	const unsigned char *sp = s;
+
+	while (n--) {
+		if (*sp == (unsigned char)c)
+			return (void *)sp;
+		sp++;
+	}
+
+	return NULL;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/memcmp.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/memcmp.c b/libs/baselibc/src/memcmp.c
new file mode 100644
index 0000000..3ce9941
--- /dev/null
+++ b/libs/baselibc/src/memcmp.c
@@ -0,0 +1,19 @@
+/*
+ * memcmp.c
+ */
+
+#include <string.h>
+
+int memcmp(const void *s1, const void *s2, size_t n)
+{
+	const unsigned char *c1 = s1, *c2 = s2;
+	int d = 0;
+
+	while (n--) {
+		d = (int)*c1++ - (int)*c2++;
+		if (d)
+			break;
+	}
+
+	return d;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/memcpy.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/memcpy.c b/libs/baselibc/src/memcpy.c
new file mode 100644
index 0000000..5ce206d
--- /dev/null
+++ b/libs/baselibc/src/memcpy.c
@@ -0,0 +1,29 @@
+/*
+ * memcpy.c
+ */
+
+#include <string.h>
+#include <stdint.h>
+
+void *memcpy(void *dst, const void *src, size_t n)
+{
+	const char *p = src;
+	char *q = dst;
+#if defined(__i386__)
+	size_t nl = n >> 2;
+	asm volatile ("cld ; rep ; movsl ; movl %3,%0 ; rep ; movsb":"+c" (nl),
+		      "+S"(p), "+D"(q)
+		      :"r"(n & 3));
+#elif defined(__x86_64__)
+	size_t nq = n >> 3;
+	asm volatile ("cld ; rep ; movsq ; movl %3,%%ecx ; rep ; movsb":"+c"
+		      (nq), "+S"(p), "+D"(q)
+		      :"r"((uint32_t) (n & 7)));
+#else
+	while (n--) {
+		*q++ = *p++;
+	}
+#endif
+
+	return dst;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/memfile.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/memfile.c b/libs/baselibc/src/memfile.c
new file mode 100644
index 0000000..c915004
--- /dev/null
+++ b/libs/baselibc/src/memfile.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+
+size_t memfile_write(FILE *instance, const char *bp, size_t n)
+{
+    struct MemFile *f = (struct MemFile*)instance;
+    size_t i = 0;
+    
+    while (n--)
+    {
+        f->bytes_written++;
+        if (f->bytes_written <= f->size)
+        {
+            *f->buffer++ = *bp++;
+            i++;
+        }
+    }
+    
+    return i;
+}
+
+const struct File_methods MemFile_methods = {
+    &memfile_write,
+    NULL
+};
+
+FILE *fmemopen_w(struct MemFile* storage, char *buffer, size_t size)
+{
+    storage->file.vmt = &MemFile_methods;
+    storage->buffer = buffer;
+    storage->bytes_written = 0;
+    storage->size = size;
+    return (FILE*)storage;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/memmem.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/memmem.c b/libs/baselibc/src/memmem.c
new file mode 100644
index 0000000..8b5faa0
--- /dev/null
+++ b/libs/baselibc/src/memmem.c
@@ -0,0 +1,52 @@
+/*
+ * memmem.c
+ *
+ * Find a byte string inside a longer byte string
+ *
+ * This uses the "Not So Naive" algorithm, a very simple but
+ * usually effective algorithm, see:
+ *
+ * http://www-igm.univ-mlv.fr/~lecroq/string/
+ */
+
+#include <string.h>
+
+void *memmem(const void *haystack, size_t n, const void *needle, size_t m)
+{
+	const unsigned char *y = (const unsigned char *)haystack;
+	const unsigned char *x = (const unsigned char *)needle;
+
+	size_t j, k, l;
+
+	if (m > n || !m || !n)
+		return NULL;
+
+	if (1 != m) {
+		if (x[0] == x[1]) {
+			k = 2;
+			l = 1;
+		} else {
+			k = 1;
+			l = 2;
+		}
+
+		j = 0;
+		while (j <= n - m) {
+			if (x[1] != y[j + 1]) {
+				j += k;
+			} else {
+				if (!memcmp(x + 2, y + j + 2, m - 2)
+				    && x[0] == y[j])
+					return (void *)&y[j];
+				j += l;
+			}
+		}
+	} else
+		do {
+			if (*y == *x)
+				return (void *)y;
+			y++;
+		} while (--n);
+
+	return NULL;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/memmove.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/memmove.c b/libs/baselibc/src/memmove.c
new file mode 100644
index 0000000..a398cd8
--- /dev/null
+++ b/libs/baselibc/src/memmove.c
@@ -0,0 +1,36 @@
+/*
+ * memmove.c
+ */
+
+#include <string.h>
+
+void *memmove(void *dst, const void *src, size_t n)
+{
+	const char *p = src;
+	char *q = dst;
+#if defined(__i386__) || defined(__x86_64__)
+	if (q < p) {
+		asm volatile("cld; rep; movsb"
+			     : "+c" (n), "+S"(p), "+D"(q));
+	} else {
+		p += (n - 1);
+		q += (n - 1);
+		asm volatile("std; rep; movsb; cld"
+			     : "+c" (n), "+S"(p), "+D"(q));
+	}
+#else
+	if (q < p) {
+		while (n--) {
+			*q++ = *p++;
+		}
+	} else {
+		p += n;
+		q += n;
+		while (n--) {
+			*--q = *--p;
+		}
+	}
+#endif
+
+	return dst;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/memrchr.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/memrchr.c b/libs/baselibc/src/memrchr.c
new file mode 100644
index 0000000..ff6d711
--- /dev/null
+++ b/libs/baselibc/src/memrchr.c
@@ -0,0 +1,19 @@
+/*
+ * memrchr.c
+ */
+
+#include <stddef.h>
+#include <string.h>
+
+void *memrchr(const void *s, int c, size_t n)
+{
+	const unsigned char *sp = (const unsigned char *)s + n - 1;
+
+	while (n--) {
+		if (*sp == (unsigned char)c)
+			return (void *)sp;
+		sp--;
+	}
+
+	return NULL;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/memset.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/memset.c b/libs/baselibc/src/memset.c
new file mode 100644
index 0000000..aa00b5b
--- /dev/null
+++ b/libs/baselibc/src/memset.c
@@ -0,0 +1,30 @@
+/*
+ * memset.c
+ */
+
+#include <string.h>
+#include <stdint.h>
+
+void *memset(void *dst, int c, size_t n)
+{
+	char *q = dst;
+
+#if defined(__i386__)
+	size_t nl = n >> 2;
+	asm volatile ("cld ; rep ; stosl ; movl %3,%0 ; rep ; stosb"
+		      : "+c" (nl), "+D" (q)
+		      : "a" ((unsigned char)c * 0x01010101U), "r" (n & 3));
+#elif defined(__x86_64__)
+	size_t nq = n >> 3;
+	asm volatile ("cld ; rep ; stosq ; movl %3,%%ecx ; rep ; stosb"
+		      :"+c" (nq), "+D" (q)
+		      : "a" ((unsigned char)c * 0x0101010101010101U),
+			"r" ((uint32_t) n & 7));
+#else
+	while (n--) {
+		*q++ = c;
+	}
+#endif
+
+	return dst;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/memswap.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/memswap.c b/libs/baselibc/src/memswap.c
new file mode 100644
index 0000000..b32315c
--- /dev/null
+++ b/libs/baselibc/src/memswap.c
@@ -0,0 +1,24 @@
+/*
+ * memswap()
+ *
+ * Swaps the contents of two nonoverlapping memory areas.
+ * This really could be done faster...
+ */
+
+#include <string.h>
+
+void memswap(void *m1, void *m2, size_t n)
+{
+	char *p = m1;
+	char *q = m2;
+	char tmp;
+
+	while (n--) {
+		tmp = *p;
+		*p = *q;
+		*q = tmp;
+
+		p++;
+		q++;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/mrand48.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/mrand48.c b/libs/baselibc/src/mrand48.c
new file mode 100644
index 0000000..1a2383b
--- /dev/null
+++ b/libs/baselibc/src/mrand48.c
@@ -0,0 +1,13 @@
+/*
+ * mrand48.c
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+
+extern unsigned short __rand48_seed[3];	/* Common with lrand48.c, srand48.c */
+
+long mrand48(void)
+{
+	return jrand48(__rand48_seed);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/mynewt.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/mynewt.c b/libs/baselibc/src/mynewt.c
new file mode 100644
index 0000000..dbe4eaf
--- /dev/null
+++ b/libs/baselibc/src/mynewt.c
@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2015 Runtime Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <console/console.h>
+
+static size_t
+stdin_read(FILE *fp, char *bp, size_t n)
+{
+    return 0;
+}
+
+static size_t
+stdout_write(FILE *fp, const char *bp, size_t n)
+{
+    console_write(bp, n);
+    return n;
+}
+
+static struct File_methods _stdin_methods = {
+    .write = stdout_write,
+    .read = stdin_read
+};
+
+static struct File _stdin = {
+    .vmt = &_stdin_methods
+};
+
+struct File *const stdin = &_stdin;
+struct File *const stdout = &_stdin;
+struct File *const stderr = &_stdin;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/nrand48.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/nrand48.c b/libs/baselibc/src/nrand48.c
new file mode 100644
index 0000000..cb3532b
--- /dev/null
+++ b/libs/baselibc/src/nrand48.c
@@ -0,0 +1,11 @@
+/*
+ * nrand48.c
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+
+long nrand48(unsigned short xsubi[3])
+{
+	return (long)((uint32_t) jrand48(xsubi) >> 1);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/qsort.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/qsort.c b/libs/baselibc/src/qsort.c
new file mode 100644
index 0000000..4c189fc
--- /dev/null
+++ b/libs/baselibc/src/qsort.c
@@ -0,0 +1,46 @@
+/*
+ * qsort.c
+ *
+ * This is actually combsort.  It's an O(n log n) algorithm with
+ * simplicity/small code size being its main virtue.
+ */
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+static inline size_t newgap(size_t gap)
+{
+	gap = (gap * 10) / 13;
+	if (gap == 9 || gap == 10)
+		gap = 11;
+
+	if (gap < 1)
+		gap = 1;
+	return gap;
+}
+
+void qsort(void *base, size_t nmemb, size_t size,
+	   int (*compar) (const void *, const void *))
+{
+	size_t gap = nmemb;
+	size_t i, j;
+	char *p1, *p2;
+	int swapped;
+
+	if (!nmemb)
+		return;
+
+	do {
+		gap = newgap(gap);
+		swapped = 0;
+
+		for (i = 0, p1 = base; i < nmemb - gap; i++, p1 += size) {
+			j = i + gap;
+			if (compar(p1, p2 = (char *)base + j * size) > 0) {
+				memswap(p1, p2, size);
+				swapped = 1;
+			}
+		}
+	} while (gap > 1 || swapped);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/realloc.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/realloc.c b/libs/baselibc/src/realloc.c
new file mode 100644
index 0000000..14a2f2f
--- /dev/null
+++ b/libs/baselibc/src/realloc.c
@@ -0,0 +1,48 @@
+/*
+ * realloc.c
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "malloc.h"
+
+/* FIXME: This is cheesy, it should be fixed later */
+
+void *realloc(void *ptr, size_t size)
+{
+	struct free_arena_header *ah;
+	void *newptr;
+	size_t oldsize;
+
+	if (!ptr)
+		return malloc(size);
+
+	if (size == 0) {
+		free(ptr);
+		return NULL;
+	}
+
+	/* Add the obligatory arena header, and round up */
+	size = (size + 2 * sizeof(struct arena_header) - 1) & ARENA_SIZE_MASK;
+
+	ah = (struct free_arena_header *)
+	    ((struct arena_header *)ptr - 1);
+
+	if (ah->a.size >= size && size >= (ah->a.size >> 2)) {
+		/* This field is a good size already. */
+		return ptr;
+	} else {
+		/* Make me a new block.  This is kind of bogus; we should
+		   be checking the following block to see if we can do an
+		   in-place adjustment... fix that later. */
+
+		oldsize = ah->a.size - sizeof(struct arena_header);
+
+		newptr = malloc(size);
+		memcpy(newptr, ptr, (size < oldsize) ? size : oldsize);
+		free(ptr);
+
+		return newptr;
+	}
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/sprintf.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/sprintf.c b/libs/baselibc/src/sprintf.c
new file mode 100644
index 0000000..c6d8758
--- /dev/null
+++ b/libs/baselibc/src/sprintf.c
@@ -0,0 +1,18 @@
+/*
+ * sprintf.c
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+
+int sprintf(char *buffer, const char *format, ...)
+{
+	va_list ap;
+	int rv;
+
+	va_start(ap, format);
+	rv = vsnprintf(buffer, ~(size_t) 0, format, ap);
+	va_end(ap);
+
+	return rv;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/srand48.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/srand48.c b/libs/baselibc/src/srand48.c
new file mode 100644
index 0000000..e1c9567
--- /dev/null
+++ b/libs/baselibc/src/srand48.c
@@ -0,0 +1,15 @@
+/*
+ * srand48.c
+ */
+
+#include <stdlib.h>
+#include <stdint.h>
+
+unsigned short __rand48_seed[3];	/* Common with mrand48.c, lrand48.c */
+
+void srand48(long seedval)
+{
+	__rand48_seed[0] = 0x330e;
+	__rand48_seed[1] = (unsigned short)seedval;
+	__rand48_seed[2] = (unsigned short)((uint32_t) seedval >> 16);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/sscanf.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/sscanf.c b/libs/baselibc/src/sscanf.c
new file mode 100644
index 0000000..f53b276
--- /dev/null
+++ b/libs/baselibc/src/sscanf.c
@@ -0,0 +1,17 @@
+/*
+ * sscanf()
+ */
+
+#include <stdio.h>
+
+int sscanf(const char *str, const char *format, ...)
+{
+	va_list ap;
+	int rv;
+
+	va_start(ap, format);
+	rv = vsscanf(str, format, ap);
+	va_end(ap);
+
+	return rv;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strcasecmp.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strcasecmp.c b/libs/baselibc/src/strcasecmp.c
new file mode 100644
index 0000000..ee1f28b
--- /dev/null
+++ b/libs/baselibc/src/strcasecmp.c
@@ -0,0 +1,24 @@
+/*
+ * strcasecmp.c
+ */
+
+#include <string.h>
+#include <ctype.h>
+
+int strcasecmp(const char *s1, const char *s2)
+{
+	const unsigned char *c1 = (const unsigned char *)s1;
+	const unsigned char *c2 = (const unsigned char *)s2;
+	unsigned char ch;
+	int d = 0;
+
+	while (1) {
+		/* toupper() expects an unsigned char (implicitly cast to int)
+		   as input, and returns an int, which is exactly what we want. */
+		d = toupper(ch = *c1++) - toupper(*c2++);
+		if (d || !ch)
+			break;
+	}
+
+	return d;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strcat.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strcat.c b/libs/baselibc/src/strcat.c
new file mode 100644
index 0000000..6c5b673
--- /dev/null
+++ b/libs/baselibc/src/strcat.c
@@ -0,0 +1,11 @@
+/*
+ * strcat.c
+ */
+
+#include <string.h>
+
+char *strcat(char *dst, const char *src)
+{
+	strcpy(strchr(dst, '\0'), src);
+	return dst;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strchr.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strchr.c b/libs/baselibc/src/strchr.c
new file mode 100644
index 0000000..6a57313
--- /dev/null
+++ b/libs/baselibc/src/strchr.c
@@ -0,0 +1,17 @@
+/*
+ * strchr.c
+ */
+
+#include <string.h>
+
+char *strchr(const char *s, int c)
+{
+	while (*s != (char)c) {
+		if (!*s)
+			return NULL;
+		s++;
+	}
+
+	return (char *)s;
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strcmp.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strcmp.c b/libs/baselibc/src/strcmp.c
new file mode 100644
index 0000000..3ab9f5a
--- /dev/null
+++ b/libs/baselibc/src/strcmp.c
@@ -0,0 +1,21 @@
+/*
+ * strcmp.c
+ */
+
+#include <string.h>
+
+int strcmp(const char *s1, const char *s2)
+{
+	const unsigned char *c1 = (const unsigned char *)s1;
+	const unsigned char *c2 = (const unsigned char *)s2;
+	unsigned char ch;
+	int d = 0;
+
+	while (1) {
+		d = (int)(ch = *c1++) - (int)*c2++;
+		if (d || !ch)
+			break;
+	}
+
+	return d;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strcpy.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strcpy.c b/libs/baselibc/src/strcpy.c
new file mode 100644
index 0000000..aa656cf
--- /dev/null
+++ b/libs/baselibc/src/strcpy.c
@@ -0,0 +1,20 @@
+/*
+ * strcpy.c
+ *
+ * strcpy()
+ */
+
+#include <string.h>
+
+char *strcpy(char *dst, const char *src)
+{
+	char *q = dst;
+	const char *p = src;
+	char ch;
+
+	do {
+		*q++ = ch = *p++;
+	} while (ch);
+
+	return dst;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strcspn.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strcspn.c b/libs/baselibc/src/strcspn.c
new file mode 100644
index 0000000..ba9e3be
--- /dev/null
+++ b/libs/baselibc/src/strcspn.c
@@ -0,0 +1,51 @@
+/*
+FUNCTION
+	<<strcspn>>---count characters not in string
+
+INDEX
+	strcspn
+
+ANSI_SYNOPSIS
+	size_t strcspn(const char *<[s1]>, const char *<[s2]>);
+
+TRAD_SYNOPSIS
+	size_t strcspn(<[s1]>, <[s2]>)
+	char *<[s1]>;
+	char *<[s2]>;
+
+DESCRIPTION
+	This function computes the length of the initial part of
+	the string pointed to by <[s1]> which consists entirely of
+	characters <[NOT]> from the string pointed to by <[s2]>
+	(excluding the terminating null character).
+
+RETURNS
+	<<strcspn>> returns the length of the substring found.
+
+PORTABILITY
+<<strcspn>> is ANSI C.
+
+<<strcspn>> requires no supporting OS subroutines.
+ */
+
+#include <string.h>
+
+size_t strcspn(const char *s1, const char *s2)
+{
+  const char *s = s1;
+  const char *c;
+
+  while (*s1)
+    {
+      for (c = s2; *c; c++)
+	{
+	  if (*s1 == *c)
+	    break;
+	}
+      if (*c)
+	break;
+      s1++;
+    }
+
+  return s1 - s;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strdup.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strdup.c b/libs/baselibc/src/strdup.c
new file mode 100644
index 0000000..905b51d
--- /dev/null
+++ b/libs/baselibc/src/strdup.c
@@ -0,0 +1,17 @@
+/*
+ * strdup.c
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+char *strdup(const char *s)
+{
+	int l = strlen(s) + 1;
+	char *d = malloc(l);
+
+	if (d)
+		memcpy(d, s, l);
+
+	return d;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strlcat.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strlcat.c b/libs/baselibc/src/strlcat.c
new file mode 100644
index 0000000..6d95087
--- /dev/null
+++ b/libs/baselibc/src/strlcat.c
@@ -0,0 +1,30 @@
+/*
+ * strlcat.c
+ */
+
+#include <string.h>
+
+size_t strlcat(char *dst, const char *src, size_t size)
+{
+	size_t bytes = 0;
+	char *q = dst;
+	const char *p = src;
+	char ch;
+
+	while (bytes < size && *q) {
+		q++;
+		bytes++;
+	}
+	if (bytes == size)
+		return (bytes + strlen(src));
+
+	while ((ch = *p++)) {
+		if (bytes + 1 < size)
+			*q++ = ch;
+
+		bytes++;
+	}
+
+	*q = '\0';
+	return bytes;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strlcpy.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strlcpy.c b/libs/baselibc/src/strlcpy.c
new file mode 100644
index 0000000..3ec8fd2
--- /dev/null
+++ b/libs/baselibc/src/strlcpy.c
@@ -0,0 +1,26 @@
+/*
+ * strlcpy.c
+ */
+
+#include <string.h>
+
+size_t strlcpy(char *dst, const char *src, size_t size)
+{
+	size_t bytes = 0;
+	char *q = dst;
+	const char *p = src;
+	char ch;
+
+	while ((ch = *p++)) {
+		if (bytes + 1 < size)
+			*q++ = ch;
+
+		bytes++;
+	}
+
+	/* If size == 0 there is no space for a final null... */
+	if (size)
+		*q = '\0';
+
+	return bytes;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strlen.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strlen.c b/libs/baselibc/src/strlen.c
new file mode 100644
index 0000000..86526a5
--- /dev/null
+++ b/libs/baselibc/src/strlen.c
@@ -0,0 +1,13 @@
+/*
+ * strlen()
+ */
+
+#include <string.h>
+
+size_t strlen(const char *s)
+{
+	const char *ss = s;
+	while (*ss)
+		ss++;
+	return ss - s;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strncasecmp.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strncasecmp.c b/libs/baselibc/src/strncasecmp.c
new file mode 100644
index 0000000..0551935
--- /dev/null
+++ b/libs/baselibc/src/strncasecmp.c
@@ -0,0 +1,24 @@
+/*
+ * strncasecmp.c
+ */
+
+#include <string.h>
+#include <ctype.h>
+
+int strncasecmp(const char *s1, const char *s2, size_t n)
+{
+	const unsigned char *c1 = (const unsigned char *)s1;
+	const unsigned char *c2 = (const unsigned char *)s2;
+	unsigned char ch;
+	int d = 0;
+
+	while (n--) {
+		/* toupper() expects an unsigned char (implicitly cast to int)
+		   as input, and returns an int, which is exactly what we want. */
+		d = toupper(ch = *c1++) - toupper(*c2++);
+		if (d || !ch)
+			break;
+	}
+
+	return d;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strncat.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strncat.c b/libs/baselibc/src/strncat.c
new file mode 100644
index 0000000..5b86216
--- /dev/null
+++ b/libs/baselibc/src/strncat.c
@@ -0,0 +1,21 @@
+/*
+ * strncat.c
+ */
+
+#include <string.h>
+
+char *strncat(char *dst, const char *src, size_t n)
+{
+	char *q = strchr(dst, '\0');
+	const char *p = src;
+	char ch;
+
+	while (n--) {
+		*q++ = ch = *p++;
+		if (!ch)
+			return dst;
+	}
+	*q = '\0';
+
+	return dst;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strncmp.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strncmp.c b/libs/baselibc/src/strncmp.c
new file mode 100644
index 0000000..5235545
--- /dev/null
+++ b/libs/baselibc/src/strncmp.c
@@ -0,0 +1,21 @@
+/*
+ * strncmp.c
+ */
+
+#include <string.h>
+
+int strncmp(const char *s1, const char *s2, size_t n)
+{
+	const unsigned char *c1 = (const unsigned char *)s1;
+	const unsigned char *c2 = (const unsigned char *)s2;
+	unsigned char ch;
+	int d = 0;
+
+	while (n--) {
+		d = (int)(ch = *c1++) - (int)*c2++;
+		if (d || !ch)
+			break;
+	}
+
+	return d;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strncpy.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strncpy.c b/libs/baselibc/src/strncpy.c
new file mode 100644
index 0000000..fffc118
--- /dev/null
+++ b/libs/baselibc/src/strncpy.c
@@ -0,0 +1,24 @@
+/*
+ * strncpy.c
+ */
+
+#include <string.h>
+
+char *strncpy(char *dst, const char *src, size_t n)
+{
+	char *q = dst;
+	const char *p = src;
+	char ch;
+
+	while (n) {
+		n--;
+		*q++ = ch = *p++;
+		if (!ch)
+			break;
+	}
+
+	/* The specs say strncpy() fills the entire buffer with NUL.  Sigh. */
+	memset(q, 0, n);
+
+	return dst;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strndup.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strndup.c b/libs/baselibc/src/strndup.c
new file mode 100644
index 0000000..427162f
--- /dev/null
+++ b/libs/baselibc/src/strndup.c
@@ -0,0 +1,19 @@
+/*
+ * strndup.c
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+char *strndup(const char *s, size_t n)
+{
+	int l = n > strlen(s) ? strlen(s) + 1 : n + 1;
+	char *d = malloc(l);
+
+	if (!d)
+		return NULL;
+	
+	memcpy(d, s, l);
+	d[n] = '\0';
+	return d;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strnlen.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strnlen.c b/libs/baselibc/src/strnlen.c
new file mode 100644
index 0000000..1678f4b
--- /dev/null
+++ b/libs/baselibc/src/strnlen.c
@@ -0,0 +1,18 @@
+/*
+ * strnlen()
+ */
+
+#include <string.h>
+
+size_t strnlen(const char *s, size_t maxlen)
+{
+	const char *ss = s;
+
+	/* Important: the maxlen test must precede the reference through ss;
+	   since the byte beyond the maximum may segfault */
+	while ((maxlen > 0) && *ss) {
+		ss++;
+		maxlen--;
+	}
+	return ss - s;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strntoimax.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strntoimax.c b/libs/baselibc/src/strntoimax.c
new file mode 100644
index 0000000..179d9e5
--- /dev/null
+++ b/libs/baselibc/src/strntoimax.c
@@ -0,0 +1,13 @@
+/*
+ * strntoimax.c
+ *
+ * strntoimax()
+ */
+
+#include <stddef.h>
+#include <inttypes.h>
+
+intmax_t strntoimax(const char *nptr, char **endptr, int base, size_t n)
+{
+	return (intmax_t) strntoumax(nptr, endptr, base, n);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strntoumax.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strntoumax.c b/libs/baselibc/src/strntoumax.c
new file mode 100644
index 0000000..56dddad
--- /dev/null
+++ b/libs/baselibc/src/strntoumax.c
@@ -0,0 +1,77 @@
+/*
+ * strntoumax.c
+ *
+ * The strntoumax() function and associated
+ */
+
+#include <stddef.h>
+#include <stdint.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+static inline int digitval(int ch)
+{
+	if (ch >= '0' && ch <= '9') {
+		return ch - '0';
+	} else if (ch >= 'A' && ch <= 'Z') {
+		return ch - 'A' + 10;
+	} else if (ch >= 'a' && ch <= 'z') {
+		return ch - 'a' + 10;
+	} else {
+		return -1;
+	}
+}
+
+uintmax_t strntoumax(const char *nptr, char **endptr, int base, size_t n)
+{
+	int minus = 0;
+	uintmax_t v = 0;
+	int d;
+
+	while (n && isspace((unsigned char)*nptr)) {
+		nptr++;
+		n--;
+	}
+
+	/* Single optional + or - */
+	if (n) {
+		char c = *nptr;
+		if (c == '-' || c == '+') {
+			minus = (c == '-');
+			nptr++;
+			n--;
+		}
+	}
+
+	if (base == 0) {
+		if (n >= 2 && nptr[0] == '0' &&
+		    (nptr[1] == 'x' || nptr[1] == 'X')) {
+			n -= 2;
+			nptr += 2;
+			base = 16;
+		} else if (n >= 1 && nptr[0] == '0') {
+			n--;
+			nptr++;
+			base = 8;
+		} else {
+			base = 10;
+		}
+	} else if (base == 16) {
+		if (n >= 2 && nptr[0] == '0' &&
+		    (nptr[1] == 'x' || nptr[1] == 'X')) {
+			n -= 2;
+			nptr += 2;
+		}
+	}
+
+	while (n && (d = digitval(*nptr)) >= 0 && d < base) {
+		v = v * base + d;
+		n--;
+		nptr++;
+	}
+
+	if (endptr)
+		*endptr = (char *)nptr;
+
+	return minus ? -v : v;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strpbrk.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strpbrk.c b/libs/baselibc/src/strpbrk.c
new file mode 100644
index 0000000..1873971
--- /dev/null
+++ b/libs/baselibc/src/strpbrk.c
@@ -0,0 +1,55 @@
+/*
+FUNCTION
+	<<strpbrk>>---find characters in string
+
+INDEX
+	strpbrk
+
+ANSI_SYNOPSIS
+	#include <string.h>
+	char *strpbrk(const char *<[s1]>, const char *<[s2]>);
+
+TRAD_SYNOPSIS
+	#include <string.h>
+	char *strpbrk(<[s1]>, <[s2]>)
+	char *<[s1]>;
+	char *<[s2]>;
+
+DESCRIPTION
+	This function locates the first occurence in the string
+	pointed to by <[s1]> of any character in string pointed to by
+	<[s2]> (excluding the terminating null character).
+
+RETURNS
+	<<strpbrk>> returns a pointer to the character found in <[s1]>, or a
+	null pointer if no character from <[s2]> occurs in <[s1]>.
+
+PORTABILITY
+<<strpbrk>> requires no supporting OS subroutines.
+*/
+
+#include <string.h>
+
+char *strpbrk(const char *s1, const char *s2)
+{
+  const char *c = s2;
+  if (!*s1)
+    return (char *) NULL;
+
+  while (*s1)
+    {
+      for (c = s2; *c; c++)
+	{
+	  if (*s1 == *c)
+	    break;
+	}
+      if (*c)
+	break;
+      s1++;
+    }
+
+  if (*c == '\0')
+    s1 = NULL;
+
+  return (char *) s1;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strrchr.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strrchr.c b/libs/baselibc/src/strrchr.c
new file mode 100644
index 0000000..69b238f
--- /dev/null
+++ b/libs/baselibc/src/strrchr.c
@@ -0,0 +1,19 @@
+/*
+ * strrchr.c
+ */
+
+#include <string.h>
+
+char *strrchr(const char *s, int c)
+{
+	const char *found = NULL;
+
+	while (*s) {
+		if (*s == (char)c)
+			found = s;
+		s++;
+	}
+
+	return (char *)found;
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strsep.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strsep.c b/libs/baselibc/src/strsep.c
new file mode 100644
index 0000000..44e76bd
--- /dev/null
+++ b/libs/baselibc/src/strsep.c
@@ -0,0 +1,21 @@
+/*
+ * strsep.c
+ */
+
+#include <string.h>
+
+char *strsep(char **stringp, const char *delim)
+{
+	char *s = *stringp;
+	char *e;
+
+	if (!s)
+		return NULL;
+
+	e = strpbrk(s, delim);
+	if (e)
+		*e++ = '\0';
+
+	*stringp = e;
+	return s;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strspn.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strspn.c b/libs/baselibc/src/strspn.c
new file mode 100644
index 0000000..e8b213c
--- /dev/null
+++ b/libs/baselibc/src/strspn.c
@@ -0,0 +1,56 @@
+/*
+FUNCTION
+	<<strspn>>---find initial match
+
+INDEX
+	strspn
+
+ANSI_SYNOPSIS
+	#include <string.h>
+	size_t strspn(const char *<[s1]>, const char *<[s2]>);
+
+TRAD_SYNOPSIS
+	#include <string.h>
+	size_t strspn(<[s1]>, <[s2]>)
+	char *<[s1]>;
+	char *<[s2]>;
+
+DESCRIPTION
+	This function computes the length of the initial segment of
+	the string pointed to by <[s1]> which consists entirely of
+	characters from the string pointed to by <[s2]> (excluding the
+	terminating null character).
+
+RETURNS
+	<<strspn>> returns the length of the segment found.
+
+PORTABILITY
+<<strspn>> is ANSI C.
+
+<<strspn>> requires no supporting OS subroutines.
+
+QUICKREF
+	strspn ansi pure
+*/
+
+#include <string.h>
+
+size_t strspn(const char *s1, const char *s2)
+{
+  const char *s = s1;
+  const char *c;
+
+  while (*s1)
+    {
+      for (c = s2; *c; c++)
+	{
+	  if (*s1 == *c)
+	    break;
+	}
+      if (*c == '\0')
+	break;
+      s1++;
+    }
+
+  return s1 - s;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strstr.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strstr.c b/libs/baselibc/src/strstr.c
new file mode 100644
index 0000000..8850858
--- /dev/null
+++ b/libs/baselibc/src/strstr.c
@@ -0,0 +1,11 @@
+/*
+ * strstr.c
+ */
+
+#include <string.h>
+
+char *strstr(const char *haystack, const char *needle)
+{
+	return (char *)memmem(haystack, strlen(haystack), needle,
+			      strlen(needle));
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strtoimax.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtoimax.c b/libs/baselibc/src/strtoimax.c
new file mode 100644
index 0000000..cd4fdca
--- /dev/null
+++ b/libs/baselibc/src/strtoimax.c
@@ -0,0 +1,3 @@
+#define TYPE intmax_t
+#define NAME strtoimax
+#include "templates/strtox.c.template"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strtok.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtok.c b/libs/baselibc/src/strtok.c
new file mode 100644
index 0000000..6b169a1
--- /dev/null
+++ b/libs/baselibc/src/strtok.c
@@ -0,0 +1,12 @@
+/*
+ * strtok.c
+ */
+
+#include <string.h>
+
+char *strtok(char *s, const char *delim)
+{
+	static char *holder;
+
+	return strtok_r(s, delim, &holder);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strtok_r.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtok_r.c b/libs/baselibc/src/strtok_r.c
new file mode 100644
index 0000000..695d516
--- /dev/null
+++ b/libs/baselibc/src/strtok_r.c
@@ -0,0 +1,13 @@
+#include <string.h>
+
+char *strtok_r(char *s, const char *delim, char **holder)
+{
+	if (s)
+		*holder = s;
+
+	do {
+		s = strsep(holder, delim);
+	} while (s && !*s);
+
+	return s;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strtol.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtol.c b/libs/baselibc/src/strtol.c
new file mode 100644
index 0000000..ab318cd
--- /dev/null
+++ b/libs/baselibc/src/strtol.c
@@ -0,0 +1,3 @@
+#define TYPE signed long
+#define NAME strtol
+#include "templates/strtox.c.template"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strtoll.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtoll.c b/libs/baselibc/src/strtoll.c
new file mode 100644
index 0000000..ceb924d
--- /dev/null
+++ b/libs/baselibc/src/strtoll.c
@@ -0,0 +1,3 @@
+#define TYPE signed long long
+#define NAME strtoll
+#include "templates/strtox.c.template"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strtoul.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtoul.c b/libs/baselibc/src/strtoul.c
new file mode 100644
index 0000000..d0201e1
--- /dev/null
+++ b/libs/baselibc/src/strtoul.c
@@ -0,0 +1,3 @@
+#define TYPE unsigned long
+#define NAME strtoul
+#include "templates/strtox.c.template"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strtoull.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtoull.c b/libs/baselibc/src/strtoull.c
new file mode 100644
index 0000000..2da622a
--- /dev/null
+++ b/libs/baselibc/src/strtoull.c
@@ -0,0 +1,3 @@
+#define TYPE unsigned long long
+#define NAME strtoull
+#include "templates/strtox.c.template"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/strtoumax.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/strtoumax.c b/libs/baselibc/src/strtoumax.c
new file mode 100644
index 0000000..c49d125
--- /dev/null
+++ b/libs/baselibc/src/strtoumax.c
@@ -0,0 +1,3 @@
+#define TYPE uintmax_t
+#define NAME strtoumax
+#include "templates/strtox.c.template"

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/templates/atox.c.template
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/templates/atox.c.template b/libs/baselibc/src/templates/atox.c.template
new file mode 100644
index 0000000..c013bb4
--- /dev/null
+++ b/libs/baselibc/src/templates/atox.c.template
@@ -0,0 +1,14 @@
+/*
+ * atox.c
+ *
+ * atoi(), atol(), atoll()
+ */
+
+#include <inttypes.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+TYPE NAME(const char *nptr)
+{
+	return (TYPE) strntoumax(nptr, (char **)NULL, 10, ~(size_t) 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/templates/strtox.c.template
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/templates/strtox.c.template b/libs/baselibc/src/templates/strtox.c.template
new file mode 100644
index 0000000..c22e7c7
--- /dev/null
+++ b/libs/baselibc/src/templates/strtox.c.template
@@ -0,0 +1,14 @@
+/*
+ * strtox.c
+ *
+ * strto...() functions, by macro definition
+ */
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <inttypes.h>
+
+TYPE NAME(const char *nptr, char **endptr, int base)
+{
+	return (TYPE) strntoumax(nptr, endptr, base, ~(size_t) 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/test/printf_tests.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/test/printf_tests.c b/libs/baselibc/src/test/printf_tests.c
new file mode 100644
index 0000000..f9f380f
--- /dev/null
+++ b/libs/baselibc/src/test/printf_tests.c
@@ -0,0 +1,22 @@
+#include "unittests.h"
+
+int main()
+{
+    int status = 0;
+    
+    {
+        COMMENT("Testing basic snprintf functionality");
+        char buf[20];
+        
+        snprintf(buf, sizeof(buf), "%08d", 55);
+        TEST(strcmp(buf, "00000055") == 0);
+        
+        TEST(snprintf(buf, sizeof(buf), "01234567890123456789") == 20);
+        TEST(strcmp(buf, "0123456789012345678") == 0);
+    }
+        
+    if (status != 0)
+        fprintf(stdout, "\n\nSome tests FAILED!\n");
+
+    return status;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/b32abb57/libs/baselibc/src/test/tests_glue.c
----------------------------------------------------------------------
diff --git a/libs/baselibc/src/test/tests_glue.c b/libs/baselibc/src/test/tests_glue.c
new file mode 100644
index 0000000..b18a689
--- /dev/null
+++ b/libs/baselibc/src/test/tests_glue.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+
+#if defined(linux)
+/* Connects the baselibc stdio to normal POSIX stdio */
+size_t write(int fd, const void *buf, size_t count);
+
+static size_t stdio_write(FILE *instance, const char *bp, size_t n)
+{
+    if (instance == stdout)
+        return write(1, bp, n);
+    else
+        return write(2, bp, n);
+}
+#else
+#error No suitable write() implementation.
+#endif
+
+
+static struct File_methods stdio_methods = {
+        &stdio_write, NULL
+};
+
+static struct File _stdout = {
+        &stdio_methods
+};
+
+static struct File _stderr = {
+        &stdio_methods
+};
+
+FILE* const stdout = &_stdout;
+FILE* const stderr = &_stderr;
+