1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
13 #include <sys/types.h>
18 int main(int argc, char **argv)
20 char *dname1, *dname2;
21 int fddir1, fddir2, rc;
25 if (argc < 2 || argc > 3) {
26 fprintf(stderr, "usage: %s dirname1 [dirname2]\n", argv[0]);
36 //create the directory
37 fprintf(stderr, "creating directory %s\n", dname1);
38 rc = mkdir(dname1, 0744);
40 fprintf(stderr, "creating %s fails: %s\n",
41 dname1, strerror(errno));
46 fprintf(stderr, "opening directory\n");
47 fddir1 = open(dname1, O_RDONLY | O_DIRECTORY);
49 fprintf(stderr, "open %s fails: %s\n",
50 dname1, strerror(errno));
54 // doesn't matter if the two dirs are the same??
55 fddir2 = open(dname2, O_RDONLY | O_DIRECTORY);
57 fprintf(stderr, "open %s fails: %s\n",
58 dname2, strerror(errno));
64 if ( (dp = opendir(dname2)) == NULL) {
65 fprintf(stderr, "opendir() %s\n", strerror(errno));
72 fprintf (stderr, "unlinking %s\n", dname1);
75 fprintf(stderr, "unlink %s error: %s\n",
76 dname1, strerror(errno));
80 if (access(dname2, F_OK) == 0){
81 fprintf(stderr, "%s still exists\n", dname2);
85 if (access(dname1, F_OK) == 0){
86 fprintf(stderr, "%s still exists\n", dname1);
91 rc = fchmod (fddir1, 0777);
94 fprintf(stderr, "fchmod unlinked dir fails %s\n",
99 // fstat two dirs to check if they are the same
100 rc = fstat(fddir1, &st1);
103 fprintf(stderr, "fstat unlinked dir %s fails %s\n",
104 dname1, strerror(errno));
108 rc = fstat(fddir2, &st2);
110 fprintf(stderr, "fstat dir %s fails %s\n",
111 dname2, strerror(errno));
115 if (st1.st_mode != st2.st_mode) { // can we do this?
116 fprintf(stderr, "fstat different value on %s and %s\n", dname1, dname2);
120 fprintf(stderr, "Ok, everything goes well.\n");