File: sys-statx.c

package info (click to toggle)
valgrind 1%3A3.19.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 170,080 kB
  • sloc: ansic: 782,981; exp: 26,134; xml: 22,780; asm: 14,072; cpp: 7,903; makefile: 6,768; perl: 6,097; sh: 5,669; javascript: 981; awk: 148
file content (59 lines) | stat: -rw-r--r-- 1,355 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Test (somewhat) stats and stat.  */
#define _GNU_SOURCE
#include "config.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <string.h>
#include <sys/syscall.h>
#ifndef HAVE_STRUCT_STATX_IN_SYS_STAT_H
#include <linux/stat.h>
#endif
#include <errno.h>

int check_stat2;

#define field(fieldname,s) s->st_##fieldname
#if defined(__NR_statx)
#define checkfield(fieldname) \
   assert(!check_stat2 || stat1.st_##fieldname == stat2.stx_##fieldname)
#else
#define checkfield(fieldname) \
   assert(!check_stat2 || stat1.st_##fieldname == stat2.st_##fieldname)
#endif

int main (void)
{
   struct stat stat1;

   memset(&stat1, 0x55, sizeof(stat1));

   assert (stat ("/tmp", &stat1) == 0);
#if defined(__NR_statx)
   struct statx stat2;
   memset(&stat2, 0x22, sizeof(stat2));
   if (syscall (__NR_statx, 0, "/tmp", 0, STATX_ALL, &stat2) == 0)
      check_stat2 = 1;
   else {
      if (errno == ENOSYS)
         check_stat2 = 0; // Defined but not provided by kernel.
      else
         check_stat2 = 1; // Probably better fail ...
   }
#else
   struct stat stat2;
   check_stat2 = 1;
   memset(&stat2, 0x22, sizeof(stat2));
   assert (stat ("/tmp", &stat2) == 0);
#endif

   checkfield(nlink);
   checkfield(uid);
   checkfield(gid);
   checkfield(mode);
   checkfield(ino);

   return 0;
}