stat.c 1.8 KB

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