summaryrefslogtreecommitdiff
path: root/components/libc/compilers/dlib
diff options
context:
space:
mode:
Diffstat (limited to 'components/libc/compilers/dlib')
-rw-r--r--components/libc/compilers/dlib/SConscript5
-rw-r--r--components/libc/compilers/dlib/libc.c12
-rw-r--r--components/libc/compilers/dlib/libc.h2
-rw-r--r--components/libc/compilers/dlib/stdio.c12
-rw-r--r--components/libc/compilers/dlib/syscall_close.c11
-rw-r--r--components/libc/compilers/dlib/syscall_lseek.c7
-rw-r--r--components/libc/compilers/dlib/syscall_open.c12
-rw-r--r--components/libc/compilers/dlib/syscall_read.c18
-rw-r--r--components/libc/compilers/dlib/syscall_remove.c12
-rw-r--r--components/libc/compilers/dlib/syscall_write.c30
10 files changed, 46 insertions, 75 deletions
diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript
index 75a5812fab..3eee0e0184 100644
--- a/components/libc/compilers/dlib/SConscript
+++ b/components/libc/compilers/dlib/SConscript
@@ -11,7 +11,7 @@ CPPDEFINES = ['RT_USING_DLIBC']
if rtconfig.PLATFORM == 'iar':
- if GetDepend('RT_USING_DFS'):
+ if GetDepend('RT_LIBC_USING_FILEIO'):
from distutils.version import LooseVersion
from iar import IARVersion
@@ -20,7 +20,6 @@ if rtconfig.PLATFORM == 'iar':
if LooseVersion(IARVersion()) < LooseVersion("8.20.1"):
CPPDEFINES = CPPDEFINES + ['_DLIB_THREAD_SUPPORT']
- group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'],
- CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
+ group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
Return('group')
diff --git a/components/libc/compilers/dlib/libc.c b/components/libc/compilers/dlib/libc.c
index f540ac955f..f6e504bdae 100644
--- a/components/libc/compilers/dlib/libc.c
+++ b/components/libc/compilers/dlib/libc.c
@@ -7,29 +7,24 @@
* Date Author Notes
* 2017/10/15 bernard the first version
*/
-#include <fcntl.h>
#include <rtthread.h>
+#include <fcntl.h>
#include "libc.h"
-
#ifdef RT_USING_PTHREADS
#include <pthread.h>
#endif
int libc_system_init(void)
{
-#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
+#ifdef RT_USING_POSIX
rt_device_t dev_console;
dev_console = rt_console_get_device();
if (dev_console)
{
- #if defined(RT_USING_POSIX)
libc_stdio_set_console(dev_console->parent.name, O_RDWR);
- #else
- libc_stdio_set_console(dev_console->parent.name, O_WRONLY);
- #endif
}
-#endif
+#endif /* RT_USING_POSIX */
#if defined (RT_USING_PTHREADS) && !defined (RT_USING_COMPONENTS_INIT)
pthread_system_init();
@@ -38,4 +33,3 @@ int libc_system_init(void)
return 0;
}
INIT_COMPONENT_EXPORT(libc_system_init);
-
diff --git a/components/libc/compilers/dlib/libc.h b/components/libc/compilers/dlib/libc.h
index 9643c1161f..292dbde973 100644
--- a/components/libc/compilers/dlib/libc.h
+++ b/components/libc/compilers/dlib/libc.h
@@ -16,8 +16,10 @@ extern "C" {
#endif
int libc_system_init(void);
+#ifdef RT_USING_POSIX
int libc_stdio_get_console(void);
int libc_stdio_set_console(const char* device_name, int mode);
+#endif /* RT_USING_POSIX */
#ifdef __cplusplus
}
diff --git a/components/libc/compilers/dlib/stdio.c b/components/libc/compilers/dlib/stdio.c
index ed3f5dfef9..fea98aedd5 100644
--- a/components/libc/compilers/dlib/stdio.c
+++ b/components/libc/compilers/dlib/stdio.c
@@ -7,17 +7,17 @@
* Date Author Notes
* 2017/10/15 bernard implement stdio for IAR dlib.
*/
+#include <rtthread.h>
+
+#ifdef RT_USING_POSIX
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
-#include <rtthread.h>
+#include <fcntl.h>
+#include <unistd.h>
#include "libc.h"
-#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
-#include <dfs_posix.h>
-
#define STDIO_DEVICE_NAME_MAX 32
static int std_fd = -1;
@@ -46,4 +46,4 @@ int libc_stdio_get_console(void) {
return std_fd;
}
-#endif
+#endif /* RT_USING_POSIX */
diff --git a/components/libc/compilers/dlib/syscall_close.c b/components/libc/compilers/dlib/syscall_close.c
index 7ed1cc2f2d..bafe21aa4b 100644
--- a/components/libc/compilers/dlib/syscall_close.c
+++ b/components/libc/compilers/dlib/syscall_close.c
@@ -8,10 +8,8 @@
* 2015-01-28 Bernard first version
*/
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
#include <yfuns.h>
+#include <unistd.h>
#pragma module_name = "?__close"
int __close(int handle)
@@ -20,10 +18,9 @@ int __close(int handle)
handle == _LLIO_STDERR ||
handle == _LLIO_STDIN)
return _LLIO_ERROR;
-
-#ifdef RT_USING_DFS
+#ifdef RT_LIBC_USING_FILEIO
return close(handle);
#else
- return 0;
-#endif
+ return _LLIO_ERROR;
+#endif /* RT_LIBC_USING_FILEIO */
}
diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c
index 47a069bf0a..4a3a5c6a46 100644
--- a/components/libc/compilers/dlib/syscall_lseek.c
+++ b/components/libc/compilers/dlib/syscall_lseek.c
@@ -8,10 +8,8 @@
* 2015-01-28 Bernard first version
*/
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
#include <yfuns.h>
+#include <unistd.h>
#pragma module_name = "?__lseek"
long __lseek(int handle, long offset, int whence)
@@ -20,8 +18,7 @@ long __lseek(int handle, long offset, int whence)
handle == _LLIO_STDERR ||
handle == _LLIO_STDIN)
return _LLIO_ERROR;
-
-#ifdef RT_USING_DFS
+#ifdef RT_LIBC_USING_FILEIO
return lseek(handle, offset, whence);
#else
return _LLIO_ERROR;
diff --git a/components/libc/compilers/dlib/syscall_open.c b/components/libc/compilers/dlib/syscall_open.c
index 37bfcecb47..891b9afe58 100644
--- a/components/libc/compilers/dlib/syscall_open.c
+++ b/components/libc/compilers/dlib/syscall_open.c
@@ -10,17 +10,13 @@
#include <rtthread.h>
#include <yfuns.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
+#include <fcntl.h>
#pragma module_name = "?__open"
int __open(const char *filename, int mode)
{
-#ifndef RT_USING_DFS
- return _LLIO_ERROR;
-#else
+#ifdef RT_LIBC_USING_FILEIO
int handle;
int open_mode = O_RDONLY;
@@ -70,5 +66,7 @@ int __open(const char *filename, int mode)
return _LLIO_ERROR;
return handle;
-#endif
+#else
+ return _LLIO_ERROR;
+#endif /* RT_LIBC_USING_FILEIO */
}
diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c
index ae980be6ca..f65b502966 100644
--- a/components/libc/compilers/dlib/syscall_read.c
+++ b/components/libc/compilers/dlib/syscall_read.c
@@ -9,10 +9,8 @@
*/
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
#include <yfuns.h>
+#include <unistd.h>
#include "libc.h"
#define DBG_TAG "dlib.syscall_read"
@@ -22,32 +20,26 @@
#pragma module_name = "?__read"
size_t __read(int handle, unsigned char *buf, size_t len)
{
-#ifdef RT_USING_DFS
+#ifdef RT_LIBC_USING_FILEIO
int size;
-#endif
if (handle == _LLIO_STDIN)
{
-#ifdef RT_USING_POSIX
if (libc_stdio_get_console() < 0)
{
LOG_W("Do not invoke standard input before initializing libc");
return 0;
}
return read(STDIN_FILENO, buf, len);
-#else
- return _LLIO_ERROR;
-#endif
}
else if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
return _LLIO_ERROR;
}
-#ifndef RT_USING_DFS
- return _LLIO_ERROR;
-#else
size = read(handle, buf, len);
return size;
-#endif
+#else
+ return _LLIO_ERROR;
+#endif /* RT_LIBC_USING_FILEIO */
}
diff --git a/components/libc/compilers/dlib/syscall_remove.c b/components/libc/compilers/dlib/syscall_remove.c
index 7d74236f4c..05bfbb67ae 100644
--- a/components/libc/compilers/dlib/syscall_remove.c
+++ b/components/libc/compilers/dlib/syscall_remove.c
@@ -8,17 +8,15 @@
* 2015-01-28 Bernard first version
*/
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
#include <yfuns.h>
+#include <unistd.h>
#pragma module_name = "?remove"
int remove(const char *val)
{
-#ifndef RT_USING_DFS
- return -1;
-#else
+#ifdef RT_USING_POSIX
return unlink(val);
-#endif
+#else
+ return -1;
+#endif /* RT_USING_POSIX */
}
diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c
index ffee51882d..af47d64a3e 100644
--- a/components/libc/compilers/dlib/syscall_write.c
+++ b/components/libc/compilers/dlib/syscall_write.c
@@ -9,10 +9,8 @@
*/
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
#include <yfuns.h>
+#include <unistd.h>
#include "libc.h"
#define DBG_TAG "dlib.syscall_write"
@@ -23,24 +21,20 @@
size_t __write(int handle, const unsigned char *buf, size_t len)
{
-#ifdef RT_USING_DFS
+#ifdef RT_LIBC_USING_FILEIO
int size;
-#endif
+#endif /* RT_LIBC_USING_FILEIO */
if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
-#ifndef RT_USING_CONSOLE
- return _LLIO_ERROR;
-#else
-
-#ifdef RT_USING_POSIX
+#ifdef RT_LIBC_USING_FILEIO
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);
-#else
+#elif defined(RT_USING_CONSOLE)
rt_device_t console_device;
console_device = rt_console_get_device();
@@ -50,19 +44,19 @@ size_t __write(int handle, const unsigned char *buf, size_t len)
}
return len;
-#endif
-#endif
+#else
+ return _LLIO_ERROR;
+#endif /* RT_LIBC_USING_FILEIO */
}
else if (handle == _LLIO_STDIN)
{
return _LLIO_ERROR;
}
-#ifndef RT_USING_DFS
- return _LLIO_ERROR;
-#else
+#ifdef RT_LIBC_USING_FILEIO
size = write(handle, buf, len);
return size;
-#endif
+#else
+ return _LLIO_ERROR;
+#endif /* RT_LIBC_USING_FILEIO */
}
-