forked from len0rd/rockbox
reverted the fixed 4 bytes write, made the read code more reliable, use
fdprintf() when writing the highscore, add newline after score in the saved file for easier loading (but the load code is fixed to better deal with files saved using the former method as well) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7323 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
6cf8df810a
commit
0a0be62b8d
1 changed files with 9 additions and 6 deletions
|
@ -473,18 +473,21 @@ void iohiscore(void)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
unsigned int compare,init=0;
|
unsigned int compare,init=0;
|
||||||
|
|
||||||
rb->snprintf(phscore,sizeof(phscore),"%d",init);
|
|
||||||
|
|
||||||
fd = rb->open(HISCORE_FILE,O_RDWR | O_CREAT);
|
/* clear the buffer we're about to load the highscore data into */
|
||||||
rb->read(fd,phscore,4);
|
rb->memset(phscore, 0, sizeof(phscore));
|
||||||
|
|
||||||
|
fd = rb->open(HISCORE_FILE,O_RDWR | O_CREAT);
|
||||||
|
|
||||||
|
/* highscore used to %d, is now %d\n
|
||||||
|
Deal with no file or bad file */
|
||||||
|
rb->read(fd,phscore, sizeof(phscore));
|
||||||
|
|
||||||
compare = rb->atoi(phscore);
|
compare = rb->atoi(phscore);
|
||||||
|
|
||||||
if(hiscore > compare){
|
if(hiscore > compare){
|
||||||
rb->snprintf(phscore,sizeof(phscore),"%d",hiscore);
|
|
||||||
rb->lseek(fd,0,SEEK_SET);
|
rb->lseek(fd,0,SEEK_SET);
|
||||||
rb->write(fd,phscore,4);
|
rb->fdprintf(fd, "%d\n", hiscore);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
hiscore = compare;
|
hiscore = compare;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue