fstat.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 defined __NR_fstat
  27. int fstat(int fd, struct stat *buf)
  28. {
  29. int result;
  30. # ifdef __NR_fstat64
  31. /* normal stat call has limited values for various stat elements
  32. * e.g. uid device major/minor etc.
  33. * so we use 64 variant if available
  34. * in order to get newer versions of stat elements
  35. */
  36. struct kernel_stat64 kbuf;
  37. result = INLINE_SYSCALL(fstat64, 2, fd, &kbuf);
  38. if (result == 0) {
  39. __xstat32_conv(&kbuf, buf);
  40. }
  41. # else
  42. struct kernel_stat kbuf;
  43. result = INLINE_SYSCALL(fstat, 2, fd, &kbuf);
  44. if (result == 0) {
  45. __xstat_conv(&kbuf, buf);
  46. }
  47. # endif
  48. return result;
  49. }
  50. libc_hidden_def(fstat)
  51. #endif
  52. # if ! defined __NR_fstat64
  53. strong_alias_untyped(fstat,fstat64)
  54. libc_hidden_def(fstat64)
  55. #endif