fstat.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. }
  37. libc_hidden_def(fstat)
  38. #elif defined __NR_fstat
  39. int fstat(int fd, struct stat *buf)
  40. {
  41. int result;
  42. # ifdef __NR_fstat64
  43. /* normal stat call has limited values for various stat elements
  44. * e.g. uid device major/minor etc.
  45. * so we use 64 variant if available
  46. * in order to get newer versions of stat elements
  47. */
  48. struct kernel_stat64 kbuf;
  49. result = INLINE_SYSCALL(fstat64, 2, fd, &kbuf);
  50. if (result == 0) {
  51. __xstat32_conv(&kbuf, buf);
  52. }
  53. # else
  54. struct kernel_stat kbuf;
  55. result = INLINE_SYSCALL(fstat, 2, fd, &kbuf);
  56. if (result == 0) {
  57. __xstat_conv(&kbuf, buf);
  58. }
  59. # endif
  60. return result;
  61. }
  62. libc_hidden_def(fstat)
  63. #endif
  64. # if ! defined __NR_fstat64 && ! defined __UCLIBC_HAVE_STATX__
  65. strong_alias_untyped(fstat,fstat64)
  66. libc_hidden_def(fstat64)
  67. #endif