stat.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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
  19. # include <fcntl.h>
  20. int stat(const char *file_name, struct stat *buf)
  21. {
  22. return fstatat64(AT_FDCWD, file_name, buf, 0);
  23. }
  24. #else
  25. # include "xstatconv.h"
  26. int stat(const char *file_name, struct stat *buf)
  27. {
  28. int result;
  29. # ifdef __NR_stat64
  30. /* normal stat call has limited values for various stat elements
  31. * e.g. uid device major/minor etc.
  32. * so we use 64 variant if available
  33. * in order to get newer versions of stat elements
  34. */
  35. struct kernel_stat64 kbuf;
  36. result = INLINE_SYSCALL(stat64, 2, file_name, &kbuf);
  37. if (result == 0) {
  38. __xstat32_conv(&kbuf, buf);
  39. }
  40. # else
  41. struct kernel_stat kbuf;
  42. result = INLINE_SYSCALL(stat, 2, file_name, &kbuf);
  43. if (result == 0) {
  44. __xstat_conv(&kbuf, buf);
  45. }
  46. # endif /* __NR_stat64 */
  47. return result;
  48. }
  49. #endif /* __NR_fstat64 */
  50. libc_hidden_def(stat)
  51. #if ! defined __NR_stat64 && ! defined __NR_fstatat64
  52. strong_alias_untyped(stat,stat64)
  53. libc_hidden_def(stat64)
  54. #endif