make_b: clean up whitespace

This commit is contained in:
Vince Weaver 2016-12-08 22:04:19 -05:00
parent 75bfb3c573
commit 2f482f68aa

View File

@ -8,55 +8,55 @@
int main(int argc, char **argv) { int main(int argc, char **argv) {
int in_fd,out_fd,offset,write_result; int in_fd,out_fd,offset,write_result;
unsigned char buffer[256]; unsigned char buffer[256];
int result,file_size; int result,file_size;
struct stat file_info; struct stat file_info;
if (argc!=4) { if (argc!=4) {
printf("MAKE_B version %s\b",VERSION); printf("MAKE_B version %s\b",VERSION);
printf(" Usage: %s in_file out_file offset\n\n",argv[0]); printf(" Usage: %s in_file out_file offset\n\n",argv[0]);
printf("\tin_file : input file\n"); printf("\tin_file : input file\n");
printf("\tout_file : output file\n"); printf("\tout_file : output file\n");
printf("\toffset : offset which file should be loaded\n\n"); printf("\toffset : offset which file should be loaded\n\n");
exit(1); exit(1);
} }
if (stat(argv[1],&file_info)<0) { if (stat(argv[1],&file_info)<0) {
printf("Error! %s not found!\n",argv[1]); printf("Error! %s not found!\n",argv[1]);
exit(2); exit(2);
} }
file_size=(int)file_info.st_size; file_size=(int)file_info.st_size;
if ((in_fd=open(argv[1],O_RDONLY))<0) { if ((in_fd=open(argv[1],O_RDONLY))<0) {
printf("Error opening %s!\n",argv[1]); printf("Error opening %s!\n",argv[1]);
exit(3); exit(3);
} }
if ((out_fd=open(argv[2],O_WRONLY|O_CREAT,0666))<0) { if ((out_fd=open(argv[2],O_WRONLY|O_CREAT,0666))<0) {
printf("Error opening %s\n",argv[2]); printf("Error opening %s\n",argv[2]);
exit(4); exit(4);
} }
offset=strtol(argv[3],NULL,0); offset=strtol(argv[3],NULL,0);
buffer[0]=offset&0xff; buffer[0]=offset&0xff;
buffer[1]=(offset>>8)&0xff; buffer[1]=(offset>>8)&0xff;
buffer[2]=file_size&0xff; buffer[2]=file_size&0xff;
buffer[3]=(file_size>>8)&0xff; buffer[3]=(file_size>>8)&0xff;
write_result=write(out_fd,&buffer,4); write_result=write(out_fd,&buffer,4);
while( (result=read(in_fd,&buffer,256))>0) { while( (result=read(in_fd,&buffer,256))>0) {
write_result=write(out_fd,&buffer,result); write_result=write(out_fd,&buffer,result);
} }
if (write_result<0) fprintf(stderr,"Error writing\n"); if (write_result<0) fprintf(stderr,"Error writing\n");
close(in_fd); close(in_fd);
close(out_fd); close(out_fd);
return 0; return 0;
} }