-
Notifications
You must be signed in to change notification settings - Fork 1
/
scsi2ide.c
52 lines (49 loc) · 1.61 KB
/
scsi2ide.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <errno.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
int status;
if (argc == 3) {
const char *in_fn = argv[1];
FILE *in_fp = fopen(in_fn, "rb");
if (in_fp) {
const char *out_fn = argv[2];
FILE *out_fp = fopen(out_fn, "wb");
if (out_fp) {
int byte;
status = 0;
while ((byte = getc(in_fp)) != EOF) {
if (putc(byte, out_fp) == EOF) {
fprintf(stderr, "scsi2ide: write error on %s: %s\n", out_fn, strerror(errno));
status = 4;
break;
}
if (putc(0, out_fp) == EOF) {
fprintf(stderr, "scsi2ide: write error on %s: %s\n", out_fn, strerror(errno));
status = 4;
break;
}
}
if (fclose(out_fp)) {
fprintf(stderr, "scsi2ide: write error on %s: %s\n", out_fn, strerror(errno));
status = 4;
}
}
else {
fprintf(stderr, "scsi2ide: unable to open '%s' for writing: %s\n", out_fn, strerror(errno));
status = 3;
}
fclose(in_fp);
}
else {
fprintf(stderr, "scsi2ide: unable to open '%s' for reading: %s\n", in_fn, strerror(errno));
status = 2;
}
}
else {
fputs("Usage: scsi2ide <scsi-file> <ide-file>\n", stderr);
status = 1;
}
return status;
}