syscall_write.c 1.0 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
B
bernard 已提交
33 34
        return libc_stdio_write((void*)buf, len);
#else
B
Bernard Xiong 已提交
35 36 37 38 39 40
        rt_device_t console_device;

        console_device = rt_console_get_device();
        if (console_device != 0) rt_device_write(console_device, 0, buf, len);

        return len;
B
bernard 已提交
41
#endif
B
Bernard Xiong 已提交
42 43 44
#endif
    }

B
bernard 已提交
45
    if (handle == _LLIO_STDIN) return _LLIO_ERROR;
B
Bernard Xiong 已提交
46 47 48 49

#ifndef RT_USING_DFS
    return _LLIO_ERROR;
#else
B
bernard 已提交
50
    size = write(handle, buf, len);
B
Bernard Xiong 已提交
51 52 53 54
    return size;
#endif
}