"Fossies" - the Fresh Open Source Software Archive 
Member "afio-2.5.2/regtest/cmpstat.c" (30 Nov 2018, 1522 Bytes) of package /linux/misc/afio-2.5.2.tgz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "cmpstat.c" see the
Fossies "Dox" file reference documentation.
1
2 /* compare status of files argv[1] and argv[2],
3 testing if afio restored argv[2] right.
4 if we have an argv[3], then do not compare uid/gid.
5 returns 1 if the test is not OK or other things are not OK.
6 prints reason for that to stdout.
7 */
8
9 #include <stdio.h>
10 #include <string.h>
11 #include <unistd.h>
12 #include <sys/stat.h>
13 #include <time.h>
14 #include <stdlib.h>
15
16 char ** av;
17
18 void fatal(const char *s)
19 {
20 printf("cmpstat %s %s: %s\n",av[1],av[2],s);
21 exit(1);
22 }
23
24 void fatalls(const char *s)
25 {
26 char buf[1000];
27 printf("cmpstat %s %s: %s\n",av[1],av[2],s);
28 sprintf(buf,"ls -ld \"%s\" \"%s\"",av[1],av[2]);
29 system(buf);
30 exit(1);
31 }
32
33
34 int main(int argc, char ** argv)
35 {
36 struct stat s1,s2;
37
38 av=argv;
39
40 if(argc>4) { printf("cmpstat: wrong number of args\n"); return 1; }
41
42 if(lstat(argv[1],&s1)) fatal("file 1 not found");
43
44 if(lstat(argv[2],&s2)) fatal("file 2 not found");
45
46 if(s1.st_nlink != s2.st_nlink) fatalls("nlink difference");
47
48 if(argc!=4)
49 {
50 if(s1.st_uid != s2.st_uid) fatalls("uid difference");
51 if(s1.st_gid != s2.st_gid) fatalls("gid difference");
52 }
53
54 if(!(S_ISDIR(s1.st_mode) || S_ISLNK(s1.st_mode)))
55 if(s1.st_mtime != s2.st_mtime) fatalls("mtime difference");
56
57 if(S_ISCHR(s1.st_mode) || S_ISBLK(s1.st_mode))
58 {
59 if(s1.st_rdev != s2.st_rdev) fatalls("device number difference");
60 }
61
62 if(s1.st_mode != s2.st_mode) fatalls("mode difference");
63
64 if(!(S_ISDIR(s1.st_mode)))
65 if(s1.st_size != s2.st_size) fatalls("size difference");
66
67 return 0;
68 }