xref: /nrf52832-nimble/rt-thread/components/libc/compilers/dlib/syscall_write.c (revision 104654410c56c573564690304ae786df310c91fc)
1 /*
2  * Copyright (c) 2006-2018, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2015-01-28     Bernard      first version
9  */
10 
11 #include <rtthread.h>
12 #ifdef RT_USING_DFS
13 #include <dfs_posix.h>
14 #endif
15 #include <yfuns.h>
16 #include "libc.h"
17 
18 #pragma module_name = "?__write"
19 
__write(int handle,const unsigned char * buf,size_t len)20 size_t __write(int handle, const unsigned char *buf, size_t len)
21 {
22 #ifdef RT_USING_DFS
23     int size;
24 #endif
25 
26     if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
27     {
28 #ifndef RT_USING_CONSOLE
29         return _LLIO_ERROR;
30 #else
31 
32 #ifdef RT_USING_POSIX
33         return libc_stdio_write((void*)buf, len);
34 #else
35         rt_device_t console_device;
36 
37         console_device = rt_console_get_device();
38         if (console_device != 0) rt_device_write(console_device, 0, buf, len);
39 
40         return len;
41 #endif
42 #endif
43     }
44 
45     if (handle == _LLIO_STDIN) return _LLIO_ERROR;
46 
47 #ifndef RT_USING_DFS
48     return _LLIO_ERROR;
49 #else
50     size = write(handle, buf, len);
51     return size;
52 #endif
53 }
54 
55