1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
10 #include <sys/types.h>
15 int main(int argc, char **argv)
17 char *dname1, *dname2;
18 int fddev1, fddev2, rc;
22 if (argc < 2 || argc > 3) {
23 fprintf(stderr, "usage: %s filename1 [filename2]\n", argv[0]);
33 //create the special file (right now only test on pipe)
34 fprintf(stderr, "creating special file %s\n", dname1);
35 rc = mknod(dname1, 0777|S_IFIFO, 0);
37 fprintf(stderr, "creating %s fails: %s\n",
38 dname1, strerror(errno));
42 // open the special file again
43 fprintf(stderr, "opening file\n");
44 fddev1 = open(dname1, O_RDONLY | O_NONBLOCK);
46 fprintf(stderr, "open %s fails: %s\n",
47 dname1, strerror(errno));
51 // doesn't matter if the two dirs are the same??
52 fddev2 = open(dname2, O_RDONLY | O_NONBLOCK);
54 fprintf(stderr, "open %s fails: %s\n",
55 dname2, strerror(errno));
59 // delete the special file
60 fprintf (stderr, "unlinking %s\n", dname1);
63 fprintf(stderr, "unlink %s error: %s\n",
64 dname1, strerror(errno));
68 if (access(dname2, F_OK) == 0){
69 fprintf(stderr, "%s still exists\n", dname2);
73 if (access(dname1, F_OK) == 0){
74 fprintf(stderr, "%s still exists\n", dname1);
78 // fchmod one special file
79 rc = fchmod (fddev1, 0777);
82 fprintf(stderr, "fchmod unlinked special file %s fails: %s\n",
83 dname1, strerror(errno));
87 // fstat two files to check if they are the same
88 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");