lstat.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * lstat() 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. #if defined __NR_fstatat64 && !defined __NR_lstat
  13. # include <fcntl.h>
  14. int lstat(const char *file_name, struct stat *buf)
  15. {
  16. return fstatat(AT_FDCWD, file_name, buf, AT_SYMLINK_NOFOLLOW);
  17. }
  18. libc_hidden_def(lstat)
  19. #elif __WORDSIZE == 64 && defined __NR_newfstatat
  20. # include <fcntl.h>
  21. int lstat(const char *file_name, struct stat *buf)
  22. {
  23. return fstatat(AT_FDCWD, file_name, buf, AT_SYMLINK_NOFOLLOW);
  24. }
  25. libc_hidden_def(lstat)
  26. /* For systems which have both, prefer the old one */
  27. #else
  28. # include "xstatconv.h"
  29. int lstat(const char *file_name, struct stat *buf)
  30. {
  31. int result;
  32. # ifdef __NR_lstat64
  33. /* normal stat call has limited values for various stat elements
  34. * e.g. uid device major/minor etc.
  35. * so we use 64 variant if available
  36. * in order to get newer versions of stat elements
  37. */
  38. struct kernel_stat64 kbuf;
  39. result = INLINE_SYSCALL(lstat64, 2, file_name, &kbuf);
  40. if (result == 0) {
  41. __xstat32_conv(&kbuf, buf);
  42. }
  43. # else
  44. struct kernel_stat kbuf;
  45. result = INLINE_SYSCALL(lstat, 2, file_name, &kbuf);
  46. if (result == 0) {
  47. __xstat_conv(&kbuf, buf);
  48. }
  49. # endif /* __NR_lstat64 */
  50. return result;
  51. }
  52. libc_hidden_def(lstat)
  53. # if ! defined __NR_fstatat64 && ! defined __NR_lstat64
  54. strong_alias_untyped(lstat,lstat64)
  55. libc_hidden_def(lstat64)
  56. # endif
  57. #endif /* __NR_fstatat64 */