summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-04-05 20:54:00 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-04-05 20:54:00 +0000
commit16be59858afa332cc8a0f8e61a215e1deea5e897 (patch)
tree0159742e27848cfac6eec8d9d87bd6579af48c18 /nuttx
parent3607bf2b4b1f2087cfb52ab4591f2ac347698a9c (diff)
downloadpx4-nuttx-16be59858afa332cc8a0f8e61a215e1deea5e897.tar.gz
px4-nuttx-16be59858afa332cc8a0f8e61a215e1deea5e897.tar.bz2
px4-nuttx-16be59858afa332cc8a0f8e61a215e1deea5e897.zip
Clean kernel-/user-mode module build
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3469 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/Makefile27
-rw-r--r--nuttx/arch/arm/src/common/up_createstack.c7
-rwxr-xr-xnuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h2
-rwxr-xr-xnuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c2
-rwxr-xr-xnuttx/configs/sam3u-ek/kernel/Makefile4
-rw-r--r--nuttx/fs/fs_closedir.c8
-rw-r--r--nuttx/fs/fs_fdopen.c4
-rw-r--r--nuttx/fs/fs_inode.c8
-rw-r--r--nuttx/fs/fs_inoderelease.c5
-rw-r--r--nuttx/fs/fs_inoderemove.c5
-rw-r--r--nuttx/fs/fs_inodereserve.c7
-rw-r--r--nuttx/fs/fs_opendir.c6
-rw-r--r--nuttx/fs/fs_select.c6
-rw-r--r--nuttx/lib/Makefile30
-rw-r--r--nuttx/lib/lib_internal.h34
-rw-r--r--nuttx/lib/misc/lib_init.c3
-rwxr-xr-xnuttx/lib/stdio/lib_dtoa.c5
-rw-r--r--nuttx/lib/stdio/lib_fclose.c5
-rw-r--r--nuttx/lib/string/lib_strdup.c5
-rw-r--r--nuttx/lib/unistd/lib_chdir.c2
-rw-r--r--nuttx/tools/mkconfig.c11
21 files changed, 134 insertions, 52 deletions
diff --git a/nuttx/Makefile b/nuttx/Makefile
index 30e92e135..f9cb1b782 100644
--- a/nuttx/Makefile
+++ b/nuttx/Makefile
@@ -175,7 +175,7 @@ endif
# USERLIBS is the list of libraries used to build the final user-space
# application
-NUTTXLIBS = sched/libsched$(LIBEXT) $(ARCH_SRC)/libarch$(LIBEXT) lib/liblib$(LIBEXT)
+NUTTXLIBS = sched/libsched$(LIBEXT) $(ARCH_SRC)/libarch$(LIBEXT)
USERLIBS =
# Add libraries for syscall support. The C library will be needed by
@@ -183,10 +183,10 @@ USERLIBS =
# is placed in user space (only).
ifeq ($(CONFIG_NUTTX_KERNEL),y)
-NUTTXLIBS += syscall/libstubs$(LIBEXT)
-USERLIBS += syscall/libproxies$(LIBEXT) lib/liblib$(LIBEXT) mm/libmm$(LIBEXT)
+NUTTXLIBS += syscall/libstubs$(LIBEXT) lib/libklib$(LIBEXT)
+USERLIBS += syscall/libproxies$(LIBEXT) lib/libulib$(LIBEXT) mm/libmm$(LIBEXT)
else
-NUTTXLIBS += mm/libmm$(LIBEXT)
+NUTTXLIBS += mm/libmm$(LIBEXT) lib/liblib$(LIBEXT)
endif
# Add libraries for network support. CXX, CXXFLAGS, and COMPILEXX must
@@ -246,6 +246,7 @@ NUTTXLIBS += graphics/libgraphics$(LIBEXT)
endif
# This is the name of the final target
+
BIN = nuttx$(EXEEXT)
all: $(BIN)
@@ -256,28 +257,34 @@ tools/mkconfig:
@$(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkconfig
# Create the include/nuttx/config.h file
+
include/nuttx/config.h: $(TOPDIR)/.config tools/mkconfig
tools/mkconfig $(TOPDIR) > include/nuttx/config.h
# link the arch/<arch-name>/include dir to include/arch
+
include/arch: Make.defs
@$(DIRLINK) $(TOPDIR)/$(ARCH_DIR)/include include/arch
# Link the configs/<board-name>/include dir to include/arch/board
+
include/arch/board: include/arch Make.defs include/arch
@$(DIRLINK) $(TOPDIR)/$(BOARD_DIR)/include include/arch/board
# Link the configs/<board-name>/src dir to arch/<arch-name>/src/board
+
$(ARCH_SRC)/board: Make.defs
@$(DIRLINK) $(TOPDIR)/$(BOARD_DIR)/src $(ARCH_SRC)/board
# Link arch/<arch-name>/include/<chip-name> to arch/<arch-name>/include/chip
+
$(ARCH_SRC)/chip: Make.defs
ifneq ($(CONFIG_ARCH_CHIP),)
@$(DIRLINK) $(TOPDIR)/$(ARCH_SRC)/$(CONFIG_ARCH_CHIP) $(ARCH_SRC)/chip
endif
# Link arch/<arch-name>/src/<chip-name> to arch/<arch-name>/src/chip
+
include/arch/chip: include/arch Make.defs
ifneq ($(CONFIG_ARCH_CHIP),)
@$(DIRLINK) $(TOPDIR)/$(ARCH_INC)/$(CONFIG_ARCH_CHIP) include/arch/chip
@@ -307,6 +314,9 @@ check_context:
# Possible kernel-mode builds
+lib/libklib$(LIBEXT): context
+ @$(MAKE) -C lib TOPDIR="$(TOPDIR)" libklib$(LIBEXT) EXTRADEFINES=$(KDEFINE)
+
sched/libsched$(LIBEXT): context
@$(MAKE) -C sched TOPDIR="$(TOPDIR)" libsched$(LIBEXT) EXTRADEFINES=$(KDEFINE)
@@ -336,8 +346,8 @@ syscall/libstubs$(LIBEXT): context
# Possible user-mode builds
-lib/liblib$(LIBEXT): context
- @$(MAKE) -C lib TOPDIR="$(TOPDIR)" liblib$(LIBEXT)
+lib/libulib$(LIBEXT): context
+ @$(MAKE) -C lib TOPDIR="$(TOPDIR)" libulib$(LIBEXT)
libxx/liblibxx$(LIBEXT): context
@$(MAKE) -C libxx TOPDIR="$(TOPDIR)" liblibxx$(LIBEXT)
@@ -351,6 +361,11 @@ $(APPDIR)/libapps$(LIBEXT): context
syscall/libproxies$(LIBEXT): context
@$(MAKE) -C syscall TOPDIR="$(TOPDIR)" libproxies$(LIBEXT)
+# Possible non-kernel builds
+
+lib/liblib$(LIBEXT): context
+ @$(MAKE) -C lib TOPDIR="$(TOPDIR)" liblib$(LIBEXT)
+
# If the 2 pass build option is selected, then this pass1 target is
# configured to built before the pass2 target. This pass1 target may, as an
# example, build an extra link object (CONFIG_PASS1_OBJECT) which may be an
diff --git a/nuttx/arch/arm/src/common/up_createstack.c b/nuttx/arch/arm/src/common/up_createstack.c
index 0c9f0809f..6b8094b5b 100644
--- a/nuttx/arch/arm/src/common/up_createstack.c
+++ b/nuttx/arch/arm/src/common/up_createstack.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/arm/src/common/up_createstack.c
*
- * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,6 @@
#include <sys/types.h>
#include <stdint.h>
-#include <stdlib.h>
#include <sched.h>
#include <debug.h>
@@ -97,9 +96,9 @@ int up_create_stack(_TCB *tcb, size_t stack_size)
if (!tcb->stack_alloc_ptr)
{
#ifdef CONFIG_DEBUG
- tcb->stack_alloc_ptr = (uint32_t*)zalloc(stack_size);
+ tcb->stack_alloc_ptr = (uint32_t*)kzalloc(stack_size);
#else
- tcb->stack_alloc_ptr = (uint32_t*)malloc(stack_size);
+ tcb->stack_alloc_ptr = (uint32_t*)kmalloc(stack_size);
#endif
}
diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h b/nuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h
index 7a08f7445..7601fefca 100755
--- a/nuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h
+++ b/nuttx/arch/arm/src/lpc17xx/lpc17_ohciram.h
@@ -197,7 +197,7 @@
* Configuration:
* CONFIG_USBHOST_OHCIRAM_SIZE 1536
* CONFIG_USBHOST_NEDS 2
- * CONFIG_USBHOST_NEDS 3
+ * CONFIG_USBHOST_NTDS 3
* CONFIG_USBHOST_TDBUFFERS 3
* CONFIG_USBHOST_TDBUFSIZE 128
* CONFIG_USBHOST_IOBUFSIZE 512
diff --git a/nuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c b/nuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c
index 86457bf40..17a14fea8 100755
--- a/nuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c
+++ b/nuttx/arch/arm/src/lpc17xx/lpc17_usbhost.c
@@ -2596,7 +2596,7 @@ FAR struct usbhost_driver_s *usbhost_initialize(int controller)
/* Initialize user-configurable request/descriptor transfer buffers */
buffer = (uint8_t *)LPC17_TBFREE_BASE;
- for (i = 0; i < CONFIG_USBHOST_NEDS; i++)
+ for (i = 0; i < CONFIG_USBHOST_TDBUFFERS; i++)
{
/* Put the TD buffer in a free list */
diff --git a/nuttx/configs/sam3u-ek/kernel/Makefile b/nuttx/configs/sam3u-ek/kernel/Makefile
index 688ad0e62..4c1810503 100755
--- a/nuttx/configs/sam3u-ek/kernel/Makefile
+++ b/nuttx/configs/sam3u-ek/kernel/Makefile
@@ -66,17 +66,19 @@ all: $(TOPDIR)/nuttx_user.elf $(TOPDIR)/User.map $(BOARD_INCLUDE)/user_map.h
# Create the nuttx_user.elf file containing all of the user-mode code
nuttx_user.elf:
- @echo "LD: nuttx_user.elf"
@$(LD) -o $@ $(USER_LDFLAGS) $(USER_LIBPATHS) --start-group $(USER_LDLIBS) --end-group $(USER_LIBGCC)
$(TOPDIR)/nuttx_user.elf: nuttx_user.elf
+ @echo "LD: nuttx_user.elf"
@cp -a nuttx_user.elf $(TOPDIR)/nuttx_user.elf
$(TOPDIR)/User.map: nuttx_user.elf
+ @echo "MK: User.map"
@$(NM) nuttx_user.elf >$(TOPDIR)/User.map
@$(CROSSDEV)size nuttx_user.elf
$(BOARD_INCLUDE)/user_map.h: $(TOPDIR)/User.map
+ @echo "MK: user_map.h"
@echo "/* configs/$(CONFIG_ARCH_BOARD)/include/user_map.h" > $(BOARD_INCLUDE)/user_map.h
@echo " *" >> $(BOARD_INCLUDE)/user_map.h
@echo " * This is an auto-generated file.. Do not edit this file!" >> $(BOARD_INCLUDE)/user_map.h
diff --git a/nuttx/fs/fs_closedir.c b/nuttx/fs/fs_closedir.c
index bfc4f5249..d88bc3347 100644
--- a/nuttx/fs/fs_closedir.c
+++ b/nuttx/fs/fs_closedir.c
@@ -39,10 +39,10 @@
#include <nuttx/config.h>
-#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
+#include <nuttx/kmalloc.h>
#include <nuttx/fs.h>
#include <nuttx/dirent.h>
@@ -134,17 +134,17 @@ int closedir(FAR DIR *dirp)
/* Then release the container */
- free(idir);
+ kfree(idir);
return OK;
#ifndef CONFIG_DISABLE_MOUNTPOINT
errout_with_inode:
inode_release(inode);
- free(idir);
+ kfree(idir);
#endif
errout:
- *get_errno_ptr() = ret;
+ errno = ret;
return ERROR;
}
diff --git a/nuttx/fs/fs_fdopen.c b/nuttx/fs/fs_fdopen.c
index d0a44f9e8..9445e97fa 100644
--- a/nuttx/fs/fs_fdopen.c
+++ b/nuttx/fs/fs_fdopen.c
@@ -40,12 +40,12 @@
#include <nuttx/config.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include <semaphore.h>
#include <fcntl.h>
#include <errno.h>
+#include <nuttx/kmalloc.h>
#include <nuttx/fs.h>
/****************************************************************************
@@ -145,7 +145,7 @@ FAR struct file_struct *fs_fdopen(int fd, int oflags, FAR _TCB *tcb)
/* Allocate the IO buffer */
- stream->fs_bufstart = malloc(CONFIG_STDIO_BUFFER_SIZE);
+ stream->fs_bufstart = kmalloc(CONFIG_STDIO_BUFFER_SIZE);
if (!stream)
{
err = ENOMEM;
diff --git a/nuttx/fs/fs_inode.c b/nuttx/fs/fs_inode.c
index f0d6b6948..6bbdea287 100644
--- a/nuttx/fs/fs_inode.c
+++ b/nuttx/fs/fs_inode.c
@@ -1,7 +1,7 @@
/****************************************************************************
- * fs_inode.c
+ * fs/fs_inode.c
*
- * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -179,7 +179,7 @@ void inode_semtake(void)
* the wait was awakened by a signal.
*/
- ASSERT(*get_errno_ptr() == EINTR);
+ ASSERT(errno == EINTR);
}
}
@@ -308,7 +308,7 @@ void inode_free(FAR struct inode *node)
{
inode_free(node->i_peer);
inode_free(node->i_child);
- free(node);
+ kfree(node);
}
}
diff --git a/nuttx/fs/fs_inoderelease.c b/nuttx/fs/fs_inoderelease.c
index db114c936..58aaf3659 100644
--- a/nuttx/fs/fs_inoderelease.c
+++ b/nuttx/fs/fs_inoderelease.c
@@ -39,8 +39,9 @@
#include <nuttx/config.h>
-#include <stdlib.h>
#include <errno.h>
+
+#include <nuttx/kmalloc.h>
#include <nuttx/fs.h>
#include "fs_internal.h"
@@ -95,7 +96,7 @@ void inode_release(FAR struct inode *node)
{
inode_semgive();
inode_free(node->i_child);
- free(node);
+ kfree(node);
}
else
{
diff --git a/nuttx/fs/fs_inoderemove.c b/nuttx/fs/fs_inoderemove.c
index ff8dcc2ee..cdc61f66a 100644
--- a/nuttx/fs/fs_inoderemove.c
+++ b/nuttx/fs/fs_inoderemove.c
@@ -39,8 +39,9 @@
#include <nuttx/config.h>
-#include <stdlib.h>
#include <errno.h>
+
+#include <nuttx/kmalloc.h>
#include <nuttx/fs.h>
#include "fs_internal.h"
@@ -144,7 +145,7 @@ int inode_remove(const char *path)
/* And delete it now -- recursively to delete all of its children */
inode_free(node->i_child);
- free(node);
+ kfree(node);
return OK;
}
}
diff --git a/nuttx/fs/fs_inodereserve.c b/nuttx/fs/fs_inodereserve.c
index f38e349bc..da73b0ac9 100644
--- a/nuttx/fs/fs_inodereserve.c
+++ b/nuttx/fs/fs_inodereserve.c
@@ -1,7 +1,7 @@
/****************************************************************************
* fs/fs_registerreserve.c
*
- * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -39,8 +39,9 @@
#include <nuttx/config.h>
-#include <stdlib.h>
#include <errno.h>
+
+#include <nuttx/kmalloc.h>
#include <nuttx/fs.h>
#include "fs_internal.h"
@@ -89,7 +90,7 @@ static void inode_namecpy(char *dest, const char *src)
static FAR struct inode *inode_alloc(const char *name)
{
int namelen = inode_namelen(name);
- FAR struct inode *node = (FAR struct inode*)zalloc(FSNODE_SIZE(namelen));
+ FAR struct inode *node = (FAR struct inode*)kzalloc(FSNODE_SIZE(namelen));
if (node)
{
inode_namecpy(node->i_name, name);
diff --git a/nuttx/fs/fs_opendir.c b/nuttx/fs/fs_opendir.c
index 0b164734b..b0aae94f6 100644
--- a/nuttx/fs/fs_opendir.c
+++ b/nuttx/fs/fs_opendir.c
@@ -39,13 +39,13 @@
#include <nuttx/config.h>
-#include <stdlib.h>
#include <stdbool.h>
#include <dirent.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
+#include <nuttx/kmalloc.h>
#include <nuttx/fs.h>
#include <nuttx/dirent.h>
@@ -235,7 +235,7 @@ FAR DIR *opendir(FAR const char *path)
* container.
*/
- dir = (FAR struct fs_dirent_s *)zalloc(sizeof(struct fs_dirent_s));
+ dir = (FAR struct fs_dirent_s *)kzalloc(sizeof(struct fs_dirent_s));
if (!dir)
{
/* Insufficient memory to complete the operation.*/
@@ -306,7 +306,7 @@ FAR DIR *opendir(FAR const char *path)
/* Nasty goto's make error handling simpler */
errout_with_direntry:
- free(dir);
+ kfree(dir);
errout_with_semaphore:
inode_semgive();
diff --git a/nuttx/fs/fs_select.c b/nuttx/fs/fs_select.c
index 57f5c36fe..213530e44 100644
--- a/nuttx/fs/fs_select.c
+++ b/nuttx/fs/fs_select.c
@@ -41,7 +41,6 @@
#include <sys/select.h>
-#include <stdlib.h>
#include <string.h>
#include <poll.h>
#include <time.h>
@@ -49,6 +48,7 @@
#include <assert.h>
#include <debug.h>
+#include <nuttx/kmalloc.h>
#include <nuttx/fs.h>
#include "fs_internal.h"
@@ -111,7 +111,7 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds,
/* Allocate the descriptor list for poll() */
- pollset = (struct pollfd *)zalloc(nfds * sizeof(struct pollfd));
+ pollset = (struct pollfd *)kzalloc(nfds * sizeof(struct pollfd));
if (!pollset)
{
errno = ENOMEM;
@@ -208,7 +208,7 @@ int select(int nfds, FAR fd_set *readfds, FAR fd_set *writefds,
}
}
- free(pollset);
+ kfree(pollset);
return ret;
}
diff --git a/nuttx/lib/Makefile b/nuttx/lib/Makefile
index 54ba764ff..2484fc3bf 100644
--- a/nuttx/lib/Makefile
+++ b/nuttx/lib/Makefile
@@ -80,7 +80,9 @@ QUEUEDEPPATH = --dep-path queue
MISCDEPPATH = --dep-path misc
VPATH = stdio:stdlib:unistd:sched:string:pthread:semaphore:signal:mqueue:math:net:time:libgen:queue:misc
-BIN = liblib$(LIBEXT)
+UBIN = libulib$(LIBEXT)
+KBIN = libklib$(LIBEXT)
+BIN = liblib$(LIBEXT)
all: $(BIN)
@@ -95,6 +97,22 @@ $(BIN): $(OBJS)
$(call ARCHIVE, $@, $${obj}); \
done ; )
+ifneq ($(BIN),$(UBIN))
+.userlib:
+ @$(MAKE) $(UBIN) BIN=$(UBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
+ @touch .userlib
+
+$(UBIN): kclean .userlib
+endif
+
+ifneq ($(BIN),$(KBIN))
+.kernlib:
+ @$(MAKE) $(KBIN) BIN=$(KBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
+ @touch .kernlib
+
+$(KBIN): uclean .kernlib
+endif
+
.depend: Makefile $(SRCS)
@$(MKDEP) $(ROOTDEPPATH) $(STDIODEPPATH) $(STDLIBDEPPATH) \
$(UNISTDDEPPATH) $(SCHEDDEPPATH) $(STRINGDEPPATH) $(PTHREADDEPPATH) \
@@ -105,7 +123,15 @@ $(BIN): $(OBJS)
depend: .depend
-clean:
+uclean:
+ @rm -f $(UBIN) .userlib *~ .*.swp
+ $(call CLEAN)
+
+kclean:
+ @rm -f $(KBIN) .kernlib *~ .*.swp
+ $(call CLEAN)
+
+clean: uclean kclean
@rm -f $(BIN) *~ .*.swp
$(call CLEAN)
diff --git a/nuttx/lib/lib_internal.h b/nuttx/lib/lib_internal.h
index 6ec2fe201..b9c74304e 100644
--- a/nuttx/lib/lib_internal.h
+++ b/nuttx/lib/lib_internal.h
@@ -1,7 +1,7 @@
/****************************************************************************
* lib/lib_internal.h
*
- * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,7 @@
#include <stdio.h>
#include <limits.h>
#include <semaphore.h>
+
#include <nuttx/streams.h>
/****************************************************************************
@@ -57,10 +58,35 @@
# define CONFIG_LIB_HOMEDIR "/"
#endif
+/* If C std I/O buffering is not supported, then we don't need its semaphore
+ * protection.
+ */
+
#if CONFIG_STDIO_BUFFER_SIZE <= 0
-# define lib_sem_initialize(s)
-# define lib_take_semaphore(s)
-# define lib_give_semaphore(s)
+# define lib_sem_initialize(s)
+# define lib_take_semaphore(s)
+# define lib_give_semaphore(s)
+#endif
+
+/* The NuttX C library an be build in two modes: (1) as a standard, C-libary
+ * that can be used by normal, user-space applications, or (2) as a special,
+ * kernel-mode C-library only used within the OS. If NuttX is not being
+ * built as separated kernel- and user-space modules, then only the first
+ * mode is supported.
+ */
+
+#if defined(CONFIG_NUTTX_KERNEL) && defined(__KERNEL__)
+# include <nuttx/kmalloc.h>
+# define lib_malloc(s) kmalloc(s)
+# define lib_zalloc(s) kzalloc(s)
+# define lib_realloc(p,s) krealloc(p,s)
+# define lib_free(p) kfree(p)
+#else
+# include <stdlib.h>
+# define lib_malloc(s) malloc(s)
+# define lib_zalloc(s) zalloc(s)
+# define lib_realloc(p,s) realloc(p,s)
+# define lib_free(p) free(p)
#endif
#define LIB_BUFLEN_UNKNOWN INT_MAX
diff --git a/nuttx/lib/misc/lib_init.c b/nuttx/lib/misc/lib_init.c
index 107c73c07..112b0a3c7 100644
--- a/nuttx/lib/misc/lib_init.c
+++ b/nuttx/lib/misc/lib_init.c
@@ -40,7 +40,6 @@
#include <nuttx/config.h>
#include <stdio.h>
-#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -83,7 +82,7 @@ void weak_const_function lib_initialize(void)
FAR struct streamlist *lib_alloclist(void)
{
FAR struct streamlist *list;
- list = (FAR struct streamlist*)zalloc(sizeof(struct streamlist));
+ list = (FAR struct streamlist*)lib_zalloc(sizeof(struct streamlist));
if (list)
{
int i;
diff --git a/nuttx/lib/stdio/lib_dtoa.c b/nuttx/lib/stdio/lib_dtoa.c
index 942ed2033..894af4f42 100755
--- a/nuttx/lib/stdio/lib_dtoa.c
+++ b/nuttx/lib/stdio/lib_dtoa.c
@@ -45,10 +45,11 @@
#include <nuttx/config.h>
-#include <stdlib.h>
#include <stdint.h>
#include <string.h>
+#include "lib_internal.h"
+
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -142,7 +143,7 @@ static Bigint *Balloc(int k)
else
{
x = 1 << k;
- rv = (Bigint *) malloc(sizeof(Bigint) + (x - 1) * sizeof(long));
+ rv = (Bigint *)lib_malloc(sizeof(Bigint) + (x - 1) * sizeof(long));
rv->k = k;
rv->maxwds = x;
}
diff --git a/nuttx/lib/stdio/lib_fclose.c b/nuttx/lib/stdio/lib_fclose.c
index 4a9ded90b..8d53b387b 100644
--- a/nuttx/lib/stdio/lib_fclose.c
+++ b/nuttx/lib/stdio/lib_fclose.c
@@ -39,12 +39,13 @@
#include <nuttx/config.h>
-#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include "lib_internal.h"
+
/****************************************************************************
* Global Functions
****************************************************************************/
@@ -68,7 +69,7 @@ int fclose(FAR FILE *stream)
if (stream->fs_bufstart)
{
- free(stream->fs_bufstart);
+ lib_free(stream->fs_bufstart);
}
/* Clear the whole structure */
diff --git a/nuttx/lib/string/lib_strdup.c b/nuttx/lib/string/lib_strdup.c
index 04ecaffbe..a353c629d 100644
--- a/nuttx/lib/string/lib_strdup.c
+++ b/nuttx/lib/string/lib_strdup.c
@@ -39,9 +39,10 @@
#include <nuttx/config.h>
-#include <stdlib.h>
#include <string.h>
+#include "lib_internal.h"
+
/************************************************************************
* Global Functions
************************************************************************/
@@ -51,7 +52,7 @@ FAR char *strdup(const char *s)
FAR char *news = NULL;
if (s)
{
- news = (FAR char*)malloc(strlen(s) + 1);
+ news = (FAR char*)lib_malloc(strlen(s) + 1);
if (news)
{
strcpy(news, s);
diff --git a/nuttx/lib/unistd/lib_chdir.c b/nuttx/lib/unistd/lib_chdir.c
index c054f2b23..f79b424ff 100644
--- a/nuttx/lib/unistd/lib_chdir.c
+++ b/nuttx/lib/unistd/lib_chdir.c
@@ -164,7 +164,7 @@ int chdir(FAR const char *path)
alloc = strdup(oldpwd); /* kludge needed because environment is realloc'ed */
setenv("OLDPWD", alloc, TRUE);
- free(alloc);
+ lib_free(alloc);
/* Set the cwd to the input 'path' */
diff --git a/nuttx/tools/mkconfig.c b/nuttx/tools/mkconfig.c
index ff02a58c0..cee430cd6 100644
--- a/nuttx/tools/mkconfig.c
+++ b/nuttx/tools/mkconfig.c
@@ -1,7 +1,7 @@
/****************************************************************************
* tools/mkconfig.c
*
- * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -288,6 +288,15 @@ int main(int argc, char **argv, char **envp)
printf("# undef CONFIG_STDIO_BUFFER_SIZE\n");
printf("# define CONFIG_STDIO_BUFFER_SIZE 0\n");
printf("#endif\n\n");
+ printf("/* We are building a kernel version of the C library, then some user-space features\n");
+ printf(" * need to be disabled\n");
+ printf(" */\n\n");
+ printf("#if defined(CONFIG_NUTTX_KERNEL) && defined(__KERNEL__)\n");
+ printf("# undef CONFIG_STDIO_BUFFER_SIZE\n");
+ printf("# define CONFIG_STDIO_BUFFER_SIZE 0\n");
+ printf("# undef CONFIG_NUNGET_CHARS\n");
+ printf("# define CONFIG_NUNGET_CHARS 0\n");
+ printf("#endif\n\n");
printf("/* If the maximum message size is zero, then we assume that message queues\n");
printf(" * support should be disabled\n");
printf(" */\n\n");