1
0

syscall_write.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #include <rtthread.h>
  11. #ifdef RT_USING_DFS
  12. #include <dfs_posix.h>
  13. #endif
  14. #include <yfuns.h>
  15. #include "libc.h"
  16. #pragma module_name = "?__write"
  17. size_t __write(int handle, const unsigned char *buf, size_t len)
  18. {
  19. #ifdef RT_USING_DFS
  20. int size;
  21. #endif
  22. if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
  23. {
  24. #ifndef RT_USING_CONSOLE
  25. return _LLIO_ERROR;
  26. #else
  27. #ifdef RT_USING_POSIX
  28. return libc_stdio_write((void*)buf, len);
  29. #else
  30. rt_device_t console_device;
  31. console_device = rt_console_get_device();
  32. if (console_device != 0) rt_device_write(console_device, 0, buf, len);
  33. return len;
  34. #endif
  35. #endif
  36. }
  37. if (handle == _LLIO_STDIN) return _LLIO_ERROR;
  38. #ifndef RT_USING_DFS
  39. return _LLIO_ERROR;
  40. #else
  41. size = write(handle, buf, len);
  42. return size;
  43. #endif
  44. }