fstatat64.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * fstatat64() 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 <_lfs_64.h>
  9. #include <bits/wordsize.h>
  10. #include <sys/syscall.h>
  11. #include <linux/version.h>
  12. #if defined __mips__
  13. # include <sgidefs.h>
  14. #endif
  15. /* 64bit ports tend to favor newfstatat() */
  16. #if __WORDSIZE == 64 && defined __NR_newfstatat
  17. # define __NR_fstatat64 __NR_newfstatat
  18. #endif
  19. /* mips N32 ABI use newfstatat(), too */
  20. #if defined __mips__ && _MIPS_SIM == _ABIN32
  21. # define __NR_fstatat64 __NR_newfstatat
  22. #endif
  23. #if defined(__NR_fstatat64) && (!defined(__UCLIBC_USE_TIME64__) || LINUX_VERSION_CODE <= KERNEL_VERSION(5,1,0))
  24. # include <sys/stat.h>
  25. # include "xstatconv.h"
  26. int fstatat64(int fd, const char *file, struct stat64 *buf, int flag)
  27. {
  28. # ifdef __ARCH_HAS_DEPRECATED_SYSCALLS__
  29. int ret;
  30. struct kernel_stat64 kbuf;
  31. ret = INLINE_SYSCALL(fstatat64, 4, fd, file, &kbuf, flag);
  32. if (ret == 0)
  33. __xstat64_conv(&kbuf, buf);
  34. return ret;
  35. # else
  36. return INLINE_SYSCALL(fstatat64, 4, fd, file, buf, flag);
  37. # endif
  38. }
  39. libc_hidden_def(fstatat64)
  40. #else
  41. #if defined(__NR_statx) && defined(__UCLIBC_HAVE_STATX__)
  42. # include <sys/stat.h>
  43. # include <statx_cp.h>
  44. # include <fcntl.h> // for AT_NO_AUTOMOUNT
  45. int fstatat64(int fd, const char *file, struct stat64 *buf, int flag)
  46. {
  47. struct statx tmp;
  48. int r = INLINE_SYSCALL(statx, 5, fd, file, AT_NO_AUTOMOUNT | flag,
  49. STATX_BASIC_STATS, &tmp);
  50. if (r == 0)
  51. __cp_stat64_statx ((struct stat64 *)buf, &tmp);
  52. return r;
  53. }
  54. libc_hidden_def(fstatat64)
  55. #endif
  56. /* should add emulation with fstat64() and /proc/self/fd/ ... */
  57. #endif