Changeset 544 for trunk/core/conf.c
- Timestamp:
- 10/26/08 07:10:21 (5 years ago)
- File:
-
- 1 edited
-
trunk/core/conf.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/conf.c
r543 r544 509 509 void conf_restore() { 510 510 int fd, rcnt, i; 511 long t;512 511 unsigned short id, size; 513 void *ptr; 512 char *buf; 513 int offs; 514 struct stat st; 514 515 515 516 conf_init_defaults(); … … 517 518 conf_load_defaults(); 518 519 520 if( stat(CONF_FILE,&st) != 0 && st.st_size < sizeof(int)) 521 return; 522 523 if(!(buf=umalloc(st.st_size))) 524 return; 525 519 526 fd = open(CONF_FILE, O_RDONLY, 0777); 520 if (fd>=0){ 521 // read magick value 522 rcnt = read(fd, &t, sizeof(t)); 523 if (rcnt==sizeof(t) && t==CONF_MAGICK_VALUE) { 524 while (1) { 525 rcnt = read(fd, &id, sizeof(id)); 526 if (rcnt!=sizeof(id)) break; 527 528 rcnt = read(fd, &size, sizeof(size)); 529 if (rcnt!=sizeof(size)) break; 530 531 for (i=0; i<CONF_NUM; ++i) { 532 if (conf_info[i].id==id && conf_info[i].size==size) { 533 ptr=umalloc(size); 534 if (ptr) { 535 rcnt = read(fd, ptr, size); 536 if (rcnt == size) { 537 memcpy(conf_info[i].var, ptr, size); 538 if (conf_info[i].func) { 539 conf_info[i].func(); 540 } 541 } 542 ufree(ptr); 543 } 544 break; 545 } 527 if( fd < 0 ) { 528 ufree(buf); 529 return; 530 } 531 532 rcnt = read(fd,buf,st.st_size); 533 close(fd); 534 // read magick value 535 if (*(int *)buf!=CONF_MAGICK_VALUE || rcnt != st.st_size) { 536 ufree(buf); 537 return; 538 } 539 offs=sizeof(int); 540 while (1) { 541 if (offs + sizeof(short) > rcnt) 542 break; 543 id=*((short *)(buf + offs)); 544 offs += sizeof(short); 545 546 if (offs + sizeof(short) > rcnt) 547 break; 548 size=*((short *)(buf + offs)); 549 offs += sizeof(short); 550 551 for (i=0; i<CONF_NUM; ++i) { 552 if (conf_info[i].id==id && conf_info[i].size==size) { 553 if (offs + size <= rcnt) { 554 memcpy(conf_info[i].var, buf+offs, size); 555 if (conf_info[i].func) { 556 conf_info[i].func(); 557 } 546 558 } 547 if (i == CONF_NUM) { // unknown id, just skip data 548 lseek(fd, size, SEEK_CUR); 549 } 559 offs += size; 560 break; 550 561 } 551 562 } 552 close(fd); 563 if (i == CONF_NUM) { // unknown id, just skip data 564 offs += size; 565 } 553 566 } 567 ufree(buf); 554 568 // clear any "clear on restart" values 555 569 clear_values();
Note: See TracChangeset
for help on using the changeset viewer.