syscall_write.c 1.1 KB
Newer Older
B
Bernard Xiong 已提交
1
/*
2
 * Copyright (c) 2006-2021, RT-Thread Development Team
B
Bernard Xiong 已提交
3
 *
4
 * SPDX-License-Identifier: Apache-2.0
B
Bernard Xiong 已提交
5 6 7 8 9 10 11
 *
 * Change Logs:
 * Date           Author       Notes
 * 2015-01-28     Bernard      first version
 */

#include <rtthread.h>
12 13 14
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#endif
B
Bernard Xiong 已提交
15
#include <yfuns.h>
B
bernard 已提交
16
#include "libc.h"
B
Bernard Xiong 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30

#pragma module_name = "?__write"

size_t __write(int handle, const unsigned char *buf, size_t len)
{
#ifdef RT_USING_DFS
    int size;
#endif

    if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
    {
#ifndef RT_USING_CONSOLE
        return _LLIO_ERROR;
#else
B
bernard 已提交
31

B
bernard 已提交
32
#ifdef RT_USING_POSIX
33
        return write(STDOUT_FILENO, (void*)buf, len);
B
bernard 已提交
34
#else
B
Bernard Xiong 已提交
35 36 37
        rt_device_t console_device;

        console_device = rt_console_get_device();
38 39 40 41
        if (console_device != 0)
        {
            rt_device_write(console_device, 0, buf, len);
        }
B
Bernard Xiong 已提交
42 43

        return len;
B
bernard 已提交
44
#endif
B
Bernard Xiong 已提交
45 46
#endif
    }
47 48 49 50
    else if (handle == _LLIO_STDIN)
    {
        return _LLIO_ERROR;
    }
B
Bernard Xiong 已提交
51 52 53 54

#ifndef RT_USING_DFS
    return _LLIO_ERROR;
#else
B
bernard 已提交
55
    size = write(handle, buf, len);
B
Bernard Xiong 已提交
56 57 58 59
    return size;
#endif
}