1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
15 #include <sys/types.h>
20 int main(int argc, char **argv)
22 char *dname1, *dname2;
23 int fddir1, fddir2, rc;
27 if (argc < 2 || argc > 3) {
28 fprintf(stderr, "usage: %s dirname1 [dirname2]\n", argv[0]);
38 //create the directory
39 fprintf(stderr, "creating directory %s\n", dname1);
40 rc = mkdir(dname1, 0744);
42 fprintf(stderr, "creating %s fails: %s\n",
43 dname1, strerror(errno));
48 fprintf(stderr, "opening directory\n");
49 fddir1 = open(dname1, O_RDONLY | O_DIRECTORY);
51 fprintf(stderr, "open %s fails: %s\n",
52 dname1, strerror(errno));
56 // doesn't matter if the two dirs are the same??
57 fddir2 = open(dname2, O_RDONLY | O_DIRECTORY);
59 fprintf(stderr, "open %s fails: %s\n",
60 dname2, strerror(errno));
66 if ( (dp = opendir(dname2)) == NULL) {
67 fprintf(stderr, "opendir() %s\n", strerror(errno));
74 fprintf (stderr, "unlinking %s\n", dname1);
77 fprintf(stderr, "unlink %s error: %s\n",
78 dname1, strerror(errno));
82 if (access(dname2, F_OK) == 0){
83 fprintf(stderr, "%s still exists\n", dname2);
87 if (access(dname1, F_OK) == 0){
88 fprintf(stderr, "%s still exists\n", dname1);
93 rc = fchmod (fddir1, 0777);
96 fprintf(stderr, "fchmod unlinked dir fails %s\n",
101 // fstat two dirs to check if they are the same
102 rc = fstat(fddir1, &st1);
105 fprintf(stderr, "fstat unlinked dir %s fails %s\n",
106 dname1, strerror(errno));
110 rc = fstat(fddir2, &st2);
112 fprintf(stderr, "fstat dir %s fails %s\n",
113 dname2, strerror(errno));
117 if (st1.st_mode != st2.st_mode) { // can we do this?
118 fprintf(stderr, "fstat different value on %s and %s\n", dname1, dname2);
122 fprintf(stderr, "Ok, everything goes well.\n");