syscall_read.c 982 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 <yfuns.h>
  12. #include <unistd.h>
  13. #include "libc.h"
  14. #define DBG_TAG "dlib.syscall_read"
  15. #define DBG_LVL DBG_INFO
  16. #include <rtdbg.h>
  17. #pragma module_name = "?__read"
  18. size_t __read(int handle, unsigned char *buf, size_t len)
  19. {
  20. #ifdef RT_LIBC_USING_FILEIO
  21. int size;
  22. if (handle == _LLIO_STDIN)
  23. {
  24. if (libc_stdio_get_console() < 0)
  25. {
  26. LOG_W("Do not invoke standard input before initializing libc");
  27. return 0;
  28. }
  29. return read(STDIN_FILENO, buf, len);
  30. }
  31. else if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
  32. {
  33. return _LLIO_ERROR;
  34. }
  35. size = read(handle, buf, len);
  36. return size;
  37. #else
  38. return _LLIO_ERROR;
  39. #endif /* RT_LIBC_USING_FILEIO */
  40. }