stat.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * stat() 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 <sys/syscall.h>
  9. #include <unistd.h>
  10. #include <sys/stat.h>
  11. #include <bits/uClibc_arch_features.h>
  12. #undef stat
  13. #if defined __NR_fstatat64 && !defined __NR_stat && !defined(__UCLIBC_USE_TIME64__)
  14. # include <fcntl.h>
  15. int stat(const char *file_name, struct stat *buf)
  16. {
  17. return fstatat(AT_FDCWD, file_name, buf, 0);
  18. }
  19. #elif __WORDSIZE == 64 && defined __NR_newfstatat && !defined __ARCH_HAS_DEPRECATED_SYSCALLS__
  20. # include <fcntl.h>
  21. int stat(const char *file_name, struct stat *buf)
  22. {
  23. return fstatat64(AT_FDCWD, file_name, (struct stat64 *)buf, 0);
  24. }
  25. #elif __NR_statx && defined __UCLIBC_HAVE_STATX__
  26. # include <fcntl.h>
  27. # include <statx_cp.h>
  28. int stat(const char *file_name, struct stat *buf)
  29. {
  30. struct statx tmp;
  31. int rc = INLINE_SYSCALL (statx, 5, AT_FDCWD, file_name, AT_NO_AUTOMOUNT,
  32. STATX_BASIC_STATS, &tmp);
  33. if (rc == 0)
  34. __cp_stat_statx ((struct stat *)buf, &tmp);
  35. return rc;
  36. }
  37. #else
  38. # include "xstatconv.h"
  39. int stat(const char *file_name, struct stat *buf)
  40. {
  41. int result;
  42. # ifdef __NR_stat64
  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(stat64, 2, file_name, &kbuf);
  50. if (result == 0) {
  51. __xstat32_conv(&kbuf, buf);
  52. }
  53. # else
  54. struct kernel_stat kbuf;
  55. result = INLINE_SYSCALL(stat, 2, file_name, &kbuf);
  56. if (result == 0) {
  57. __xstat_conv(&kbuf, buf);
  58. }
  59. # endif /* __NR_stat64 */
  60. return result;
  61. }
  62. #endif /* __NR_fstat64 */
  63. libc_hidden_def(stat)
  64. #if ! defined __NR_stat64 && ! defined __NR_fstatat64 && ! defined __UCLIBC_HAVE_STATX__
  65. strong_alias_untyped(stat,stat64)
  66. libc_hidden_def(stat64)
  67. #endif