forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

File modification time display issue

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Aperture



Joined: 13 Aug 2009
Posts: 6

PostPosted: Thu Aug 13, 2009 8:28 pm    Post subject: File modification time display issue Reply with quote

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
View user's profile Send private message
slasher2661996



Joined: 22 Feb 2009
Posts: 91
Location: Melbourne Australia ZOMG

PostPosted: Thu Aug 13, 2009 8:30 pm    Post subject: Reply with quote

localtime function please
Back to top
View user's profile Send private message
Aperture



Joined: 13 Aug 2009
Posts: 6

PostPosted: Thu Aug 13, 2009 8:47 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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