fstat.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * fstat() 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. #include "xstatconv.h"
  13. #if defined __NR_fstat64 && !defined __NR_fstat
  14. int fstat(int fd, struct stat *buf)
  15. {
  16. int result = INLINE_SYSCALL(fstat64, 2, fd, buf);
  17. if (result == 0) {
  18. /* Did we overflow? */
  19. if (buf->__pad1 || buf->__pad2 || buf->__pad3
  20. || buf->__pad4 || buf->__pad5
  21. || buf->__pad6 || buf->__pad7) {
  22. __set_errno(EOVERFLOW);
  23. return -1;
  24. }
  25. }
  26. return result;
  27. }
  28. libc_hidden_def(fstat)
  29. #elif defined __NR_fstat
  30. int fstat(int fd, struct stat *buf)
  31. {
  32. int result;
  33. # ifdef __NR_fstat64
  34. /* normal stat call has limited values for various stat elements
  35. * e.g. uid device major/minor etc.
  36. * so we use 64 variant if available
  37. * in order to get newer versions of stat elements
  38. */
  39. struct kernel_stat64 kbuf;
  40. result = INLINE_SYSCALL(fstat64, 2, fd, &kbuf);
  41. if (result == 0) {
  42. __xstat32_conv(&kbuf, buf);
  43. }
  44. # else
  45. struct kernel_stat kbuf;
  46. result = INLINE_SYSCALL(fstat, 2, fd, &kbuf);
  47. if (result == 0) {
  48. __xstat_conv(&kbuf, buf);
  49. }
  50. # endif
  51. return result;
  52. }
  53. libc_hidden_def(fstat)
  54. # if ! defined __NR_fstat64 && defined __UCLIBC_HAS_LFS__
  55. strong_alias_untyped(fstat,fstat64)
  56. libc_hidden_def(fstat64)
  57. # endif
  58. #endif