chiark / gitweb /
[PATCH] support log-priority levels in udev.conf
[elogind.git] / klibc / klibc / tests / stat.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <errno.h>
4 #include <sys/stat.h>
5 #include <sys/sysmacros.h>
6 #include <sys/types.h>
7
8 static void do_stat(const char *path)
9 {
10   struct stat st;
11
12   if ( stat(path, &st) ) {
13     perror(path);
14     exit(1);
15   }
16
17   printf("Path = %s\n"
18          "   st_dev       = %#jx (%u,%u)\n"
19          "   st_ino       = %ju\n"
20          "   st_mode      = %#jo\n"
21          "   st_nlink     = %ju\n"
22          "   st_uid       = %ju\n"
23          "   st_gid       = %ju\n"
24          "   st_rdev      = %#jx (%u,%u)\n"
25          "   st_size      = %ju\n"
26          "   st_blksize   = %ju\n"
27          "   st_blocks    = %ju\n",
28          path,
29          (uintmax_t)st.st_dev, major(st.st_dev), minor(st.st_dev),
30          (uintmax_t)st.st_ino,
31          (uintmax_t)st.st_mode,
32          (uintmax_t)st.st_nlink,
33          (uintmax_t)st.st_uid,
34          (uintmax_t)st.st_gid,
35          (uintmax_t)st.st_rdev, major(st.st_rdev), minor(st.st_rdev),
36          (uintmax_t)st.st_size,
37          (uintmax_t)st.st_blksize,
38          (uintmax_t)st.st_blocks);
39
40 #ifdef _STATBUF_ST_NSEC
41   printf("   st_atim      = %jd.%09u\n"
42          "   st.mtim      = %jd.%09u\n"
43          "   st.ctim      = %jd.%09u\n",
44          (uintmax_t)st.st_atim.tv_sec, (unsigned int)st.st_atim.tv_nsec,
45          (uintmax_t)st.st_mtim.tv_sec, (unsigned int)st.st_mtim.tv_nsec,
46          (uintmax_t)st.st_ctim.tv_sec, (unsigned int)st.st_ctim.tv_nsec);
47 #else
48   printf("   st_atime     = %jd\n"
49          "   st.mtime     = %jd\n"
50          "   st.ctime     = %jd\n",
51          (uintmax_t)st.st_atime,
52          (uintmax_t)st.st_mtime,
53          (uintmax_t)st.st_ctime);
54 #endif
55 }
56
57 int main(int argc, char *argv[])
58 {
59   int i;
60
61   for ( i = 1 ; i < argc ; i++ )
62     do_stat(argv[i]);
63
64   return 0;
65 }