Quick rundown of file IO?

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

Moderators: cheriff, TyRaNiD

Post Reply
Heretic
Posts: 33
Joined: Thu Feb 02, 2006 3:22 pm
Location: Pittsburgh, PA, USA
Contact:

Quick rundown of file IO?

Post by Heretic »

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

// 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&#40;i=0;i<300;i++&#41;
	&#123;
		Print&#40;0,1,0xFF,buf&#41;;
		CopyBuf&#40;&#41;;
	&#125;
	res = sceIoDread&#40;fdesc,&info&#41;;
	if&#40;res<0&#41;
		for&#40;i=0;i<300;i++&#41;
		&#123;
			Print&#40;0,0,0xFF,"Error opening thingy."&#41;;
			CopyBuf&#40;&#41;;
		&#125;
	else
		for&#40;i=0;i<300;i++&#41;
		&#123;
			Print&#40;1,2,0xFF,info.d_name&#41;;
			CopyBuf&#40;&#41;;
		&#125;
/*
Output&#58; 
"Code&#58; 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...)
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

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.
Heretic
Posts: 33
Joined: Thu Feb 02, 2006 3:22 pm
Location: Pittsburgh, PA, USA
Contact:

Post by Heretic »

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...)
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

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.
Heretic
Posts: 33
Joined: Thu Feb 02, 2006 3:22 pm
Location: Pittsburgh, PA, USA
Contact:

Post by Heretic »

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...)
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

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.
Heretic
Posts: 33
Joined: Thu Feb 02, 2006 3:22 pm
Location: Pittsburgh, PA, USA
Contact:

Post by Heretic »

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

	DIR *usr = opendir&#40;"./USER_DATA/"&#41;;
	if&#40;!usr&#41;
			Print&#40;0,0,0xFF,"Error opening thingy dir."&#41;;

	dirent *f = readdir&#40;usr&#41;; //if this line is here, doesn't compile
	usr->de = *&#40;readdir&#40;usr&#41;&#41;;
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...)
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

That is most likely because it is struct dirent, not dirent :)
Heretic
Posts: 33
Joined: Thu Feb 02, 2006 3:22 pm
Location: Pittsburgh, PA, USA
Contact:

Post by Heretic »

...
...

...



...






...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...)
Post Reply