lstat.c 2.0 KB

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