Correct size and saving

This commit is contained in:
simon.kagstrom 2010-01-30 13:03:53 +00:00
parent d884351ba8
commit 205a1d8821
2 changed files with 8 additions and 4 deletions

View File

@ -21,7 +21,7 @@ struct game_info
class GameInfo
{
public:
GameInfo(const char *filename = " ", const char *name = " ",
GameInfo(const char *filename = "unknown", const char *name = " ",
const char *author = " ",
SDL_Surface *image = NULL);

View File

@ -394,6 +394,8 @@ void Gui::saveGameInfo()
if (p)
{
size_t sz = ntohl(p->sz);
char *new_name = (char *)xmalloc(strlen(this->metadata_base_path) +
3 + strlen(this->cur_gameInfo->filename));
FILE *fp;
@ -403,12 +405,13 @@ void Gui::saveGameInfo()
fp = fopen(new_name, "w");
if (fp)
{
int n = fwrite((const void*)p, 1, p->sz, fp);
int n = fwrite((const void*)p, 1, sz, fp);
if (ferror(fp))
warning("Write error on %s\n", new_name);
else if ((size_t)n != p->sz)
warning("Could only write %d bytes of %s\n", n, new_name);
else if ((size_t)n != sz)
warning("Could only write %d bytes of %d for %s\n",
n, sz, new_name);
fclose(fp);
}
else
@ -416,6 +419,7 @@ void Gui::saveGameInfo()
free(new_name);
}
free(p);
this->gameInfoChanged = false;
}