syscall_write.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2006-2021, 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 write(STDOUT_FILENO, (void*)buf, len);
  29. #else
  30. rt_device_t console_device;
  31. console_device = rt_console_get_device();
  32. if (console_device != 0)
  33. {
  34. rt_device_write(console_device, 0, buf, len);
  35. }
  36. return len;
  37. #endif
  38. #endif
  39. }
  40. else if (handle == _LLIO_STDIN)
  41. {
  42. return _LLIO_ERROR;
  43. }
  44. #ifndef RT_USING_DFS
  45. return _LLIO_ERROR;
  46. #else
  47. size = write(handle, buf, len);
  48. return size;
  49. #endif
  50. }