Lines 240-254
Link Here
|
240 |
|
240 |
|
241 |
|
241 |
|
242 |
|
242 |
|
|
|
243 |
/* 14 Dec 2002: re-wrote to be more portable - don't assume two's-complement |
244 |
* representation for integers, and fix bug when sizeof(long) > 4. |
245 |
*/ |
243 |
long readlong() |
246 |
long readlong() |
244 |
{ |
247 |
{ |
245 |
long val1=0; |
248 |
long val1=0; |
246 |
|
249 |
int i,j; |
247 |
val1=myci()<<24L; |
|
|
248 |
val1|=myci()<<16L; |
249 |
val1|=myci()<<8; |
250 |
val1|=myci(); |
251 |
|
250 |
|
|
|
251 |
for (i=0; i<4; i++) { |
252 |
j = myci(); |
253 |
if (j==-1) return -1L; |
254 |
val1 = (val1<<8) + j; |
255 |
} |
252 |
return val1; |
256 |
return val1; |
253 |
} |
257 |
} |
254 |
int rbs() |
258 |
int rbs() |
Lines 309-315
Link Here
|
309 |
bmw=bmh=byteswide=0; |
313 |
bmw=bmh=byteswide=0; |
310 |
while( (type=readlong()) ) |
314 |
while( (type=readlong()) ) |
311 |
{ |
315 |
{ |
312 |
if(type==0xffffffffL) break; |
316 |
if(type==-1L) break; |
313 |
size=readlong(); |
317 |
size=readlong(); |
314 |
if(size&1) size++; |
318 |
if(size&1) size++; |
315 |
if(type==BMHD) |
319 |
if(type==BMHD) |
Lines 402-417
Link Here
|
402 |
input=open(resourcename,O_RDONLY); |
406 |
input=open(resourcename,O_RDONLY); |
403 |
if(input<0) return -1; |
407 |
if(input<0) return -1; |
404 |
got=read(input,buff,8); |
408 |
got=read(input,buff,8); |
405 |
if(got!=8) return -2; |
409 |
if(got!=8) {close(input);return -2;} |
406 |
if (strncmp(buff,"SCAV",4)) return -3; |
410 |
if (strncmp(buff,"SCAV",4)) {close(input);return -3;} |
407 |
max=(buff[4]<<24) | (buff[5]<<16) | (buff[6]<<8) | buff[7]; |
411 |
max=(buff[4]<<24) | (buff[5]<<16) | (buff[6]<<8) | buff[7]; |
408 |
if(num>=max) return 0; |
412 |
if(num>=max) {close(input);return 0;} |
409 |
lseek(input,(num+1)<<3,SEEK_SET); |
413 |
lseek(input,(num+1)<<3,SEEK_SET); |
410 |
got=read(input,buff,8); |
414 |
got=read(input,buff,8); |
411 |
offset=(buff[0]<<24) | (buff[1]<<16) | (buff[2]<<8) | buff[3]; |
415 |
offset=(buff[0]<<24) | (buff[1]<<16) | (buff[2]<<8) | buff[3]; |
412 |
length=(buff[4]<<24) | (buff[5]<<16) | (buff[6]<<8) | buff[7]; |
416 |
length=(buff[4]<<24) | (buff[5]<<16) | (buff[6]<<8) | buff[7]; |
413 |
if(len>length) len=length; |
417 |
if(len>length) len=length; |
414 |
if(!offset || !len) return 0; |
418 |
if(!offset || !len) {close(input);return 0;} |
415 |
lseek(input,offset,SEEK_SET); |
419 |
lseek(input,offset,SEEK_SET); |
416 |
got=read(input,put,len); |
420 |
got=read(input,put,len); |
417 |
close(input); |
421 |
close(input); |
Lines 448-455
Link Here
|
448 |
input=open(resourcename,O_RDONLY); |
452 |
input=open(resourcename,O_RDONLY); |
449 |
if(input==-1) return -4; |
453 |
if(input==-1) return -4; |
450 |
got=read(input,buff,8); |
454 |
got=read(input,buff,8); |
451 |
if(got!=8) return -2; |
455 |
if(got!=8) {close(input);return -2;} |
452 |
if(strncmp(buff,"SCAV",4)) return -3; |
456 |
if(strncmp(buff,"SCAV",4)) {close(input);return -3;} |
453 |
output=creat(bakname,00600); |
457 |
output=creat(bakname,00600); |
454 |
if(output==-1) {close(input);return -6;} |
458 |
if(output==-1) {close(input);return -6;} |
455 |
|
459 |
|
Lines 473-484
Link Here
|
473 |
for(i=0;i<max;i++) |
477 |
for(i=0;i<max;i++) |
474 |
if(headers[i+i]) |
478 |
if(headers[i+i]) |
475 |
headers[i+i]+=delta; |
479 |
headers[i+i]+=delta; |
476 |
if (write(output,"SCAV",4) != 4) return -200; |
480 |
if (write(output,"SCAV",4) != 4) {close(input);close(output);return -200;} |
477 |
if (!rlout(output,max)) return -200; |
481 |
if (!rlout(output,max)) {close(input);close(output);return -200;} |
478 |
headers[num+num]=0; |
482 |
headers[num+num]=0; |
479 |
headers[num+num+1]=len; |
483 |
headers[num+num+1]=len; |
480 |
for(i=0;i<max+max;i++) |
484 |
for(i=0;i<max+max;i++) |
481 |
if (!rlout(output,headers[i])) return -200; |
485 |
if (!rlout(output,headers[i])) {close(input);close(output);return -200;} |
482 |
|
486 |
|
483 |
if(offset) |
487 |
if(offset) |
484 |
{ |
488 |
{ |
Lines 487-494
Link Here
|
487 |
while(count) |
491 |
while(count) |
488 |
{ |
492 |
{ |
489 |
got=count>1024 ? 1024 : count; |
493 |
got=count>1024 ? 1024 : count; |
490 |
if (read(input,copybuff,got) != got) return -200; |
494 |
if (read(input,copybuff,got) != got) {close(input);close(output);return -200;} |
491 |
if (write(output,copybuff,got) != got) return -200; |
495 |
if (write(output,copybuff,got) != got) {close(input);close(output);return -200;} |
492 |
count-=got; |
496 |
count-=got; |
493 |
} |
497 |
} |
494 |
lseek(input,length,SEEK_CUR); |
498 |
lseek(input,length,SEEK_CUR); |
Lines 498-514
Link Here
|
498 |
{ |
502 |
{ |
499 |
got=read(input, copybuff, 1024); |
503 |
got=read(input, copybuff, 1024); |
500 |
if (!got) break; |
504 |
if (!got) break; |
501 |
if (write (output, copybuff, got) != got) return -200; |
505 |
if (write (output, copybuff, got) != got) {close(input);close(output);return -200;} |
502 |
offset += got; |
506 |
offset += got; |
503 |
} |
507 |
} |
504 |
if(len) |
508 |
if(len) |
505 |
{ |
509 |
{ |
506 |
if (write (output, take, len) != len) return -200; |
510 |
if (write (output, take, len) != len) {close(input);close(output);return -200;} |
507 |
lseek (output, (num+1) << 3, SEEK_SET); |
511 |
lseek (output, (num+1) << 3, SEEK_SET); |
508 |
if (!rlout (output, offset)) return -200; |
512 |
if (!rlout (output, offset)) {close(input);close(output);return -200;} |
509 |
} |
513 |
} |
510 |
close (input); |
514 |
close (input); |
511 |
if (fsync(output)) return -200; |
515 |
if (fsync(output)) {close(output);return -200;} |
512 |
if (close(output)) return -200; |
516 |
if (close(output)) return -200; |
513 |
err=rename(bakname,resourcename); |
517 |
err=rename(bakname,resourcename); |
514 |
if(err) return -1; |
518 |
if(err) return -1; |
Lines 1382-1387
Link Here
|
1382 |
break; |
1386 |
break; |
1383 |
} |
1387 |
} |
1384 |
} |
1388 |
} |
|
|
1389 |
close(file); |
1385 |
} |
1390 |
} |
1386 |
|
1391 |
|
1387 |
void remslash(char *str) |
1392 |
void remslash(char *str) |
Lines 1416-1421
Link Here
|
1416 |
return -3; |
1421 |
return -3; |
1417 |
} |
1422 |
} |
1418 |
} while(len); |
1423 |
} while(len); |
|
|
1424 |
close(input); |
1425 |
close(output); |
1419 |
return 0; |
1426 |
return 0; |
1420 |
} |
1427 |
} |
1421 |
|
1428 |
|
Lines 1448-1454
Link Here
|
1448 |
printf("Failed to create directory %s, exiting\n",temp); |
1455 |
printf("Failed to create directory %s, exiting\n",temp); |
1449 |
exit(1); |
1456 |
exit(1); |
1450 |
} |
1457 |
} |
1451 |
} |
1458 |
} else close(file); |
1452 |
|
1459 |
|
1453 |
sprintf(resourcename,"%s/%s/%s",localname,localdirname,LEVELSNAME); |
1460 |
sprintf(resourcename,"%s/%s/%s",localname,localdirname,LEVELSNAME); |
1454 |
file=open(resourcename,O_RDONLY); |
1461 |
file=open(resourcename,O_RDONLY); |
Lines 1485-1491
Link Here
|
1485 |
printf("Couldn't create %s\n",temp); |
1492 |
printf("Couldn't create %s\n",temp); |
1486 |
exit(1); |
1493 |
exit(1); |
1487 |
} |
1494 |
} |
1488 |
} |
1495 |
} else close(file); |
1489 |
} |
1496 |
} |
1490 |
|
1497 |
|
1491 |
void makercname(char *str) |
1498 |
void makercname(char *str) |