struct_stat.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* Definition for struct stat.
  2. Copyright (C) 2020-2021 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. <https://www.gnu.org/licenses/>. */
  15. #if !defined _SYS_STAT_H && !defined _FCNTL_H
  16. # error "Never include <bits/struct_stat.h> directly; use <sys/stat.h> instead."
  17. #endif
  18. #ifndef _BITS_STRUCT_STAT_H
  19. #define _BITS_STRUCT_STAT_H 1
  20. #include <bits/endian.h>
  21. #include <bits/wordsize.h>
  22. #if defined __USE_FILE_OFFSET64
  23. # define __field64(type, type64, name) type64 name
  24. #elif __WORDSIZE == 64 || defined __INO_T_MATCHES_INO64_T
  25. # if defined __INO_T_MATCHES_INO64_T && !defined __OFF_T_MATCHES_OFF64_T
  26. # error "ino_t and off_t must both be the same type"
  27. # endif
  28. # define __field64(type, type64, name) type name
  29. #elif __BYTE_ORDER == __LITTLE_ENDIAN
  30. # define __field64(type, type64, name) \
  31. type name __attribute__((__aligned__ (__alignof__ (type64)))); int __##name##_pad
  32. #else
  33. # define __field64(type, type64, name) \
  34. int __##name##_pad __attribute__((__aligned__ (__alignof__ (type64)))); type name
  35. #endif
  36. struct stat
  37. {
  38. __dev_t st_dev; /* Device. */
  39. __field64(__ino_t, __ino64_t, st_ino); /* File serial number. */
  40. __mode_t st_mode; /* File mode. */
  41. __nlink_t st_nlink; /* Link count. */
  42. __uid_t st_uid; /* User ID of the file's owner. */
  43. __gid_t st_gid; /* Group ID of the file's group.*/
  44. __dev_t st_rdev; /* Device number, if device. */
  45. __dev_t __pad1;
  46. __field64(__off_t, __off64_t, st_size); /* Size of file, in bytes. */
  47. __blksize_t st_blksize; /* Optimal block size for I/O. */
  48. int __pad2;
  49. __field64(__blkcnt_t, __blkcnt64_t, st_blocks); /* 512-byte blocks */
  50. #ifdef __USE_XOPEN2K8
  51. /* Nanosecond resolution timestamps are stored in a format
  52. equivalent to 'struct timespec'. This is the type used
  53. whenever possible but the Unix namespace rules do not allow the
  54. identifier 'timespec' to appear in the <sys/stat.h> header.
  55. Therefore we have to handle the use of this header in strictly
  56. standard-compliant sources special. */
  57. struct timespec st_atim; /* Time of last access. */
  58. struct timespec st_mtim; /* Time of last modification. */
  59. struct timespec st_ctim; /* Time of last status change. */
  60. # define st_atime st_atim.tv_sec /* Backward compatibility. */
  61. # define st_mtime st_mtim.tv_sec
  62. # define st_ctime st_ctim.tv_sec
  63. #else
  64. __time_t st_atime; /* Time of last access. */
  65. unsigned long int st_atimensec; /* Nscecs of last access. */
  66. __time_t st_mtime; /* Time of last modification. */
  67. unsigned long int st_mtimensec; /* Nsecs of last modification. */
  68. __time_t st_ctime; /* Time of last status change. */
  69. unsigned long int st_ctimensec; /* Nsecs of last status change. */
  70. #endif
  71. int __glibc_reserved[2];
  72. };
  73. #undef __field64
  74. #ifdef __USE_LARGEFILE64
  75. struct stat64
  76. {
  77. __dev_t st_dev; /* Device. */
  78. __ino64_t st_ino; /* File serial number. */
  79. __mode_t st_mode; /* File mode. */
  80. __nlink_t st_nlink; /* Link count. */
  81. __uid_t st_uid; /* User ID of the file's owner. */
  82. __gid_t st_gid; /* Group ID of the file's group.*/
  83. __dev_t st_rdev; /* Device number, if device. */
  84. __dev_t __pad1;
  85. __off64_t st_size; /* Size of file, in bytes. */
  86. __blksize_t st_blksize; /* Optimal block size for I/O. */
  87. int __pad2;
  88. __blkcnt64_t st_blocks; /* Nr. 512-byte blocks allocated. */
  89. #ifdef __USE_XOPEN2K8
  90. /* Nanosecond resolution timestamps are stored in a format
  91. equivalent to 'struct timespec'. This is the type used
  92. whenever possible but the Unix namespace rules do not allow the
  93. identifier 'timespec' to appear in the <sys/stat.h> header.
  94. Therefore we have to handle the use of this header in strictly
  95. standard-compliant sources special. */
  96. struct timespec st_atim; /* Time of last access. */
  97. struct timespec st_mtim; /* Time of last modification. */
  98. struct timespec st_ctim; /* Time of last status change. */
  99. #else
  100. __time_t st_atime; /* Time of last access. */
  101. unsigned long int st_atimensec; /* Nscecs of last access. */
  102. __time_t st_mtime; /* Time of last modification. */
  103. unsigned long int st_mtimensec; /* Nsecs of last modification. */
  104. __time_t st_ctime; /* Time of last status change. */
  105. unsigned long int st_ctimensec; /* Nsecs of last status change. */
  106. #endif
  107. int __glibc_reserved[2];
  108. };
  109. #endif
  110. /* Tell code we have these members. */
  111. #define _STATBUF_ST_BLKSIZE
  112. #define _STATBUF_ST_RDEV
  113. /* Nanosecond resolution time values are supported. */
  114. #define _STATBUF_ST_NSEC
  115. #endif /* _BITS_STRUCT_STAT_H */