diff options
| author | 192.168.1.134 <[email protected]> | 2021-12-09 19:18:24 +0800 |
|---|---|---|
| committer | 192.168.1.134 <[email protected]> | 2021-12-09 19:18:24 +0800 |
| commit | 6378f95f00fd51410d2715da55d728d4a40494de (patch) | |
| tree | bb46a565875d538189e1c1dfc9b1cfddf6862a92 /components/libc/compilers/dlib/syscall_write.c | |
| parent | d6b05287bbeaf9369546009e5af445f350b97fe9 (diff) | |
| parent | 462f093cbd7531098de3b7aadb5f8d5f1b99b4a9 (diff) | |
Merge branch 'master' of https://github.com/RT-Thread/rt-thread
Diffstat (limited to 'components/libc/compilers/dlib/syscall_write.c')
| -rw-r--r-- | components/libc/compilers/dlib/syscall_write.c | 53 |
1 files changed, 29 insertions, 24 deletions
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 */ + } } |
