Im porting one of my works from pc in directx to psp. I need to port my file routines, which i usually use FILE* and fread/fgets/.... . It seems now, that we should be using file descriptors and psp specific io functions.
therefore, what is the equivalent for fgets?
thanks,
-stellar
file io->fgets equivalent?
Re: file io->fgets equivalent?
No, unless you have a specific reason you can't use newlib, just go ahead and keep using fopen and fgets. Newlib is linked by default in build.mak.Stellar wrote:Im porting one of my works from pc in directx to psp. I need to port my file routines, which i usually use FILE* and fread/fgets/.... . It seems now, that we should be using file descriptors and psp specific io functions.
the text file was converted using ' dos2unix rocket.x3d rocket.x3d '
i have attached the source code, which is in its simplest form, it should just write the file out to the screen.
zip attached here
and thanks for you generosity :)
i have attached the source code, which is in its simplest form, it should just write the file out to the screen.
zip attached here
Code: Select all
void ReadFile()
{
char szBuffer[128];
FILE *fd = fopen( "rocket.x3d", "r" );
if ( fd )
{
while ( fgets( szBuffer, sizeof( szBuffer ), fd ) )
{
printf( "%s", szBuffer );
}
fclose( fd );
}
else
{
printf( "failed to open (%s)\n", "rocket.x3d" );
}
}
-
- Posts: 81
- Joined: Mon Dec 19, 2005 4:09 pm
I played with this one day and couldn't get results I was happy with. I was lucky that the data I was working with (array of structures) could be (and is) stored in a structure so I just did a read (sizeof(structure) * number of entries) and did a write for the same thing. It's faster too with only one read and write. I got nothing but general wierdness with the linefeeds (\n) in the files. If your data is setup this way, you may want to try this.Stellar wrote:I tried using it. it compiles no problem, but it acts just like read does. It wont stop reading at a newline the way fgets on pc does. instead, it reads the size that is passed in :( ?
Note: Many string functions are not implemented yet (or not fully) and there's no guarantee things work as they do in standard libs. Look at the source for those libraries and you'll see what I mean.
If you can do your reads/writes in the same way I do (arrays of structures), you may consider converting them on the pc side and moving the data over to be read by the psp app (without linefeeds).
David Beyer
Ive already started adding a binary option for my exporter. I know ill have to do it eventually just to keep file sizes down and make thinks simpler. in terms of tring functions. I stay exclusive to standard c routines, so im assuming you're not referring to strcat, strcmp, strcpy. thats pretty much all i use :)
anyway, i wanted to read text cause thats the way my pc model class works and I just wanted to see some results on the psp since this is my first program, just anxious i guess.
anyway, i wanted to read text cause thats the way my pc model class works and I just wanted to see some results on the psp since this is my first program, just anxious i guess.
OK, now I'm confused. Your program works perfectly. The entire file gets copied to the screen. Where's the problem? I also modified it to make sure fgets() was only returning one line at a time, and it is.Stellar wrote:i have attached the source code, which is in its simplest form, it should just write the file out to the screen.
What string functions are not implemented or are not complete? Newlib is a pretty standard library.dbeyer3069 wrote:Note: Many string functions are not implemented yet (or not fully) and there's no guarantee things work as they do in standard libs. Look at the source for those libraries and you'll see what I mean.
-
- Posts: 81
- Joined: Mon Dec 19, 2005 4:09 pm
Good question. I reinstalled and updated all my pspdev (cygwin) today and I cannot find the sources I was looking at (must have been much older ones). The source code (stdio) had numerous functions commented out and said they weren't implemented fully (and I tried with no luck). Looks like I have replaced all that.What string functions are not implemented or are not complete? Newlib is a pretty standard library.
I had been looking at sscanf() which wasn't implemented into the sources I had. Glad you mentioned this -- I can try it again. Not sure how I got such old stuff.
David Beyer