Add missing zstd.h to coregrind Makefile.am noinst_HEADERS
[valgrind.git] / memcheck / tests / linux / sys-statx.c
blob3cbbd3404949621c783f1a89cfce65cea442bc12
1 /* Test (somewhat) stats and stat. */
2 #define _GNU_SOURCE
3 #include "config.h"
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <unistd.h>
7 #include <fcntl.h>
8 #include <assert.h>
9 #include <string.h>
10 #include <sys/syscall.h>
11 #if defined(MUSL_LIBC)
12 /* musl has __NR_statx but not the structs that it needs */
13 #undef __NR_statx
14 #else
15 #if !defined(HAVE_STRUCT_STATX_IN_SYS_STAT_H)
16 #include <linux/stat.h>
17 #endif /* HAVE_STRUCT_STATX_IN_SYS_STAT_H */
18 #endif /* MUSL_LIBC */
19 #include <errno.h>
21 int check_stat2;
23 #define field(fieldname,s) s->st_##fieldname
24 #if defined(__NR_statx)
25 #define checkfield(fieldname) \
26 assert(!check_stat2 || stat1.st_##fieldname == stat2.stx_##fieldname)
27 #else
28 #define checkfield(fieldname) \
29 assert(!check_stat2 || stat1.st_##fieldname == stat2.st_##fieldname)
30 #endif
32 int main (void)
34 struct stat stat1;
36 memset(&stat1, 0x55, sizeof(stat1));
38 assert (stat ("/tmp", &stat1) == 0);
39 #if defined(__NR_statx)
40 struct statx stat2;
41 memset(&stat2, 0x22, sizeof(stat2));
42 if (syscall (__NR_statx, 0, "/tmp", 0, STATX_ALL, &stat2) == 0)
43 check_stat2 = 1;
44 else {
45 if (errno == ENOSYS)
46 check_stat2 = 0; // Defined but not provided by kernel.
47 else
48 check_stat2 = 1; // Probably better fail ...
50 #else
51 struct stat stat2;
52 check_stat2 = 1;
53 memset(&stat2, 0x22, sizeof(stat2));
54 assert (stat ("/tmp", &stat2) == 0);
55 #endif
57 checkfield(nlink);
58 checkfield(uid);
59 checkfield(gid);
60 checkfield(mode);
61 checkfield(ino);
63 return 0;