#define BUFSIZZ 5120 // caseB: 5120 fails soon after a windows format a: // maybe there is an error or not, from windows. // hard to tell, but in any case, the return value // is not correct. If it works once then you // can use any size after that point. // john refling. caseB.c /* OUTPUT: this case triggers bad return value open floppy, which is OK fno = 3, errno = 0 'No error' ie: fopen() OK try write() 5120 which is NOT ok, sometimes. RV = 0xffffffff or 4294967295, errno = 13 'Permission denied' but nothing actually written RV IS NOT == 0 RV IS NOT < 0 RV IS NOT == -1 RV IS NOT == -1L RV IS == -1U !!! 32 bit -1 !!! no way to detect this write() failure! */ #include #include #include #include #include #include #include int main(int argc, char *argv[]) { char *buf = calloc(1, BUFSIZZ); printf("\nopen floppy, which is OK\n"); int fno = open("/dev/floppy", O_RDWR, 0777); printf("fno = %d, errno = %d '%s'\n", fno, errno, strerror(errno)); printf("ie: fopen() OK\n\n"); // write some data to the floppy, when this fails, // it seems to put a "32 bit -1" in return value, // not a 64 bit -1 !!! printf("try write() 5120 which is NOT ok\n"); errno = 0; ssize_t RV = write(fno, buf, BUFSIZZ); // print out the RV, it is a ssize_t, use %ld printf("RV = 0x%lx or %ld, errno = %d '%s'\n\nbut nothing actually written\n", (long unsigned)RV, RV, errno, strerror(errno)); if (512 == RV) return(0); // see what constants RV matches: fprintf(stderr, "RV %s == 0\n", (RV == 0)?"IS":"IS NOT"); fprintf(stderr, "RV %s < 0\n", (RV < 0)?"IS":"IS NOT"); fprintf(stderr, "RV %s == -1\n", (RV == -1)?"IS":"IS NOT"); fprintf(stderr, "RV %s == -1L\n", (RV == -1L)?"IS":"IS NOT"); fprintf(stderr, "RV %s == -1U\n\n", (RV == -1U)?"IS":"IS NOT"); fprintf(stderr, "\nno way to detect this failure!\n"); return 0; }