File modification time display issue

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Aperture
Posts: 6
Joined: Thu Aug 13, 2009 7:58 pm

File modification time display issue

Post by Aperture »

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: Select all

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 &#40;i=0; i<NB_SAVEGAMES; i++&#41;
	&#123;
		sprintf&#40;save_name, "game_%02d.sav", i+1&#41;;
		if &#40;stat&#40;save_name, &buffer&#41;&#41;
		&#123;
			sprintf&#40;save_list&#91;i&#93;, "<EMPTY SLOT>"&#41;;
		&#125;
		else
		&#123;
			t = localtime&#40;&buffer.st_mtime&#41;;
			sprintf&#40;save_list&#91;i&#93;, "%04d.%02d.%02d %02d&#58;%02d&#58;%02d", t->tm_year+1900, t->tm_mon+1, t->tm_mday,
				t->tm_hour, t->tm_min, t->tm_sec&#41;;
		&#125;
	&#125;
&#125;
slasher2661996
Posts: 91
Joined: Sun Feb 22, 2009 8:32 am
Location: Melbourne Australia ZOMG

Post by slasher2661996 »

localtime function please
Aperture
Posts: 6
Joined: Thu Aug 13, 2009 7:58 pm

Post by Aperture »

standard one from <time.h>
If you want a test program:

Code: Select all

#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&#91;NB_SAVEGAMES&#93;&#91;20&#93;;
void create_savegame_list&#40;&#41;
&#123;
   int i;
   char save_name&#91;&#93; = "game_00.sav";
   struct stat buffer;
   struct tm* t;

   for &#40;i=0; i<NB_SAVEGAMES; i++&#41;
   &#123;
      sprintf&#40;save_name, "game_%02d.sav", i+1&#41;;
      if &#40;stat&#40;save_name, &buffer&#41;&#41;
      &#123;
         sprintf&#40;save_list&#91;i&#93;, "<EMPTY SLOT>"&#41;;
      &#125;
      else
      &#123;
         t = localtime&#40;&buffer.st_mtime&#41;;
         sprintf&#40;save_list&#91;i&#93;, "%04d.%02d.%02d %02d&#58;%02d&#58;%02d", t->tm_year+1900, t->tm_mon+1, t->tm_mday,
            t->tm_hour, t->tm_min, t->tm_sec&#41;;
      &#125;
   &#125;
&#125;

int main&#40;&#41;
&#123;
int i;
   create_savegame_list&#40;&#41;;
   for &#40;i=0; i<NB_SAVEGAMES; i++&#41;
     printf&#40;"%s\n", save_list&#91;i&#93;&#41;;

&#125;
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.
Post Reply