fstat.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * fstat() for uClibc
  4. *
  5. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  6. *
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. #include <features.h>
  10. #include <unistd.h>
  11. #include <sys/stat.h>
  12. #include <sys/syscall.h>
  13. #include "xstatconv.h"
  14. #if defined __NR_fstat64 && !defined __NR_fstat
  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 && __aarch64__
  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_fstat
  28. int fstat(int fd, struct stat *buf)
  29. {
  30. int result;
  31. # ifdef __NR_fstat64
  32. /* normal stat call has limited values for various stat elements
  33. * e.g. uid device major/minor etc.
  34. * so we use 64 variant if available
  35. * in order to get newer versions of stat elements
  36. */
  37. struct kernel_stat64 kbuf;
  38. result = INLINE_SYSCALL(fstat64, 2, fd, &kbuf);
  39. if (result == 0) {
  40. __xstat32_conv(&kbuf, buf);
  41. }
  42. # else
  43. struct kernel_stat kbuf;
  44. result = INLINE_SYSCALL(fstat, 2, fd, &kbuf);
  45. if (result == 0) {
  46. __xstat_conv(&kbuf, buf);
  47. }
  48. # endif
  49. return result;
  50. }
  51. libc_hidden_def(fstat)
  52. #endif
  53. # if ! defined __NR_fstat64
  54. strong_alias_untyped(fstat,fstat64)
  55. libc_hidden_def(fstat64)
  56. #endif