Magellan Linux

Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/tests/stat.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1709 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

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, (uintmax_t) st.st_blocks);
38
39 #ifdef _STATBUF_ST_NSEC
40 printf(" st_atim = %jd.%09u\n"
41 " st.mtim = %jd.%09u\n"
42 " st.ctim = %jd.%09u\n",
43 (uintmax_t) st.st_atim.tv_sec, (unsigned int)st.st_atim.tv_nsec,
44 (uintmax_t) st.st_mtim.tv_sec, (unsigned int)st.st_mtim.tv_nsec,
45 (uintmax_t) st.st_ctim.tv_sec, (unsigned int)st.st_ctim.tv_nsec);
46 #else
47 printf(" st_atime = %jd\n"
48 " st.mtime = %jd\n"
49 " st.ctime = %jd\n",
50 (uintmax_t) st.st_atime,
51 (uintmax_t) st.st_mtime, (uintmax_t) st.st_ctime);
52 #endif
53 }
54
55 int main(int argc, char *argv[])
56 {
57 int i;
58
59 for (i = 1; i < argc; i++)
60 do_stat(argv[i]);
61
62 return 0;
63 }