1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *  * Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *  * Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in
12  *    the documentation and/or other materials provided with the
13  *    distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <sys/stat.h>
30 
31 #include "header_checks.h"
32 
sys_stat_h()33 static void sys_stat_h() {
34   TYPE(struct stat);
35 #if defined(__BIONIC__) && (defined(__arm__) || defined(__i386__))
36   STRUCT_MEMBER(struct stat, unsigned long long, st_dev);
37 #else
38   STRUCT_MEMBER(struct stat, dev_t, st_dev);
39 #endif
40 #if defined(__BIONIC__) && !defined(__LP64__)
41   STRUCT_MEMBER(struct stat, unsigned long long, st_ino);
42 #else
43   STRUCT_MEMBER(struct stat, ino_t, st_ino);
44 #endif
45 #if defined(__BIONIC__) && (defined(__arm__) || defined(__i386__))
46   STRUCT_MEMBER(struct stat, unsigned int, st_mode);
47 #else
48   STRUCT_MEMBER(struct stat, mode_t, st_mode);
49 #endif
50 #if defined(__BIONIC__) && defined(__x86_64__)
51   // We can't just fix the x86_64 nlink_t because it's ABI via <fts.h>.
52   STRUCT_MEMBER(struct stat, unsigned long, st_nlink);
53 #else
54   STRUCT_MEMBER(struct stat, nlink_t, st_nlink);
55 #endif
56   STRUCT_MEMBER(struct stat, uid_t, st_uid);
57   STRUCT_MEMBER(struct stat, gid_t, st_gid);
58 #if defined(__BIONIC__) && (defined(__arm__) || defined(__i386__))
59   STRUCT_MEMBER(struct stat, unsigned long long, st_rdev);
60 #else
61   STRUCT_MEMBER(struct stat, dev_t, st_rdev);
62 #endif
63 #if defined(__BIONIC__) && !defined(__LP64__)
64   STRUCT_MEMBER(struct stat, long long, st_size);
65 #else
66   STRUCT_MEMBER(struct stat, off_t, st_size);
67 #endif
68   STRUCT_MEMBER(struct stat, struct timespec, st_atim);
69   STRUCT_MEMBER(struct stat, struct timespec, st_mtim);
70   STRUCT_MEMBER(struct stat, struct timespec, st_ctim);
71 #if defined(__BIONIC__)
72 #if defined(__aarch64__)
73   STRUCT_MEMBER(struct stat, int, st_blksize);
74 #elif defined(__x86_64__)
75   STRUCT_MEMBER(struct stat, long, st_blksize);
76 #else
77   STRUCT_MEMBER(struct stat, unsigned long, st_blksize);
78 #endif
79 #else
80   STRUCT_MEMBER(struct stat, blksize_t, st_blksize);
81 #endif
82 #if defined(__BIONIC__)
83 #if defined(__LP64__)
84   STRUCT_MEMBER(struct stat, long, st_blocks);
85 #else
86   STRUCT_MEMBER(struct stat, unsigned long long, st_blocks);
87 #endif
88 #else
89   STRUCT_MEMBER(struct stat, blkcnt_t, st_blocks);
90 #endif
91 
92   TYPE(blkcnt_t);
93   TYPE(blksize_t);
94   TYPE(dev_t);
95   TYPE(ino_t);
96   TYPE(mode_t);
97   TYPE(nlink_t);
98   TYPE(uid_t);
99   TYPE(gid_t);
100   TYPE(off_t);
101   TYPE(time_t);
102 
103   TYPE(struct timespec);
104 
105 #if !defined(st_atime)
106 #error st_atime
107 #endif
108 #if !defined(st_ctime)
109 #error st_ctime
110 #endif
111 #if !defined(st_mtime)
112 #error st_mtime
113 #endif
114 
115 #include "sys_stat_h_mode_constants.h"
116 #include "sys_stat_h_file_type_test_macros.h"
117 
118 #if !defined(S_TYPEISMQ)
119 #error S_TYPEISMQ
120 #endif
121 #if !defined(S_TYPEISSEM)
122 #error S_TYPEISSEM
123 #endif
124 #if !defined(S_TYPEISSHM)
125 #error S_TYPEISSHM
126 #endif
127 
128 #if !defined(__BIONIC__) && !defined(__GLIBC__)
129 #if !defined(S_TYPEISTMO)
130 #error S_TYPEISTMO
131 #endif
132 #endif
133 
134   MACRO(UTIME_NOW);
135   MACRO(UTIME_OMIT);
136 
137   FUNCTION(chmod, int (*f)(const char*, mode_t));
138   FUNCTION(fchmod, int (*f)(int, mode_t));
139   FUNCTION(fchmodat, int (*f)(int, const char*, mode_t, int));
140   FUNCTION(fstat, int (*f)(int, struct stat*));
141   FUNCTION(fstatat, int (*f)(int, const char*, struct stat*, int));
142   FUNCTION(futimens, int (*f)(int, const struct timespec[2]));
143   FUNCTION(lstat, int (*f)(const char*, struct stat*));
144   FUNCTION(lstat, int (*f)(const char*, struct stat*));
145   FUNCTION(mkdir, int (*f)(const char*, mode_t));
146   FUNCTION(mkdirat, int (*f)(int, const char*, mode_t));
147   FUNCTION(mkfifo, int (*f)(const char*, mode_t));
148   FUNCTION(mkfifoat, int (*f)(int, const char*, mode_t));
149   FUNCTION(mknod, int (*f)(const char*, mode_t, dev_t));
150   FUNCTION(mknodat, int (*f)(int, const char*, mode_t, dev_t));
151   FUNCTION(stat, int (*f)(const char*, struct stat*));
152   FUNCTION(umask, mode_t (*f)(mode_t));
153   FUNCTION(utimensat, int (*f)(int, const char*, const struct timespec[2], int));
154 }
155