stat.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * stat() 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 <sys/syscall.h>
  10. #include <unistd.h>
  11. #include <sys/stat.h>
  12. #undef stat
  13. #if defined __NR_fstatat64 && !defined __NR_stat
  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. #else
  20. # include "xstatconv.h"
  21. int stat(const char *file_name, struct stat *buf)
  22. {
  23. int result;
  24. # ifdef __NR_stat64
  25. /* normal stat call has limited values for various stat elements
  26. * e.g. uid device major/minor etc.
  27. * so we use 64 variant if available
  28. * in order to get newer versions of stat elements
  29. */
  30. struct kernel_stat64 kbuf;
  31. result = INLINE_SYSCALL(stat64, 2, file_name, &kbuf);
  32. if (result == 0) {
  33. __xstat32_conv(&kbuf, buf);
  34. }
  35. # else
  36. struct kernel_stat kbuf;
  37. result = INLINE_SYSCALL(stat, 2, file_name, &kbuf);
  38. if (result == 0) {
  39. __xstat_conv(&kbuf, buf);
  40. }
  41. # endif /* __NR_stat64 */
  42. return result;
  43. }
  44. #endif /* __NR_fstat64 */
  45. libc_hidden_def(stat)
  46. #if ! defined __NR_stat64 && ! defined __NR_fstatat64
  47. strong_alias_untyped(stat,stat64)
  48. libc_hidden_def(stat64)
  49. #endif