1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
10 #include <sys/types.h>
17 int main(int argc, char **argv)
19 char *dname1, *dname2;
20 int fddev1, fddev2, rc;
24 if (argc < 2 || argc > 3) {
25 fprintf(stderr, "usage: %s filename1 [filename2]\n", argv[0]);
35 //create the special file (right now only test on pipe)
36 fprintf(stderr, "creating special file %s\n", dname1);
37 rc = mknod(dname1, 0777|S_IFIFO, 0);
39 fprintf(stderr, "creating %s fails: %s\n",
40 dname1, strerror(errno));
44 // open the special file again
45 fprintf(stderr, "opening file\n");
46 fddev1 = open(dname1, O_RDONLY | O_NONBLOCK);
48 fprintf(stderr, "open %s fails: %s\n",
49 dname1, strerror(errno));
53 // doesn't matter if the two dirs are the same??
54 fddev2 = open(dname2, O_RDONLY | O_NONBLOCK);
56 fprintf(stderr, "open %s fails: %s\n",
57 dname2, strerror(errno));
61 // delete the special file
62 fprintf (stderr, "unlinking %s\n", dname1);
65 fprintf(stderr, "unlink %s error: %s\n",
66 dname1, strerror(errno));
70 if (access(dname2, F_OK) == 0) {
71 fprintf(stderr, "%s still exists\n", dname2);
75 if (access(dname1, F_OK) == 0) {
76 fprintf(stderr, "%s still exists\n", dname1);
80 // fchmod one special file
81 rc = fchmod (fddev1, 0777);
83 fprintf(stderr, "fchmod unlinked special file %s fails: %s\n",
84 dname1, strerror(errno));
88 // fstat two files to check if they are the same
89 rc = fstat(fddev1, &st1);
91 fprintf(stderr, "fstat unlinked special file %s fails: %s\n",
92 dname1, strerror(errno));
96 rc = fstat(fddev2, &st2);
98 fprintf(stderr, "fstat file %s fails: %s\n",
99 dname2, strerror(errno));
103 if (st1.st_mode != st2.st_mode) { // can we do this?
104 fprintf(stderr, "fstat different value on %s and %s\n", dname1, dname2);
108 fprintf(stderr, "Ok, everything goes well.\n");