fstat.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 <bits/uClibc_arch_features.h>
  13. #include "xstatconv.h"
  14. #if defined __NR_fstat64 && !defined __NR_fstat && !defined(__UCLIBC_USE_TIME64__)
  15. int fstat(int fd, struct stat *buf)
  16. {
  17. return INLINE_SYSCALL(fstat64, 2, fd, buf);
  18. }
  19. libc_hidden_def(fstat)
  20. #elif __WORDSIZE == 64 && defined __NR_newfstatat && !defined __ARCH_HAS_DEPRECATED_SYSCALLS__
  21. #include <fcntl.h>
  22. int fstat(int fd, struct stat *buf)
  23. {
  24. return INLINE_SYSCALL(fstat, 2, fd, buf);
  25. }
  26. libc_hidden_def(fstat)
  27. #elif defined __NR_statx && defined __UCLIBC_HAVE_STATX__
  28. # include <fcntl.h>
  29. # include <statx_cp.h>
  30. int fstat(int fd, struct stat *buf)
  31. {
  32. struct statx tmp;
  33. int rc = INLINE_SYSCALL (statx, 5, fd, "", AT_EMPTY_PATH,
  34. STATX_BASIC_STATS, &tmp);
  35. if (rc == 0)
  36. __cp_stat_statx ((struct stat *)buf, &tmp);
  37. return rc;
  38. }
  39. libc_hidden_def(fstat)
  40. #elif defined __NR_fstat
  41. int fstat(int fd, struct stat *buf)
  42. {
  43. int result;
  44. # ifdef __NR_fstat64
  45. /* normal stat call has limited values for various stat elements
  46. * e.g. uid device major/minor etc.
  47. * so we use 64 variant if available
  48. * in order to get newer versions of stat elements
  49. */
  50. struct kernel_stat64 kbuf;
  51. result = INLINE_SYSCALL(fstat64, 2, fd, &kbuf);
  52. if (result == 0) {
  53. __xstat32_conv(&kbuf, buf);
  54. }
  55. # else
  56. struct kernel_stat kbuf;
  57. result = INLINE_SYSCALL(fstat, 2, fd, &kbuf);
  58. if (result == 0) {
  59. __xstat_conv(&kbuf, buf);
  60. }
  61. # endif
  62. return result;
  63. }
  64. libc_hidden_def(fstat)
  65. #endif
  66. # if ! defined __NR_fstat64 && ! defined __UCLIBC_HAVE_STATX__
  67. strong_alias_untyped(fstat,fstat64)
  68. libc_hidden_def(fstat64)
  69. #endif