summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libc
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2000-10-18 15:02:06 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2000-10-18 15:02:06 +0000
commit3815a2b73c951c77f7e06f30837e95bcfe709ec8 (patch)
tree44233e93d730cd9b56507347947f557533ff2b21 /c/src/lib/libc
parentb541e1f8601c95c7952812ea8045cf2244848fd5 (diff)
downloadrtems-3815a2b73c951c77f7e06f30837e95bcfe709ec8.tar.bz2
2000-10-18 Joel Sherrill <joel@OARcorp.com>
* libc/Makefile.am: Added mallocfreespace.c. * libc/mallocfreespace.c: New file based on work by Nick Simon <Nick.SIMON@syntegra.bt.co.uk> which he included in malloc.c. * libc/libcsupport.h: Added prototype for malloc_free_space().
Diffstat (limited to 'c/src/lib/libc')
-rw-r--r--c/src/lib/libc/Makefile.am2
-rw-r--r--c/src/lib/libc/libcsupport.h1
-rw-r--r--c/src/lib/libc/mallocfreespace.c40
3 files changed, 42 insertions, 1 deletions
diff --git a/c/src/lib/libc/Makefile.am b/c/src/lib/libc/Makefile.am
index 56647cfe8f..b56d6f33dc 100644
--- a/c/src/lib/libc/Makefile.am
+++ b/c/src/lib/libc/Makefile.am
@@ -37,7 +37,7 @@ SYSTEM_CALL_C_FILES = open.c close.c read.c write.c lseek.c ioctl.c mkdir.c \
DIRECTORY_SCAN_C_FILES = opendir.c closedir.c readdir.c rewinddir.c \
scandir.c seekdir.c telldir.c getcwd.c
-MALLOC_C_FILES = malloc.c __brk.c __sbrk.c
+MALLOC_C_FILES = malloc.c mallocfreespace.c __brk.c __sbrk.c
PASSWORD_GROUP_C_FILES = getpwent.c getgrent.c
diff --git a/c/src/lib/libc/libcsupport.h b/c/src/lib/libc/libcsupport.h
index 4c6764c1d4..4def1e82c5 100644
--- a/c/src/lib/libc/libcsupport.h
+++ b/c/src/lib/libc/libcsupport.h
@@ -33,6 +33,7 @@ extern void malloc_walk(size_t source, size_t printf_enabled);
extern void libc_init(int reentrant);
extern int host_errno(void);
extern void fix_syscall_errno(void);
+extern size_t malloc_free_space();
#ifdef __cplusplus
}
diff --git a/c/src/lib/libc/mallocfreespace.c b/c/src/lib/libc/mallocfreespace.c
new file mode 100644
index 0000000000..28ef83278e
--- /dev/null
+++ b/c/src/lib/libc/mallocfreespace.c
@@ -0,0 +1,40 @@
+/*
+ * RTEMS Malloc Get Status Information
+ *
+ *
+ * COPYRIGHT (c) 1989-2000.
+ * On-Line Applications Research Corporation (OAR).
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.OARcorp.com/rtems/license.html.
+ *
+ * $Id$
+ */
+
+#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
+#include <rtems.h>
+#include "libcsupport.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+
+extern rtems_id RTEMS_Malloc_Heap;
+
+/*
+ * Find amount of free heap remaining
+ */
+
+size_t malloc_free_space( void )
+{
+ region_information_block heap_info;
+
+ if ( region_get_information( RTEMS_Malloc_Heap, &heap_info ) ) {
+ return (size_t) heap_info.free_size;
+ }
+ return (size_t) -1;
+}