1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
12 #include <sys/types.h>
17 int main(int argc, char **argv)
19 char *dname1, *dname2;
20 int fddir1, fddir2, rc;
24 if (argc < 2 || argc > 3) {
25 fprintf(stderr, "usage: %s dirname1 [dirname2]\n", argv[0]);
35 //create the directory
36 fprintf(stderr, "creating directory %s\n", dname1);
37 rc = mkdir(dname1, 0744);
39 fprintf(stderr, "creating %s fails: %s\n",
40 dname1, strerror(errno));
45 fprintf(stderr, "opening directory\n");
46 fddir1 = open(dname1, O_RDONLY | O_DIRECTORY);
48 fprintf(stderr, "open %s fails: %s\n",
49 dname1, strerror(errno));
53 // doesn't matter if the two dirs are the same??
54 fddir2 = open(dname2, O_RDONLY | O_DIRECTORY);
56 fprintf(stderr, "open %s fails: %s\n",
57 dname2, strerror(errno));
63 if ( (dp = opendir(dname2)) == NULL) {
64 fprintf(stderr, "opendir() %s\n", strerror(errno));
71 fprintf (stderr, "unlinking %s\n", dname1);
74 fprintf(stderr, "unlink %s error: %s\n",
75 dname1, strerror(errno));
79 if (access(dname2, F_OK) == 0){
80 fprintf(stderr, "%s still exists\n", dname2);
84 if (access(dname1, F_OK) == 0){
85 fprintf(stderr, "%s still exists\n", dname1);
90 rc = fchmod (fddir1, 0777);
93 fprintf(stderr, "fchmod unlinked dir fails %s\n",
98 // fstat two dirs to check if they are the same
99 rc = fstat(fddir1, &st1);
102 fprintf(stderr, "fstat unlinked dir %s fails %s\n",
103 dname1, strerror(errno));
107 rc = fstat(fddir2, &st2);
109 fprintf(stderr, "fstat dir %s fails %s\n",
110 dname2, strerror(errno));
114 if (st1.st_mode != st2.st_mode) { // can we do this?
115 fprintf(stderr, "fstat different value on %s and %s\n", dname1, dname2);
119 fprintf(stderr, "Ok, everything goes well.\n");