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