syscall_lseek.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #include <compiler_private.h>
  14. #define DBG_TAG "dlib.syscall.lseek"
  15. #define DBG_LVL DBG_INFO
  16. #include <rtdbg.h>
  17. /*
  18. * The "__lseek" function makes the next file operation (__read or
  19. * __write) act on a new location. The parameter "whence" specifies
  20. * how the "offset" parameter should be interpreted according to the
  21. * following table:
  22. *
  23. * 0 (=SEEK_SET) - Goto location "offset".
  24. * 1 (=SEEK_CUR) - Go "offset" bytes from the current location.
  25. * 2 (=SEEK_END) - Go to "offset" bytes from the end.
  26. *
  27. * This function should return the current file position, or -1 on
  28. * failure.
  29. */
  30. #pragma module_name = "?__lseek"
  31. long __lseek(int handle, long offset, int whence)
  32. {
  33. if (handle == _LLIO_STDOUT ||
  34. handle == _LLIO_STDERR ||
  35. handle == _LLIO_STDIN)
  36. return _LLIO_ERROR;
  37. #ifdef DFS_USING_POSIX
  38. return lseek(handle, offset, whence);
  39. #else
  40. LOG_W(_WARNING_WITHOUT_FS);
  41. return _LLIO_ERROR;
  42. #endif /* DFS_USING_POSIX */
  43. }