using sceIoOpen and sceIoWrite

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

Moderators: cheriff, TyRaNiD

Post Reply
PsPfReAK
Posts: 61
Joined: Sat Mar 28, 2009 9:02 am
Contact:

using sceIoOpen and sceIoWrite

Post by PsPfReAK »

Hello all, right, i know how to check for a file using sceIoOpen simple stuff. But how do write using sceIoWite.
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?
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

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: Select all

int main(){
     SetupCallbacks();
     makeNiceGame();
     sceKernelExitGame();
}
m0skit0
Posts: 191
Joined: Tue Jun 02, 2009 8:58 pm

Post by m0skit0 »

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.
PsPfReAK
Posts: 61
Joined: Sat Mar 28, 2009 9:02 am
Contact:

Post by PsPfReAK »

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
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

main.c:

Code: Select all

#include <malloc.h>

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


PSP_MODULE_INFO&#40;"test", 0, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;PSP_THREAD_ATTR_USER&#41;;
PSP_HEAP_SIZE_KB&#40;1024 * 2&#41;;

int main&#40;&#41; &#123;
    SceUID filein, fileout;
    char* pBuf=0;
    int mSize=0;
    pspDebugScreenInit&#40;&#41;;

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


    //Open ms0&#58;/test.txt for writing.
    fileout = sceIoOpen&#40;"ms0&#58;/test.txt", PSP_O_WRONLY | PSP_O_CREAT, 0777&#41;;
    //Write pBuf to the new file/
    sceIoWrite&#40;fileout, pBuf, mSize&#41;;
    //Close the file.
    sceIoClose&#40;fileout&#41;;

    pspDebugScreenPrintf&#40;"ms0&#58;/test.txt has been written.\nSize&#58; %i\n",mSize&#41;;

    //Timeout before app shuts down.
    sceKernelDelayThread&#40;5000000&#41;;
    sceKernelExitGame&#40;&#41;;
&#125;

Code: Select all

int main&#40;&#41;&#123;
     SetupCallbacks&#40;&#41;;
     makeNiceGame&#40;&#41;;
     sceKernelExitGame&#40;&#41;;
&#125;
PsPfReAK
Posts: 61
Joined: Sat Mar 28, 2009 9:02 am
Contact:

Post by PsPfReAK »

Thanks alot, i get it now :)
User avatar
Ameen
Posts: 10
Joined: Sun Jun 14, 2009 6:28 am
Location: Bahrain
Contact:

Post by Ameen »

Wow, that was more than sufficient!
m0skit0
Posts: 191
Joined: Tue Jun 02, 2009 8:58 pm

Post by m0skit0 »

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.
Post Reply