fstat.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * fstat() for uClibc
  3. *
  4. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <features.h>
  9. #include <unistd.h>
  10. #include <sys/stat.h>
  11. #include <sys/syscall.h>
  12. #include "xstatconv.h"
  13. #if defined __NR_fstat64 && !defined __NR_fstat
  14. int fstat(int fd, struct stat *buf)
  15. {
  16. return INLINE_SYSCALL(fstat64, 2, fd, buf);
  17. }
  18. libc_hidden_def(fstat)
  19. #elif __WORDSIZE == 64 && defined __NR_newfstatat && !defined __ARCH_HAS_DEPRECATED_SYSCALLS__
  20. #include <fcntl.h>
  21. int fstat(int fd, struct stat *buf)
  22. {
  23. return INLINE_SYSCALL(fstat, 2, fd, buf);
  24. }
  25. libc_hidden_def(fstat)
  26. #elif __NR_statx && defined __UCLIBC_HAVE_STATX__
  27. # include <fcntl.h>
  28. # include <statx_cp.h>
  29. int fstat(int fd, struct stat *buf)
  30. {
  31. struct statx tmp;
  32. int rc = INLINE_SYSCALL (statx, 5, fd, "", AT_EMPTY_PATH,
  33. STATX_BASIC_STATS, &tmp);
  34. if (rc == 0)
  35. __cp_stat_statx ((struct stat *)buf, &tmp);
  36. return rc;
  37. }
  38. libc_hidden_def(fstat)
  39. #elif defined __NR_fstat
  40. int fstat(int fd, struct stat *buf)
  41. {
  42. int result;
  43. # ifdef __NR_fstat64
  44. /* normal stat call has limited values for various stat elements
  45. * e.g. uid device major/minor etc.
  46. * so we use 64 variant if available
  47. * in order to get newer versions of stat elements
  48. */
  49. struct kernel_stat64 kbuf;
  50. result = INLINE_SYSCALL(fstat64, 2, fd, &kbuf);
  51. if (result == 0) {
  52. __xstat32_conv(&kbuf, buf);
  53. }
  54. # else
  55. struct kernel_stat kbuf;
  56. result = INLINE_SYSCALL(fstat, 2, fd, &kbuf);
  57. if (result == 0) {
  58. __xstat_conv(&kbuf, buf);
  59. }
  60. # endif
  61. return result;
  62. }
  63. libc_hidden_def(fstat)
  64. #endif
  65. # if ! defined __NR_fstat64 && ! defined __UCLIBC_HAVE_STATX__
  66. strong_alias_untyped(fstat,fstat64)
  67. libc_hidden_def(fstat64)
  68. #endif