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 

using sceIoOpen and sceIoWrite

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



Joined: 28 Mar 2009
Posts: 61

PostPosted: Mon Aug 31, 2009 7:01 pm    Post subject: using sceIoOpen and sceIoWrite Reply with quote

Hello all, right, i know how to check for a file using sceIoOpen simple stuff. But how do write using sceIoWite.

Quote:
bytes_written = sceIoWrite(fd, data, 100);


How would i define, bytes_written. FD would be like sceUID FD right?

and also what about data. the 100 is the size of the file right?
Back to top
View user's profile Send private message Visit poster's website
jojojoris



Joined: 30 Mar 2008
Posts: 261

PostPosted: Mon Aug 31, 2009 8:18 pm    Post subject: Reply with quote

Is's basicly the same as in the normal libc (stdio.h - fopen/fwrite/fclose)

http://psp.jim.sh/pspsdk-doc/group__FileIO.html

And use better english?
_________________
Code:
int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
Back to top
View user's profile Send private message
m0skit0



Joined: 02 Jun 2009
Posts: 226

PostPosted: Mon Aug 31, 2009 10:19 pm    Post subject: Reply with quote

sceIoOpen has not the standard form of fopen. But the other two have same parameters, you're right.
_________________
The Incredible Bill Gates wrote:
The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
Back to top
View user's profile Send private message
PsPfReAK



Joined: 28 Mar 2009
Posts: 61

PostPosted: Mon Aug 31, 2009 11:09 pm    Post subject: Reply with quote

well i have this

SceUID test;
test = sceIoOpen("ms0:/test.txt", O_WRONLY|O_CREAT, 0777);

that will open test.txt for writing and will create the file if it dont exist.

now what do i do with sceIowrite?

im trying copy the contents ./test.txt to ms0:/test.txt
Back to top
View user's profile Send private message Visit poster's website
jojojoris



Joined: 30 Mar 2008
Posts: 261

PostPosted: Tue Sep 01, 2009 12:08 am    Post subject: Reply with quote

main.c:

Code:
#include <malloc.h>

#include <pspkernel.h>
#include <pspdebug.h>


PSP_MODULE_INFO("test", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
PSP_HEAP_SIZE_KB(1024 * 2);

int main() {
    SceUID filein, fileout;
    char* pBuf=0;
    int mSize=0;
    pspDebugScreenInit();

    pspDebugScreenPrintf("Opening test.txt and read the content.\n");
    //Open test.txt for reading.
    filein = sceIoOpen("test.txt", PSP_O_RDONLY | PSP_O_CREAT, 0777);
    //Check if the file is opened correctly.
    if (filein) {
        //Get filesize and set cursor back to the beginning of the file.
        mSize = sceIoLseek(filein, 0, PSP_SEEK_END);
        sceIoLseek(filein, 0, PSP_SEEK_SET);
        //Allocate enough memory to store the file.
        pBuf = (char*) malloc(mSize);
        sceIoRead(filein, pBuf, mSize);
        //Close the file.
        sceIoClose(filein);
    }
    else{
        pspDebugScreenPrintf("Opening test.txt failed: %i\n",filein);
    }


    //Open ms0:/test.txt for writing.
    fileout = sceIoOpen("ms0:/test.txt", PSP_O_WRONLY | PSP_O_CREAT, 0777);
    //Write pBuf to the new file/
    sceIoWrite(fileout, pBuf, mSize);
    //Close the file.
    sceIoClose(fileout);

    pspDebugScreenPrintf("ms0:/test.txt has been written.\nSize: %i\n",mSize);

    //Timeout before app shuts down.
    sceKernelDelayThread(5000000);
    sceKernelExitGame();
}

_________________
Code:
int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
Back to top
View user's profile Send private message
PsPfReAK



Joined: 28 Mar 2009
Posts: 61

PostPosted: Tue Sep 01, 2009 1:56 am    Post subject: Reply with quote

Thanks alot, i get it now :)
Back to top
View user's profile Send private message Visit poster's website
Ameen



Joined: 14 Jun 2009
Posts: 12
Location: Bahrain

PostPosted: Tue Sep 01, 2009 11:27 am    Post subject: Reply with quote

Wow, that was more than sufficient!
Back to top
View user's profile Send private message Visit poster's website
m0skit0



Joined: 02 Jun 2009
Posts: 226

PostPosted: Thu Sep 03, 2009 2:10 am    Post subject: Reply with quote

Wow, wonderful standard file handling. Awesome! >_>
_________________
The Incredible Bill Gates wrote:
The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
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