summaryrefslogtreecommitdiff
path: root/components/libc/compilers/dlib/syscall_read.c
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/syscall_read.c
parentd6b05287bbeaf9369546009e5af445f350b97fe9 (diff)
parent462f093cbd7531098de3b7aadb5f8d5f1b99b4a9 (diff)
Merge branch 'master' of https://github.com/RT-Thread/rt-thread
Diffstat (limited to 'components/libc/compilers/dlib/syscall_read.c')
-rw-r--r--components/libc/compilers/dlib/syscall_read.c32
1 files changed, 24 insertions, 8 deletions
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 */
}