summaryrefslogtreecommitdiff
path: root/components/libc/compilers/dlib
diff options
context:
space:
mode:
author192.168.1.134 <[email protected]>2021-12-09 19:18:24 +0800
committer192.168.1.134 <[email protected]>2021-12-09 19:18:24 +0800
commit6378f95f00fd51410d2715da55d728d4a40494de (patch)
treebb46a565875d538189e1c1dfc9b1cfddf6862a92 /components/libc/compilers/dlib
parentd6b05287bbeaf9369546009e5af445f350b97fe9 (diff)
parent462f093cbd7531098de3b7aadb5f8d5f1b99b4a9 (diff)
Merge branch 'master' of https://github.com/RT-Thread/rt-thread
Diffstat (limited to 'components/libc/compilers/dlib')
-rw-r--r--components/libc/compilers/dlib/SConscript2
-rw-r--r--components/libc/compilers/dlib/syscall_close.c12
-rw-r--r--components/libc/compilers/dlib/syscall_lseek.c21
-rw-r--r--components/libc/compilers/dlib/syscall_mem.c38
-rw-r--r--components/libc/compilers/dlib/syscall_open.c11
-rw-r--r--components/libc/compilers/dlib/syscall_read.c32
-rw-r--r--components/libc/compilers/dlib/syscall_remove.c18
-rw-r--r--components/libc/compilers/dlib/syscall_write.c53
8 files changed, 134 insertions, 53 deletions
diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript
index 39707abc61..f685873e16 100644
--- a/components/libc/compilers/dlib/SConscript
+++ b/components/libc/compilers/dlib/SConscript
@@ -7,7 +7,7 @@ group = []
CPPDEFINES = ['RT_USING_DLIBC']
if rtconfig.PLATFORM == 'iar':
- if GetDepend('RT_USING_POSIX'):
+ if GetDepend('DFS_USING_POSIX'):
from distutils.version import LooseVersion
from iar import IARVersion
diff --git a/components/libc/compilers/dlib/syscall_close.c b/components/libc/compilers/dlib/syscall_close.c
index 2897c2418a..30ee6f2388 100644
--- a/components/libc/compilers/dlib/syscall_close.c
+++ b/components/libc/compilers/dlib/syscall_close.c
@@ -8,19 +8,25 @@
* 2015-01-28 Bernard first version
*/
#include <rtthread.h>
-#include <yfuns.h>
+#include <LowLevelIOInterface.h>
#include <unistd.h>
+/*
+ * The "__close" function should close the file corresponding to
+ * "handle". It should return 0 on success and nonzero on failure.
+ */
+
#pragma module_name = "?__close"
+
int __close(int handle)
{
if (handle == _LLIO_STDOUT ||
handle == _LLIO_STDERR ||
handle == _LLIO_STDIN)
return _LLIO_ERROR;
-#ifdef RT_USING_POSIX
+#ifdef DFS_USING_POSIX
return close(handle);
#else
return _LLIO_ERROR;
-#endif /* RT_USING_POSIX */
+#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c
index 4ea55ef1c3..622f613c51 100644
--- a/components/libc/compilers/dlib/syscall_lseek.c
+++ b/components/libc/compilers/dlib/syscall_lseek.c
@@ -8,19 +8,34 @@
* 2015-01-28 Bernard first version
*/
#include <rtthread.h>
-#include <yfuns.h>
+#include <LowLevelIOInterface.h>
#include <unistd.h>
+/*
+ * The "__lseek" function makes the next file operation (__read or
+ * __write) act on a new location. The parameter "whence" specifies
+ * how the "offset" parameter should be interpreted according to the
+ * following table:
+ *
+ * 0 (=SEEK_SET) - Goto location "offset".
+ * 1 (=SEEK_CUR) - Go "offset" bytes from the current location.
+ * 2 (=SEEK_END) - Go to "offset" bytes from the end.
+ *
+ * This function should return the current file position, or -1 on
+ * failure.
+ */
+
#pragma module_name = "?__lseek"
+
long __lseek(int handle, long offset, int whence)
{
if (handle == _LLIO_STDOUT ||
handle == _LLIO_STDERR ||
handle == _LLIO_STDIN)
return _LLIO_ERROR;
-#ifdef RT_USING_POSIX
+#ifdef DFS_USING_POSIX
return lseek(handle, offset, whence);
#else
return _LLIO_ERROR;
-#endif /* RT_USING_POSIX */
+#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_mem.c b/components/libc/compilers/dlib/syscall_mem.c
index 9c6de64455..74b960f0b9 100644
--- a/components/libc/compilers/dlib/syscall_mem.c
+++ b/components/libc/compilers/dlib/syscall_mem.c
@@ -6,27 +6,55 @@
* Change Logs:
* Date Author Notes
* 2015-01-28 Bernard first version
+ * 2021-11-13 Meco Man implement no-heap warning
*/
#include <rtthread.h>
+#include <stddef.h>
-#ifdef RT_USING_HEAP
-void *malloc(rt_size_t n)
+#ifndef RT_USING_HEAP
+#define DBG_TAG "dlib.syscall_mem"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\
+ RT_ASSERT(0);\
+ }while(0)
+#endif /* RT_USING_HEAP */
+
+void *malloc(size_t n)
{
+#ifdef RT_USING_HEAP
return rt_malloc(n);
+#else
+ _NO_HEAP_ERROR();
+ return RT_NULL;
+#endif
}
-void *realloc(void *rmem, rt_size_t newsize)
+void *realloc(void *rmem, size_t newsize)
{
+#ifdef RT_USING_HEAP
return rt_realloc(rmem, newsize);
+#else
+ _NO_HEAP_ERROR();
+ return RT_NULL;
+#endif
}
-void *calloc(rt_size_t nelem, rt_size_t elsize)
+void *calloc(size_t nelem, size_t elsize)
{
+#ifdef RT_USING_HEAP
return rt_calloc(nelem, elsize);
+#else
+ _NO_HEAP_ERROR();
+ return RT_NULL;
+#endif
}
void free(void *rmem)
{
+#ifdef RT_USING_HEAP
rt_free(rmem);
-}
+#else
+ _NO_HEAP_ERROR();
#endif
+}
diff --git a/components/libc/compilers/dlib/syscall_open.c b/components/libc/compilers/dlib/syscall_open.c
index 8fb3c3a11f..66cddc83c1 100644
--- a/components/libc/compilers/dlib/syscall_open.c
+++ b/components/libc/compilers/dlib/syscall_open.c
@@ -9,14 +9,19 @@
*/
#include <rtthread.h>
-#include <yfuns.h>
+#include <LowLevelIOInterface.h>
#include <fcntl.h>
+/*
+ * The "__open" function opens the file named "filename" as specified
+ * by "mode".
+ */
+
#pragma module_name = "?__open"
int __open(const char *filename, int mode)
{
-#ifdef RT_USING_POSIX
+#ifdef DFS_USING_POSIX
int handle;
int open_mode = O_RDONLY;
@@ -68,5 +73,5 @@ int __open(const char *filename, int mode)
return handle;
#else
return _LLIO_ERROR;
-#endif /* RT_USING_POSIX */
+#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c
index c926c577b5..62bc05d243 100644
--- a/components/libc/compilers/dlib/syscall_read.c
+++ b/components/libc/compilers/dlib/syscall_read.c
@@ -9,30 +9,46 @@
*/
#include <rtthread.h>
-#include <yfuns.h>
+#include <LowLevelIOInterface.h>
#include <unistd.h>
-#ifdef RT_USING_POSIX_STDIO
+#ifdef RT_USING_POSIX_DEVIO
#include "libc.h"
-#endif
+#endif /* RT_USING_POSIX_DEVIO */
#define DBG_TAG "dlib.syscall_read"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
+/*
+ * The "__read" function reads a number of bytes, at most "size" into
+ * the memory area pointed to by "buffer". It returns the number of
+ * bytes read, 0 at the end of the file, or _LLIO_ERROR if failure
+ * occurs.
+ *
+ * The template implementation below assumes that the application
+ * provides the function "MyLowLevelGetchar". It should return a
+ * character value, or -1 on failure.
+ */
+
#pragma module_name = "?__read"
+
size_t __read(int handle, unsigned char *buf, size_t len)
{
-#ifdef RT_USING_POSIX_STDIO
+#ifdef DFS_USING_POSIX
int size;
if (handle == _LLIO_STDIN)
{
+#ifdef RT_USING_POSIX_DEVIO
if (libc_stdio_get_console() < 0)
{
LOG_W("Do not invoke standard input before initializing libc");
- return 0;
+ return 0; /* error, but keep going */
}
- return read(STDIN_FILENO, buf, len);
+ return read(STDIN_FILENO, buf, len); /* return the length of the data read */
+#else
+ return _LLIO_ERROR;
+#endif /* RT_USING_POSIX_DEVIO */
}
else if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
@@ -40,8 +56,8 @@ size_t __read(int handle, unsigned char *buf, size_t len)
}
size = read(handle, buf, len);
- return size;
+ return size; /* return the length of the data read */
#else
return _LLIO_ERROR;
-#endif /* RT_USING_POSIX */
+#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_remove.c b/components/libc/compilers/dlib/syscall_remove.c
index 05bfbb67ae..870f91b8c1 100644
--- a/components/libc/compilers/dlib/syscall_remove.c
+++ b/components/libc/compilers/dlib/syscall_remove.c
@@ -8,15 +8,21 @@
* 2015-01-28 Bernard first version
*/
#include <rtthread.h>
-#include <yfuns.h>
+#include <LowLevelIOInterface.h>
#include <unistd.h>
+/*
+ * The "remove" function should remove the file named "filename". It
+ * should return 0 on success and nonzero on failure.
+ */
+
#pragma module_name = "?remove"
-int remove(const char *val)
+
+int remove(const char *filename)
{
-#ifdef RT_USING_POSIX
- return unlink(val);
+#ifdef DFS_USING_POSIX
+ return unlink(filename);
#else
- return -1;
-#endif /* RT_USING_POSIX */
+ return _LLIO_ERROR;
+#endif /* DFS_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c
index 72bac6ba49..2bc5863d8a 100644
--- a/components/libc/compilers/dlib/syscall_write.c
+++ b/components/libc/compilers/dlib/syscall_write.c
@@ -9,56 +9,61 @@
*/
#include <rtthread.h>
-#include <yfuns.h>
+#include <LowLevelIOInterface.h>
#include <unistd.h>
-#ifdef RT_USING_POSIX_STDIO
-#include "libc.h"
-#endif
-
#define DBG_TAG "dlib.syscall_write"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
+/*
+ * The "__write" function should output "size" number of bytes from
+ * "buffer" in some application-specific way. It should return the
+ * number of characters written, or _LLIO_ERROR on failure.
+ *
+ * If "buffer" is zero then __write should perform flushing of
+ * internal buffers, if any. In this case "handle" can be -1 to
+ * indicate that all handles should be flushed.
+ *
+ * The template implementation below assumes that the application
+ * provides the function "MyLowLevelPutchar". It should return the
+ * character written, or -1 on failure.
+ */
+
#pragma module_name = "?__write"
size_t __write(int handle, const unsigned char *buf, size_t len)
{
-#ifdef RT_USING_POSIX
+#ifdef DFS_USING_POSIX
int size;
-#endif /* RT_USING_POSIX */
+#endif /* DFS_USING_POSIX */
if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
-#ifdef RT_USING_POSIX_STDIO
- if (libc_stdio_get_console() < 0)
- {
- LOG_W("Do not invoke standard output before initializing libc");
- return 0;
- }
- return write(STDOUT_FILENO, (void*)buf, len);
-#elif defined(RT_USING_CONSOLE)
+#ifdef RT_USING_CONSOLE
rt_device_t console_device;
console_device = rt_console_get_device();
- if (console_device != 0)
+ if (console_device)
{
rt_device_write(console_device, 0, buf, len);
}
- return len;
+ return len; /* return the length of the data written */
#else
return _LLIO_ERROR;
-#endif /* RT_USING_POSIX */
+#endif /* RT_USING_CONSOLE */
}
else if (handle == _LLIO_STDIN)
{
return _LLIO_ERROR;
}
-
-#ifdef RT_USING_POSIX
- size = write(handle, buf, len);
- return size;
+ else
+ {
+#ifdef DFS_USING_POSIX
+ size = write(handle, buf, len);
+ return size; /* return the length of the data written */
#else
- return _LLIO_ERROR;
-#endif /* RT_USING_POSIX */
+ return _LLIO_ERROR;
+#endif /* DFS_USING_POSIX */
+ }
}