// // demonstrate/test a Cygwin bug. // dup of a serial file descriptor // causes confusion. One symptom // is that select() on the dup // result will always return -1, // with an errno of 0. // // -Billy #include #include #include #include #include #include int main(int argc, char **argv) { char *device = "/dev/com1"; if(argc>1){ device = argv[1]; } int comm = open(device, O_RDONLY | O_NOCTTY); if(comm == -1) { fprintf(stderr, "open '%s' failed: %s\n", device, strerror(errno)); return 1; } int newcomm = dup(comm); if(newcomm==-1){ perror("dup"); return -1; } fd_set rfds; FD_ZERO(&rfds); FD_SET(newcomm, &rfds); int nsel = select(newcomm+1, &rfds, 0, 0, 0); fprintf(stderr, "select: nsel=%d\n", nsel); if(nsel==-1){ fprintf(stderr, "errno=%d, %s\n", errno, strerror(errno)); return 1; } return 0; }