stat.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. #elif __WORDSIZE == 64 && defined __NR_newfstatat
  20. # include <fcntl.h>
  21. int stat(const char *file_name, struct stat *buf)
  22. {
  23. return fstatat64(AT_FDCWD, file_name, buf, 0);
  24. }
  25. #else
  26. # include "xstatconv.h"
  27. int stat(const char *file_name, struct stat *buf)
  28. {
  29. int result;
  30. # ifdef __NR_stat64
  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(stat64, 2, file_name, &kbuf);
  38. if (result == 0) {
  39. __xstat32_conv(&kbuf, buf);
  40. }
  41. # else
  42. struct kernel_stat kbuf;
  43. result = INLINE_SYSCALL(stat, 2, file_name, &kbuf);
  44. if (result == 0) {
  45. __xstat_conv(&kbuf, buf);
  46. }
  47. # endif /* __NR_stat64 */
  48. return result;
  49. }
  50. #endif /* __NR_fstat64 */
  51. libc_hidden_def(stat)
  52. #if ! defined __NR_stat64 && ! defined __NR_fstatat64
  53. strong_alias_untyped(stat,stat64)
  54. libc_hidden_def(stat64)
  55. #endif