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 

Quick rundown of file IO?

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



Joined: 02 Feb 2006
Posts: 33
Location: Pittsburgh, PA, USA

PostPosted: Fri Apr 07, 2006 1:58 am    Post subject: Quick rundown of file IO? Reply with quote

I haven't really done anything with the psp file IO API yet, but now it seems necessary for me to learn a thing or 2.

I have been using fopen, fread, fwrite, etc for all my file needs, and it has been working fine, but now i need the ability to scan a directory for all files contained within. I looked at the sdk and decided i need sceIoDopen and sceIoDread (i think), so now i'm trying to get them working... to no avail. My problems are:

A) relative filepaths seem to not work at all... this isnt a horrible problem, but i'd rather not use absolute paths if possible.

B) after trying a relative path, i get error code 12 (0xC), the same as when i try an absolute path beginning with "ms0:/"

C) Using "device:/PSP/GAME/MyFolder/MySubfolder/" gives me (i believe) a good return SceUID, but then when i try to read files from it, it doesnt return anything.

Anyway, here's what I have and my output, any help would be appreciated:

Code:

// Note that the folder device:/PSP/GAME/LatestBreakIn/data/ contains the
// file bgpic.raw. This is what I would love to see output...

   int res, i, j;
   SceIoDirent info;
   
   SceUID fdesc = sceIoDopen("device:/PSP/GAME/LatestBreakIn/data/");
   sprintf(buf,"Code: %x",(int)fdesc);
   for(i=0;i<300;i++)
   {
      Print(0,1,0xFF,buf);
      CopyBuf();
   }
   res = sceIoDread(fdesc,&info);
   if(res<0)
      for(i=0;i<300;i++)
      {
         Print(0,0,0xFF,"Error opening thingy.");
         CopyBuf();
      }
   else
      for(i=0;i<300;i++)
      {
         Print(1,2,0xFF,info.d_name);
         CopyBuf();
      }
/*
Output:
"Code: 80020321"
"Error opening thingy."
*/


So any help again would help me tremendously. Thanks in advance.
_________________
http://omegagames.netfirms.com -- Support struggling programmers by suffering through their crappy games! (Ok, you don't have to...)
Back to top
View user's profile Send private message Visit poster's website AIM Address
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Fri Apr 07, 2006 2:59 am    Post subject: Reply with quote

You might as well use the unix style opendir/readdir/closedir which is provided with the toolchain. That will work with relative paths in theory and you require less hassle than using the sony api directly.
Back to top
View user's profile Send private message
Heretic



Joined: 02 Feb 2006
Posts: 33
Location: Pittsburgh, PA, USA

PostPosted: Fri Apr 07, 2006 4:02 am    Post subject: Reply with quote

I wasn't aware there was anything like that. How would I go about using them? Maybe just a small sample line of code would be all, but ill look it up on google in the meantime.
_________________
http://omegagames.netfirms.com -- Support struggling programmers by suffering through their crappy games! (Ok, you don't have to...)
Back to top
View user's profile Send private message Visit poster's website AIM Address
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Fri Apr 07, 2006 4:19 am    Post subject: Reply with quote

Just do a search for it, it is the same as it is on a unix system so there will be plenty of examples around.
Back to top
View user's profile Send private message
Heretic



Joined: 02 Feb 2006
Posts: 33
Location: Pittsburgh, PA, USA

PostPosted: Fri Apr 07, 2006 5:20 am    Post subject: Reply with quote

Is there a directive (or whatever its called) for the dirent.h library? like how math needs -lm etc.?
_________________
http://omegagames.netfirms.com -- Support struggling programmers by suffering through their crappy games! (Ok, you don't have to...)
Back to top
View user's profile Send private message Visit poster's website AIM Address
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Fri Apr 07, 2006 6:05 am    Post subject: Reply with quote

Nope, it is part of libc so you shouldn't need to add anything. However ensure you dont have USE_PSPSDK_LIBC (i think that is its name) in your Makefile otherwise it wont work.
Back to top
View user's profile Send private message
Heretic



Joined: 02 Feb 2006
Posts: 33
Location: Pittsburgh, PA, USA

PostPosted: Fri Apr 07, 2006 6:31 am    Post subject: Reply with quote

I give up... :(

Seriously, I have the #include <dirent.h> but for some reason i think that the compiler is linking to a different header? I think this because:

The header I thought I was using defines two struct i use: DIR and dirent. DIR contains a SceUID and a dirent. dirent is the same as a psp struct defined somewhere else (dont remember its name).

The compiler recognized DIR as a valid variable type, but did NOT recognize dirent. This was puzzling, but since DIR contains a dirent, I tried to access that instead. This works. So I have this:

Code:
   DIR *usr = opendir("./USER_DATA/");
   if(!usr)
         Print(0,0,0xFF,"Error opening thingy dir.");

   dirent *f = readdir(usr); //if this line is here, doesn't compile
   usr->de = *(readdir(usr));


And without the dirent *f, it compiles, even though usr->de IS a dirent. dubbaya-tee-eff?

This really sucks! Blech!
_________________
http://omegagames.netfirms.com -- Support struggling programmers by suffering through their crappy games! (Ok, you don't have to...)
Back to top
View user's profile Send private message Visit poster's website AIM Address
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Fri Apr 07, 2006 7:15 am    Post subject: Reply with quote

That is most likely because it is struct dirent, not dirent :)
Back to top
View user's profile Send private message
Heretic



Joined: 02 Feb 2006
Posts: 33
Location: Pittsburgh, PA, USA

PostPosted: Fri Apr 07, 2006 7:42 am    Post subject: Reply with quote

...
...

...



...






...I hate C.

...Thank you for that tip, I iz teh n00bz0r. (Too used to using typedef...)

Goddamn son of a programming language!!!
_________________
http://omegagames.netfirms.com -- Support struggling programmers by suffering through their crappy games! (Ok, you don't have to...)
Back to top
View user's profile Send private message Visit poster's website AIM Address
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