 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
TheSamuraiElephant
Joined: 04 Aug 2005 Posts: 17
|
Posted: Tue Sep 20, 2005 8:05 pm Post subject: sceIoRead question |
|
|
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 |
|
 |
CyberBill
Joined: 26 Jul 2005 Posts: 86 Location: Redmond, WA
|
Posted: Wed Sep 21, 2005 5:23 pm Post subject: |
|
|
| 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 |
|
 |
TheSamuraiElephant
Joined: 04 Aug 2005 Posts: 17
|
Posted: Wed Sep 21, 2005 10:42 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|