 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Aperture
Joined: 13 Aug 2009 Posts: 6
|
Posted: Thu Aug 13, 2009 8:28 pm Post subject: File modification time display issue |
|
|
Hello all,
In a custom savegame menu, I am trying to display the modification time of my gamesave files, but the time stamps obtained with the code below are all in 2004.04.08 instead of the current date on PSP.
The same code gives the expected results on Linux however, and when converting the time_t struct returned by time(NULL) on PSP, I also get the current date as expected.
I checked that I also see the proper creation & modification time for my files when accessing them through USB.
It all looks as if the st_#time attributes of the stat struct on PSP are set to a different time origin or something...
Am I doing something wrong here?
| Code: |
char save_list[NB_SAVEGAMES][20];
void create_savegame_list()
{
int i;
char save_name[] = "game_00.sav";
struct stat buffer;
struct tm* t;
for (i=0; i<NB_SAVEGAMES; i++)
{
sprintf(save_name, "game_%02d.sav", i+1);
if (stat(save_name, &buffer))
{
sprintf(save_list[i], "<EMPTY SLOT>");
}
else
{
t = localtime(&buffer.st_mtime);
sprintf(save_list[i], "%04d.%02d.%02d %02d:%02d:%02d", t->tm_year+1900, t->tm_mon+1, t->tm_mday,
t->tm_hour, t->tm_min, t->tm_sec);
}
}
} |
|
|
| Back to top |
|
 |
slasher2661996
Joined: 22 Feb 2009 Posts: 91 Location: Melbourne Australia ZOMG
|
Posted: Thu Aug 13, 2009 8:30 pm Post subject: |
|
|
| localtime function please |
|
| Back to top |
|
 |
Aperture
Joined: 13 Aug 2009 Posts: 6
|
Posted: Thu Aug 13, 2009 8:47 pm Post subject: |
|
|
standard one from <time.h>
If you want a test program: | Code: | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#define NB_SAVEGAMES 4
char save_list[NB_SAVEGAMES][20];
void create_savegame_list()
{
int i;
char save_name[] = "game_00.sav";
struct stat buffer;
struct tm* t;
for (i=0; i<NB_SAVEGAMES; i++)
{
sprintf(save_name, "game_%02d.sav", i+1);
if (stat(save_name, &buffer))
{
sprintf(save_list[i], "<EMPTY SLOT>");
}
else
{
t = localtime(&buffer.st_mtime);
sprintf(save_list[i], "%04d.%02d.%02d %02d:%02d:%02d", t->tm_year+1900, t->tm_mon+1, t->tm_mday,
t->tm_hour, t->tm_min, t->tm_sec);
}
}
}
int main()
{
int i;
create_savegame_list();
for (i=0; i<NB_SAVEGAMES; i++)
printf("%s\n", save_list[i]);
} | Then just create a couple of game_01.sav, game_02.sav. This code works as expected on UNIX, and I just confirmed that there was indeed a huge difference between the time_t values returned by stat and by time(NULL) on PSP. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|