xstatconv.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* Convert between the kernel's `struct stat' format, and libc's.
  2. Copyright (C) 1991,1995,1996,1997,2000,2002 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>.
  15. Modified for uClibc by Erik Andersen <andersen@codepoet.org>
  16. */
  17. #include <sys/stat.h>
  18. #include <string.h>
  19. #include "xstatconv.h"
  20. void __xstat_conv(struct kernel_stat *kbuf, struct stat *buf)
  21. {
  22. /* Convert to current kernel version of `struct stat'. */
  23. memset(buf, 0x00, sizeof(*buf));
  24. buf->st_dev = kbuf->st_dev;
  25. buf->st_ino = kbuf->st_ino;
  26. buf->st_mode = kbuf->st_mode;
  27. buf->st_nlink = kbuf->st_nlink;
  28. buf->st_uid = kbuf->st_uid;
  29. buf->st_gid = kbuf->st_gid;
  30. buf->st_rdev = kbuf->st_rdev;
  31. buf->st_size = kbuf->st_size;
  32. buf->st_blksize = kbuf->st_blksize;
  33. buf->st_blocks = kbuf->st_blocks;
  34. #if defined(__UCLIBC_USE_TIME64__)
  35. buf->st_atim.tv_sec = kbuf->__st_atim32.tv_sec;
  36. buf->st_atim.tv_nsec = kbuf->__st_atim32.tv_nsec;
  37. buf->st_mtim.tv_sec = kbuf->__st_mtim32.tv_sec;
  38. buf->st_mtim.tv_nsec = kbuf->__st_mtim32.tv_nsec;
  39. buf->st_ctim.tv_sec = kbuf->__st_ctim32.tv_sec;
  40. buf->st_ctim.tv_nsec = kbuf->__st_ctim32.tv_nsec;
  41. #else
  42. buf->st_atim.tv_sec = kbuf->st_atim.tv_sec;
  43. buf->st_atim.tv_nsec = kbuf->st_atim.tv_nsec;
  44. buf->st_mtim.tv_sec = kbuf->st_mtim.tv_sec;
  45. buf->st_mtim.tv_nsec = kbuf->st_mtim.tv_nsec;
  46. buf->st_ctim.tv_sec = kbuf->st_ctim.tv_sec;
  47. buf->st_ctim.tv_nsec = kbuf->st_ctim.tv_nsec;
  48. #endif
  49. }
  50. void __xstat32_conv(struct kernel_stat64 *kbuf, struct stat *buf)
  51. {
  52. /* Convert to current kernel version of `struct stat64'. */
  53. memset(buf, 0x00, sizeof(*buf));
  54. buf->st_dev = kbuf->st_dev;
  55. buf->st_ino = kbuf->st_ino;
  56. buf->st_mode = kbuf->st_mode;
  57. buf->st_nlink = kbuf->st_nlink;
  58. buf->st_uid = kbuf->st_uid;
  59. buf->st_gid = kbuf->st_gid;
  60. buf->st_rdev = kbuf->st_rdev;
  61. buf->st_size = kbuf->st_size;
  62. buf->st_blksize = kbuf->st_blksize;
  63. buf->st_blocks = kbuf->st_blocks;
  64. #if defined(__UCLIBC_USE_TIME64__)
  65. buf->st_atim.tv_sec = kbuf->__st_atim32.tv_sec;
  66. buf->st_atim.tv_nsec = kbuf->__st_atim32.tv_nsec;
  67. buf->st_mtim.tv_sec = kbuf->__st_mtim32.tv_sec;
  68. buf->st_mtim.tv_nsec = kbuf->__st_mtim32.tv_nsec;
  69. buf->st_ctim.tv_sec = kbuf->__st_ctim32.tv_sec;
  70. buf->st_ctim.tv_nsec = kbuf->__st_ctim32.tv_nsec;
  71. #else
  72. buf->st_atim.tv_sec = kbuf->st_atim.tv_sec;
  73. buf->st_atim.tv_nsec = kbuf->st_atim.tv_nsec;
  74. buf->st_mtim.tv_sec = kbuf->st_mtim.tv_sec;
  75. buf->st_mtim.tv_nsec = kbuf->st_mtim.tv_nsec;
  76. buf->st_ctim.tv_sec = kbuf->st_ctim.tv_sec;
  77. buf->st_ctim.tv_nsec = kbuf->st_ctim.tv_nsec;
  78. #endif
  79. }
  80. void __xstat64_conv(struct kernel_stat64 *kbuf, struct stat64 *buf)
  81. {
  82. /* Convert to current kernel version of `struct stat64'. */
  83. memset(buf, 0x00, sizeof(*buf));
  84. buf->st_dev = kbuf->st_dev;
  85. buf->st_ino = kbuf->st_ino;
  86. # ifdef _HAVE_STAT64___ST_INO
  87. buf->__st_ino = kbuf->__st_ino;
  88. # endif
  89. buf->st_mode = kbuf->st_mode;
  90. buf->st_nlink = kbuf->st_nlink;
  91. buf->st_uid = kbuf->st_uid;
  92. buf->st_gid = kbuf->st_gid;
  93. buf->st_rdev = kbuf->st_rdev;
  94. buf->st_size = kbuf->st_size;
  95. buf->st_blksize = kbuf->st_blksize;
  96. buf->st_blocks = kbuf->st_blocks;
  97. #if defined(__UCLIBC_USE_TIME64__)
  98. buf->st_atim.tv_sec = kbuf->__st_atim32.tv_sec;
  99. buf->st_atim.tv_nsec = kbuf->__st_atim32.tv_nsec;
  100. buf->st_mtim.tv_sec = kbuf->__st_mtim32.tv_sec;
  101. buf->st_mtim.tv_nsec = kbuf->__st_mtim32.tv_nsec;
  102. buf->st_ctim.tv_sec = kbuf->__st_ctim32.tv_sec;
  103. buf->st_ctim.tv_nsec = kbuf->__st_ctim32.tv_nsec;
  104. #else
  105. buf->st_atim.tv_sec = kbuf->st_atim.tv_sec;
  106. buf->st_atim.tv_nsec = kbuf->st_atim.tv_nsec;
  107. buf->st_mtim.tv_sec = kbuf->st_mtim.tv_sec;
  108. buf->st_mtim.tv_nsec = kbuf->st_mtim.tv_nsec;
  109. buf->st_ctim.tv_sec = kbuf->st_ctim.tv_sec;
  110. buf->st_ctim.tv_nsec = kbuf->st_ctim.tv_nsec;
  111. #endif
  112. }