sceIoRead question

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

Moderators: cheriff, TyRaNiD

Post Reply
TheSamuraiElephant
Posts: 17
Joined: Thu Aug 04, 2005 9:10 pm

sceIoRead question

Post by TheSamuraiElephant »

In my program I'm reading a file from flash using sceIoRead.
I want to read a string from the file that is terminated with a null character, I know the start position of the string, but I'd like to output the string once I've finished reading it.
Ideally, I'd like to be able to just loop until I hit the null character keeping a count, then just read from position - count to position into a string.
I don't think it's possible using sceIoRead to read backwards though is it?
If this is the case, would it be better to just read into a buffer until i hit the null character?
CyberBill
Posts: 86
Joined: Tue Jul 26, 2005 3:53 pm
Location: Redmond, WA

Post by CyberBill »

Code: Select all

SceOff sceIoLseek(SceUID fd, SceOff offset, int whence);
long   sceIoLseek32(SceUID fd, long offset, int whence);
But just to let you know, unless you absolutely have to, reading from a file this way isnt goign to be fast. Read the file from flash fully into a RAM, using a single sceIoRead function, and then use strlen() on it. Example (excluding erroneous bits):

Code: Select all

file = sceIoOpen("flash0:/fileiwant.bla");

filesize = sceIoLseek(file, 0, SCE_SEEK_END);  //I dont know the real #defines.. sorry
sceIoLseek(file, 0, SCE_SEEK_SET);

char* buffer = malloc(filesize);
sceIoRead(file, buffer, 1, filesize);
sceIoClose(file);

printf("The first string in the file is %d characters long.\n", strlen(&buffer[0]) );
I hope this helps. :)
TheSamuraiElephant
Posts: 17
Joined: Thu Aug 04, 2005 9:10 pm

Post by TheSamuraiElephant »

awesome, thanks cyberbill :)
I was reading the whole thing from flash, so i'll modify it to load into RAM first :)
Excellent advice cheers :)
Post Reply