fstatat.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. };
  59. return ret;
  60. }
  61. libc_hidden_def(fstatat)
  62. #endif
  63. /* should add emulation with fstat() and /proc/self/fd/ ... */
  64. #endif