Development C

#include
#include
#include
#include
#include
int main(int argc, char *argv[]) {
char buf[128] = {0};
int fd_in = -1, fd_out = -1;
long data_len;
if(argc != 2) {
fprintf(stderr, "Usage: MacBinary\n");
return 1;
}
if((fd_in = open(argv[1], O_RDONLY)) == -1) {
fprintf(stderr, "Error: `open(%s)'\n", argv[1]);
return 1;
}
read(fd_in, buf, 128);
buf[2 + buf[1]] = 0x00;
data_len = buf[86] + 256 * (buf[85] + 256 * (buf [84] + 256 * buf[83]));
if((fd_out = open(&buf[2], O_RDONLY|O_CREAT, 0666)) == -1) {
fprintf(stderr, "Error: `open(%s)'\n", &buf[2]);
return 1;
}
for(; data_len > 0; data_len -= 128)
write(fd_out, buf, read(fd_in ,buf, data_len < 128 ? data_len : 128));
close(fd_out);
close(fd_in);
return 0;
}