struct_stat.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Definition for struct stat.
  17. Copyright (C) 2020-2026 Free Software Foundation, Inc.
  18. This file is part of the GNU C Library.
  19. The GNU C Library is free software; you can redistribute it and/or
  20. modify it under the terms of the GNU Lesser General Public
  21. License as published by the Free Software Foundation; either
  22. version 2.1 of the License, or (at your option) any later version.
  23. The GNU C Library is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. Lesser General Public License for more details.
  27. You should have received a copy of the GNU Lesser General Public
  28. License along with the GNU C Library. If not, see
  29. <https://www.gnu.org/licenses/>. */
  30. #if !defined _SYS_STAT_H && !defined _FCNTL_H
  31. # error "Never include <bits/struct_stat.h> directly; use <sys/stat.h> instead."
  32. #endif
  33. #ifndef _BITS_STRUCT_STAT_H
  34. #define _BITS_STRUCT_STAT_H 1
  35. struct stat
  36. {
  37. #ifdef __USE_TIME64_REDIRECTS
  38. # include <bits/struct_stat_time64_helper.h>
  39. #else
  40. __dev_t st_dev; /* Device. */
  41. # ifndef __x86_64__
  42. unsigned short int __pad1;
  43. # endif
  44. # if defined __x86_64__ || !defined __USE_FILE_OFFSET64
  45. __ino_t st_ino; /* File serial number. */
  46. # else
  47. __ino_t __st_ino; /* 32bit file serial number. */
  48. # endif
  49. # ifndef __x86_64__
  50. __mode_t st_mode; /* File mode. */
  51. __nlink_t st_nlink; /* Link count. */
  52. # else
  53. __nlink_t st_nlink; /* Link count. */
  54. __mode_t st_mode; /* File mode. */
  55. # endif
  56. __uid_t st_uid; /* User ID of the file's owner. */
  57. __gid_t st_gid; /* Group ID of the file's group.*/
  58. # ifdef __x86_64__
  59. int __pad0;
  60. # endif
  61. __dev_t st_rdev; /* Device number, if device. */
  62. # ifndef __x86_64__
  63. unsigned short int __pad2;
  64. # endif
  65. # if defined __x86_64__ || !defined __USE_FILE_OFFSET64
  66. __off_t st_size; /* Size of file, in bytes. */
  67. # else
  68. __off64_t st_size; /* Size of file, in bytes. */
  69. # endif
  70. __blksize_t st_blksize; /* Optimal block size for I/O. */
  71. # if defined __x86_64__ || !defined __USE_FILE_OFFSET64
  72. __blkcnt_t st_blocks; /* Number 512-byte blocks allocated. */
  73. # else
  74. __blkcnt64_t st_blocks; /* Number 512-byte blocks allocated. */
  75. # endif
  76. # ifdef __USE_XOPEN2K8
  77. /* Nanosecond resolution timestamps are stored in a format
  78. equivalent to 'struct timespec'. This is the type used
  79. whenever possible but the Unix namespace rules do not allow the
  80. identifier 'timespec' to appear in the <sys/stat.h> header.
  81. Therefore we have to handle the use of this header in strictly
  82. standard-compliant sources special. */
  83. struct timespec st_atim; /* Time of last access. */
  84. struct timespec st_mtim; /* Time of last modification. */
  85. struct timespec st_ctim; /* Time of last status change. */
  86. # define st_atime st_atim.tv_sec /* Backward compatibility. */
  87. # define st_mtime st_mtim.tv_sec
  88. # define st_ctime st_ctim.tv_sec
  89. # else
  90. __time_t st_atime; /* Time of last access. */
  91. __syscall_ulong_t st_atimensec; /* Nscecs of last access. */
  92. __time_t st_mtime; /* Time of last modification. */
  93. __syscall_ulong_t st_mtimensec; /* Nsecs of last modification. */
  94. __time_t st_ctime; /* Time of last status change. */
  95. __syscall_ulong_t st_ctimensec; /* Nsecs of last status change. */
  96. # endif
  97. # ifdef __x86_64__
  98. __syscall_slong_t __glibc_reserved[3];
  99. # else
  100. # ifndef __USE_FILE_OFFSET64
  101. unsigned long int __glibc_reserved4;
  102. unsigned long int __glibc_reserved5;
  103. # else
  104. __ino64_t st_ino; /* File serial number. */
  105. # endif
  106. # endif
  107. #endif /* __USE_TIME64_REDIRECTS */
  108. };
  109. #ifdef __USE_LARGEFILE64
  110. /* Note stat64 has the same shape as stat for x86-64. */
  111. struct stat64
  112. {
  113. # ifdef __USE_TIME64_REDIRECTS
  114. # include <bits/struct_stat_time64_helper.h>
  115. # else
  116. __dev_t st_dev; /* Device. */
  117. # ifdef __x86_64__
  118. __ino64_t st_ino; /* File serial number. */
  119. __nlink_t st_nlink; /* Link count. */
  120. __mode_t st_mode; /* File mode. */
  121. # else
  122. unsigned int __pad1;
  123. __ino_t __st_ino; /* 32bit file serial number. */
  124. __mode_t st_mode; /* File mode. */
  125. __nlink_t st_nlink; /* Link count. */
  126. # endif
  127. __uid_t st_uid; /* User ID of the file's owner. */
  128. __gid_t st_gid; /* Group ID of the file's group.*/
  129. # ifdef __x86_64__
  130. int __pad0;
  131. __dev_t st_rdev; /* Device number, if device. */
  132. __off_t st_size; /* Size of file, in bytes. */
  133. # else
  134. __dev_t st_rdev; /* Device number, if device. */
  135. unsigned int __pad2;
  136. __off64_t st_size; /* Size of file, in bytes. */
  137. # endif
  138. __blksize_t st_blksize; /* Optimal block size for I/O. */
  139. __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */
  140. # ifdef __USE_XOPEN2K8
  141. /* Nanosecond resolution timestamps are stored in a format
  142. equivalent to 'struct timespec'. This is the type used
  143. whenever possible but the Unix namespace rules do not allow the
  144. identifier 'timespec' to appear in the <sys/stat.h> header.
  145. Therefore we have to handle the use of this header in strictly
  146. standard-compliant sources special. */
  147. struct timespec st_atim; /* Time of last access. */
  148. struct timespec st_mtim; /* Time of last modification. */
  149. struct timespec st_ctim; /* Time of last status change. */
  150. # else
  151. __time_t st_atime; /* Time of last access. */
  152. __syscall_ulong_t st_atimensec; /* Nscecs of last access. */
  153. __time_t st_mtime; /* Time of last modification. */
  154. __syscall_ulong_t st_mtimensec; /* Nsecs of last modification. */
  155. __time_t st_ctime; /* Time of last status change. */
  156. __syscall_ulong_t st_ctimensec; /* Nsecs of last status change. */
  157. # endif
  158. # ifdef __x86_64__
  159. __syscall_slong_t __glibc_reserved[3];
  160. # else
  161. __ino64_t st_ino; /* File serial number. */
  162. # endif
  163. # endif /* __USE_TIME64_REDIRECTS */
  164. };
  165. #endif
  166. /* Tell code we have these members. */
  167. #define _STATBUF_ST_BLKSIZE
  168. #define _STATBUF_ST_RDEV
  169. /* Nanosecond resolution time values are supported. */
  170. #define _STATBUF_ST_NSEC
  171. #endif /* _BITS_STRUCT_STAT_H */