1
0

syscall_write.c 1.3 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. #include <LowLevelIOInterface.h>
  12. #include <unistd.h>
  13. #ifdef RT_USING_POSIX_STDIO
  14. #include "libc.h"
  15. #endif
  16. #define DBG_TAG "IAR.dlib.syscall_write"
  17. #define DBG_LVL DBG_INFO
  18. #include <rtdbg.h>
  19. #pragma module_name = "?__write"
  20. size_t __write(int handle, const unsigned char *buf, size_t len)
  21. {
  22. #ifdef RT_USING_POSIX
  23. int size;
  24. #endif /* RT_USING_POSIX */
  25. if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
  26. {
  27. #ifdef RT_USING_CONSOLE
  28. rt_device_t console_device;
  29. console_device = rt_console_get_device();
  30. if (console_device)
  31. {
  32. rt_device_write(console_device, 0, buf, len);
  33. }
  34. return len; /* return the length of the data written */
  35. #else
  36. return _LLIO_ERROR;
  37. #endif /* RT_USING_CONSOLE */
  38. }
  39. else if (handle == _LLIO_STDIN)
  40. {
  41. return _LLIO_ERROR;
  42. }
  43. else
  44. {
  45. #ifdef RT_USING_POSIX
  46. size = write(handle, buf, len);
  47. return size; /* return the length of the data written */
  48. #else
  49. return _LLIO_ERROR;
  50. #endif /* RT_USING_POSIX */
  51. }
  52. }