statx_cp.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* Struct statx to stat/stat64 conversion for Linux.
  2. Copyright (C) 2018 Free Software Foundation, Inc.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library. If not, see
  13. <http://www.gnu.org/licenses/>. */
  14. #include <bits/uClibc_arch_features.h>
  15. #include <stddef.h>
  16. #include <string.h>
  17. #include <sys/stat.h>
  18. #if defined __UCLIBC_HAVE_STATX__
  19. #include <statx_cp.h>
  20. #if (!defined(__NR_fstat64) || !defined(__NR_fstatat64)) || defined(__UCLIBC_USE_TIME64__)
  21. void
  22. __cp_stat64_statx (struct stat64 *to, struct statx *from)
  23. {
  24. memset (to, 0, sizeof (struct stat64));
  25. to->st_dev = ((from->stx_dev_minor & 0xff) | (from->stx_dev_major << 8)
  26. | ((from->stx_dev_minor & ~0xff) << 12));
  27. to->st_rdev = ((from->stx_rdev_minor & 0xff) | (from->stx_rdev_major << 8)
  28. | ((from->stx_rdev_minor & ~0xff) << 12));
  29. to->st_ino = from->stx_ino;
  30. to->st_mode = from->stx_mode;
  31. to->st_nlink = from->stx_nlink;
  32. to->st_uid = from->stx_uid;
  33. to->st_gid = from->stx_gid;
  34. to->st_atime = from->stx_atime.tv_sec;
  35. to->st_atim.tv_nsec = from->stx_atime.tv_nsec;
  36. to->st_mtime = from->stx_mtime.tv_sec;
  37. to->st_mtim.tv_nsec = from->stx_mtime.tv_nsec;
  38. to->st_ctime = from->stx_ctime.tv_sec;
  39. to->st_ctim.tv_nsec = from->stx_ctime.tv_nsec;
  40. to->st_size = from->stx_size;
  41. to->st_blocks = from->stx_blocks;
  42. to->st_blksize = from->stx_blksize;
  43. }
  44. void
  45. __cp_stat_statx (struct stat *to, struct statx *from)
  46. {
  47. memset (to, 0, sizeof (struct stat));
  48. to->st_dev = ((from->stx_dev_minor & 0xff) | (from->stx_dev_major << 8)
  49. | ((from->stx_dev_minor & ~0xff) << 12));
  50. to->st_rdev = ((from->stx_rdev_minor & 0xff) | (from->stx_rdev_major << 8)
  51. | ((from->stx_rdev_minor & ~0xff) << 12));
  52. to->st_ino = from->stx_ino;
  53. to->st_mode = from->stx_mode;
  54. to->st_nlink = from->stx_nlink;
  55. to->st_uid = from->stx_uid;
  56. to->st_gid = from->stx_gid;
  57. to->st_atime = from->stx_atime.tv_sec;
  58. to->st_atim.tv_nsec = from->stx_atime.tv_nsec;
  59. to->st_mtime = from->stx_mtime.tv_sec;
  60. to->st_mtim.tv_nsec = from->stx_mtime.tv_nsec;
  61. to->st_ctime = from->stx_ctime.tv_sec;
  62. to->st_ctim.tv_nsec = from->stx_ctime.tv_nsec;
  63. to->st_size = from->stx_size;
  64. to->st_blocks = from->stx_blocks;
  65. to->st_blksize = from->stx_blksize;
  66. }
  67. #endif
  68. #endif