fstatat.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * fstatat() for uClibc
  3. *
  4. * Copyright (C) 2009 Analog Devices Inc.
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <sys/syscall.h>
  9. #include <sys/stat.h>
  10. #include "xstatconv.h"
  11. /* 64bit ports tend to favor newfstatat() */
  12. #if __WORDSIZE == 64 && defined __NR_newfstatat
  13. # define __NR_fstatat64 __NR_newfstatat
  14. #endif
  15. #ifdef __NR_fstatat64
  16. int fstatat(int fd, const char *file, struct stat *buf, int flag)
  17. {
  18. int ret;
  19. # ifdef __ARCH_HAS_DEPRECATED_SYSCALLS__
  20. struct kernel_stat64 kbuf;
  21. ret = INLINE_SYSCALL(fstatat64, 4, fd, file, &kbuf, flag);
  22. if (ret == 0)
  23. __xstat32_conv(&kbuf, buf);
  24. # else
  25. ret = INLINE_SYSCALL(fstatat64, 4, fd, file, buf, flag);
  26. # endif /* __ARCH_HAS_DEPRECATED_SYSCALLS__ */
  27. return ret;
  28. }
  29. libc_hidden_def(fstatat)
  30. #else
  31. #if defined(__NR_statx) && defined __UCLIBC_HAVE_STATX__
  32. #include <sys/sysmacros.h> // for makedev
  33. int fstatat(int fd, const char *file, struct stat *buf, int flag)
  34. {
  35. int ret;
  36. struct statx tmp;
  37. ret = INLINE_SYSCALL(statx, 5, fd, file, flag,
  38. STATX_BASIC_STATS, &tmp);
  39. if (ret != 0)
  40. return ret;
  41. *buf = (struct stat) {
  42. .st_dev = makedev(tmp.stx_dev_major, tmp.stx_dev_minor),
  43. .st_ino = tmp.stx_ino,
  44. .st_mode = tmp.stx_mode,
  45. .st_nlink = tmp.stx_nlink,
  46. .st_uid = tmp.stx_uid,
  47. .st_gid = tmp.stx_gid,
  48. .st_rdev = makedev(tmp.stx_rdev_major, tmp.stx_rdev_minor),
  49. .st_size = tmp.stx_size,
  50. .st_blksize = tmp.stx_blksize,
  51. .st_blocks = tmp.stx_blocks,
  52. .st_atim.tv_sec = tmp.stx_atime.tv_sec,
  53. .st_atim.tv_nsec = tmp.stx_atime.tv_nsec,
  54. .st_mtim.tv_sec = tmp.stx_mtime.tv_sec,
  55. .st_mtim.tv_nsec = tmp.stx_mtime.tv_nsec,
  56. .st_ctim.tv_sec = tmp.stx_ctime.tv_sec,
  57. .st_ctim.tv_nsec = tmp.stx_ctime.tv_nsec,
  58. #if defined(__UCLIBC_USE_TIME64__)
  59. .__st_atim32.tv_sec = stx.stx_atime.tv_sec,
  60. .__st_atim32.tv_nsec = stx.stx_atime.tv_nsec,
  61. .__st_mtim32.tv_sec = stx.stx_mtime.tv_sec,
  62. .__st_mtim32.tv_nsec = stx.stx_mtime.tv_nsec,
  63. .__st_ctim32.tv_sec = stx.stx_ctime.tv_sec,
  64. .__st_ctim32.tv_nsec = stx.stx_ctime.tv_nsec,
  65. #endif
  66. };
  67. return ret;
  68. }
  69. libc_hidden_def(fstatat)
  70. #endif
  71. /* should add emulation with fstat() and /proc/self/fd/ ... */
  72. #endif