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 

sceIoRead question

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



Joined: 04 Aug 2005
Posts: 17

PostPosted: Tue Sep 20, 2005 8:05 pm    Post subject: sceIoRead question Reply with quote

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?
Back to top
View user's profile Send private message
CyberBill



Joined: 26 Jul 2005
Posts: 86
Location: Redmond, WA

PostPosted: Wed Sep 21, 2005 5:23 pm    Post subject: Reply with quote

Code:

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:

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. :)
Back to top
View user's profile Send private message AIM Address MSN Messenger
TheSamuraiElephant



Joined: 04 Aug 2005
Posts: 17

PostPosted: Wed Sep 21, 2005 10:42 pm    Post subject: Reply with quote

awesome, thanks cyberbill :)
I was reading the whole thing from flash, so i'll modify it to load into RAM first :)
Excellent advice cheers :)
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