lstat.c 2.1 KB

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