lstat.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /* For systems which have both, prefer the old one */
  26. #else
  27. # include "xstatconv.h"
  28. int lstat(const char *file_name, struct stat *buf)
  29. {
  30. int result;
  31. # ifdef __NR_lstat64
  32. /* normal stat call has limited values for various stat elements
  33. * e.g. uid device major/minor etc.
  34. * so we use 64 variant if available
  35. * in order to get newer versions of stat elements
  36. */
  37. struct kernel_stat64 kbuf;
  38. result = INLINE_SYSCALL(lstat64, 2, file_name, &kbuf);
  39. if (result == 0) {
  40. __xstat32_conv(&kbuf, buf);
  41. }
  42. # else
  43. struct kernel_stat kbuf;
  44. result = INLINE_SYSCALL(lstat, 2, file_name, &kbuf);
  45. if (result == 0) {
  46. __xstat_conv(&kbuf, buf);
  47. }
  48. # endif /* __NR_lstat64 */
  49. return result;
  50. }
  51. libc_hidden_def(lstat)
  52. # if ! defined __NR_fstatat64 && ! defined __NR_lstat64
  53. strong_alias_untyped(lstat,lstat64)
  54. libc_hidden_def(lstat64)
  55. # endif
  56. #endif /* __NR_fstatat64 */