1 #include <sys/stat.h>
2 #include <errno.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <time.h>
6 #include <stdint.h>
7 #include <unistd.h>
8 #include "test.h"
9
10 #define TEST(c, ...) ((c) ? 1 : (t_error(#c" failed: " __VA_ARGS__),0))
11
12 extern int __stat_time64(const char *__restrict, struct stat *__restrict);
13
main(void)14 int main(void)
15 {
16 struct stat st;
17 FILE *f;
18 time_t t;
19
20 if (TEST(stat(".",&st)==0, "errno = %s\n", strerror(errno))) {
21 TEST(S_ISDIR(st.st_mode), "\n");
22 TEST(st.st_nlink>0, "%ju\n", (uintmax_t)st.st_nlink);
23 t = time(0);
24 TEST(st.st_ctime<=t, "%jd > %jd\n", (intmax_t)st.st_ctime, (intmax_t)t);
25 TEST(st.st_mtime<=t, "%jd > %jd\n", (intmax_t)st.st_mtime, (intmax_t)t);
26 TEST(st.st_atime<=t, "%jd > %jd\n", (intmax_t)st.st_atime, (intmax_t)t);
27 }
28
29 if (TEST(__stat_time64(".",&st)==0, "errno = %s\n", strerror(errno))) {
30 TEST(S_ISDIR(st.st_mode), "\n");
31 TEST(st.st_nlink>0, "%ju\n", (uintmax_t)st.st_nlink);
32 t = time(0);
33 TEST(st.st_ctime<=t, "%jd > %jd\n", (intmax_t)st.st_ctime, (intmax_t)t);
34 TEST(st.st_mtime<=t, "%jd > %jd\n", (intmax_t)st.st_mtime, (intmax_t)t);
35 TEST(st.st_atime<=t, "%jd > %jd\n", (intmax_t)st.st_atime, (intmax_t)t);
36 }
37
38 if (TEST(stat("/dev/null",&st)==0, "errno = %s\n", strerror(errno))) {
39 TEST(S_ISCHR(st.st_mode), "\n");
40 }
41
42 if ((f = tmpfile())) {
43 fputs("hello", f);
44 fflush(f);
45 if (TEST(fstat(fileno(f),&st)==0, "errnp = %s\n", strerror(errno))) {
46 TEST(st.st_uid==geteuid(), "%d vs %d\n", (int)st.st_uid, (int)geteuid());
47 TEST(st.st_gid==getegid(), "%d vs %d\n", (int)st.st_uid, (int)geteuid());
48 TEST(st.st_size==5, "%jd vs 5\n", (intmax_t)st.st_size);
49 }
50 fclose(f);
51 }
52
53 return t_status;
54 }
55