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