fstatat.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #include <bits/uClibc_arch_features.h>
  12. /* 64bit ports tend to favor newfstatat() */
  13. #if __WORDSIZE == 64 && defined __NR_newfstatat
  14. # define __NR_fstatat64 __NR_newfstatat
  15. #endif
  16. #if defined(__NR_fstatat64) && !defined(__UCLIBC_USE_TIME64__)
  17. int fstatat(int fd, const char *file, struct stat *buf, int flag)
  18. {
  19. int ret;
  20. # ifdef __ARCH_HAS_DEPRECATED_SYSCALLS__
  21. struct kernel_stat64 kbuf;
  22. ret = INLINE_SYSCALL(fstatat64, 4, fd, file, &kbuf, flag);
  23. if (ret == 0)
  24. __xstat32_conv(&kbuf, buf);
  25. # else
  26. ret = INLINE_SYSCALL(fstatat64, 4, fd, file, buf, flag);
  27. # endif /* __ARCH_HAS_DEPRECATED_SYSCALLS__ */
  28. return ret;
  29. }
  30. libc_hidden_def(fstatat)
  31. #else
  32. #if defined(__NR_statx) && defined __UCLIBC_HAVE_STATX__
  33. #include <sys/sysmacros.h> // for makedev
  34. int fstatat(int fd, const char *file, struct stat *buf, int flag)
  35. {
  36. int ret;
  37. struct statx tmp;
  38. ret = INLINE_SYSCALL(statx, 5, fd, file, flag,
  39. STATX_BASIC_STATS, &tmp);
  40. if (ret != 0)
  41. return ret;
  42. *buf = (struct stat) {
  43. .st_dev = makedev(tmp.stx_dev_major, tmp.stx_dev_minor),
  44. .st_ino = tmp.stx_ino,
  45. .st_mode = tmp.stx_mode,
  46. .st_nlink = tmp.stx_nlink,
  47. .st_uid = tmp.stx_uid,
  48. .st_gid = tmp.stx_gid,
  49. .st_rdev = makedev(tmp.stx_rdev_major, tmp.stx_rdev_minor),
  50. .st_size = tmp.stx_size,
  51. .st_blksize = tmp.stx_blksize,
  52. .st_blocks = tmp.stx_blocks,
  53. .st_atim.tv_sec = tmp.stx_atime.tv_sec,
  54. .st_atim.tv_nsec = tmp.stx_atime.tv_nsec,
  55. .st_mtim.tv_sec = tmp.stx_mtime.tv_sec,
  56. .st_mtim.tv_nsec = tmp.stx_mtime.tv_nsec,
  57. .st_ctim.tv_sec = tmp.stx_ctime.tv_sec,
  58. .st_ctim.tv_nsec = tmp.stx_ctime.tv_nsec,
  59. };
  60. return ret;
  61. }
  62. libc_hidden_def(fstatat)
  63. #endif
  64. /* should add emulation with fstat() and /proc/self/fd/ ... */
  65. #endif