/* bintoiso--Extract an ISO image out of a CDRWin .BIN dump * * Peter Backes, 2006 * Public Domain */ #include #include #include #include int main(int argc, char *argv[]) { for (argc--, argv++; argc; argc--, argv++) { char *x, *y, *z, buf[2352]; FILE *in, *out; int len, n = 0; if (!(x = strrchr(*argv, '/'))) x = *argv; else x++; z = (y = strrchr(x, '.')) ? strcpy(strncpy(malloc(y-x+5), x, y-x) + (y-x), ".iso") - (y-x) : strcat(strcpy(malloc(strlen(x) + 5), x), ".iso"); if (!(in = fopen(*argv, "rb"))) { fprintf(stderr, "can't open %s for reading.\n", *argv); return EXIT_FAILURE; } if (!(out = fopen(z, "wb"))) { fprintf(stderr, "can't open %s for writing.\n", z); fclose(in); return EXIT_FAILURE; } for (;(len = fread(buf, 1, 2352, in)) == 2352; n++) fwrite(buf+16, 1, 2048, out); printf("%s: %d recs", *argv, n); if (len) printf(", short by %d.\n", len); else printf(".\n"); fclose(out); fclose(in); free(z); } return EXIT_SUCCESS; }