before is my code:
SceUID tid;
char buff[MAXPATHLEN];
tid = sceKernelGetThreadId();
sceIoGetThreadCwd(tid, buff, sizeof(buff));
but the game crashed.
sceKernelGetThreadId return a int value, I think it's not that sceIoGetThreadCwd needs as the first parameter.
anyone knows how to use sceIoGetThreadCwd?
I want to get the current dir without using newlib(chdir), can I use sceIoGetThreadCwd instead?
how to use sceIoGetThreadCwd?
For a start I think that function call is kernel mode only which makes it slightly more annoying :P
And you are correct with your use, it is probably the way you are calling it which is causing the problem :) For one thing you might want to check the return code, if it is > 0 then it has copied in a string into your buffer, unless something has actually set the CWD then it will be empty and you could end up with a crash just due to that I expect.
And you are correct with your use, it is probably the way you are calling it which is causing the problem :) For one thing you might want to check the return code, if it is > 0 then it has copied in a string into your buffer, unless something has actually set the CWD then it will be empty and you could end up with a crash just due to that I expect.
thx TyRaNiD.
I made a little change, and test again:
first of all, client code hasn't invoke these function, just compiled it and pack to my static lib.
1.
std::string
Directory::GetCurrentDirectory()
{
SceUID tid;
int rt;
char buff[MAXPATHLEN];
tid = sceKernelGetThreadId();
rt = sceIoGetThreadCwd(tid, buff, sizeof(buff));
if (rt > 0)
{
return buff;
}
else
{
return "123";
}
}
the game returned:
host0:/> ld host0:/test.elf
Failed to Load/Start module 'host0:/test.elf' Error: 0x80020001
but reset cmd is valid in psplink.
2. I just change the "return "123"" as followed
std::string
Directory::GetCurrentDirectory()
{
SceUID tid;
int rt;
char buff[MAXPATHLEN];
tid = sceKernelGetThreadId();
rt = sceIoGetThreadCwd(tid, buff, sizeof(buff));
if (rt > 0)
{
return buff;
}
else
{
return buff;
}
}
the game crashed, and no response message.
reset cmd now invalid in psplink.
what's the differents?I'm sure I haven't invoke them in my client code.
I made a little change, and test again:
first of all, client code hasn't invoke these function, just compiled it and pack to my static lib.
1.
std::string
Directory::GetCurrentDirectory()
{
SceUID tid;
int rt;
char buff[MAXPATHLEN];
tid = sceKernelGetThreadId();
rt = sceIoGetThreadCwd(tid, buff, sizeof(buff));
if (rt > 0)
{
return buff;
}
else
{
return "123";
}
}
the game returned:
host0:/> ld host0:/test.elf
Failed to Load/Start module 'host0:/test.elf' Error: 0x80020001
but reset cmd is valid in psplink.
2. I just change the "return "123"" as followed
std::string
Directory::GetCurrentDirectory()
{
SceUID tid;
int rt;
char buff[MAXPATHLEN];
tid = sceKernelGetThreadId();
rt = sceIoGetThreadCwd(tid, buff, sizeof(buff));
if (rt > 0)
{
return buff;
}
else
{
return buff;
}
}
the game crashed, and no response message.
reset cmd now invalid in psplink.
what's the differents?I'm sure I haven't invoke them in my client code.
Well the kernel can be extremely stupid sometimes, the first problem looks to me to be purely you app is still user mode and the kernel returns that SCE_ERROR_ERROR code which indicates it has no clue what it is doing, the second is a sometimes possible situation where when loading a user mode app with kernel imports the kernel crashes itself :)
Ensure your module is definetly kernel mode. However as you are using C++ why are you do bothered about not using getcwd anyway ?
Ensure your module is definetly kernel mode. However as you are using C++ why are you do bothered about not using getcwd anyway ?
I'm not sure about the relation between pspsdk and newlib right now, so I use sceXXX functions directly.maybe cause the confusion.
can you teach me what's the relation ?
I only know newlib is encapsulation, provide useful functions
, I found newlib-psp directory in the svn, and libc subdirectory in the pspsdk directory, they are seems a little different.
When building pspsdk , does merge them together automatic by the patch script?
how to use newlib in my app?using it as libc directly? should I do any other works?
how to implement functions that newlib hasn't port to psp, should I recompile both newlib and pspsdk? or just newlib is ok?
thanks very much.
can you teach me what's the relation ?
I only know newlib is encapsulation, provide useful functions
, I found newlib-psp directory in the svn, and libc subdirectory in the pspsdk directory, they are seems a little different.
When building pspsdk , does merge them together automatic by the patch script?
how to use newlib in my app?using it as libc directly? should I do any other works?
how to implement functions that newlib hasn't port to psp, should I recompile both newlib and pspsdk? or just newlib is ok?
thanks very much.
Well newlib is installed as part of the toolchain, it fact it is necessary in order to build gcc in the first place (well g++ at any rate). The pspsdk libc is just a legacy library and probably shouldn't be used anyway unless absolutely neccessary.
Certainly it wont work nicely if you are using sceIoChdir directly instead of using normal libc chdir as then newlib never gets the opportunity to actually get the current working directory. But using newlib is generally the simplest option, just use as you would expect (and ensure you dont have something like USE_PSPSDK_LIBC in your make file)
Certainly it wont work nicely if you are using sceIoChdir directly instead of using normal libc chdir as then newlib never gets the opportunity to actually get the current working directory. But using newlib is generally the simplest option, just use as you would expect (and ensure you dont have something like USE_PSPSDK_LIBC in your make file)
There are three libcs, newlib, pspsdk libc (which is deprecated, dont use it :P) and kernel libc. Newlib is all singing and dancing, the sdk libc is probably broken if you are lucky, the kernel libc is only for use in kernel apps (specifically kernel prx or customised kernel elf) that is very limited in scope, for example it hardly has any _safe_ string operations but if you know its limitations then it reduces binary size as you dont have to have full implementations in your code when there is already an implementation in the kernel.
In theory newlib should do 95% of what you want, the remaining 5% tends to be OS specific stuff, newlib is designed as an embedded libc for specifically unix style platforms, the PSP is missing things like signals and alot of other unixy stuff, but if you stick to classic libc style things you should be okay. It even implements the Berkley style sockets library transparently (i.e. you can call read/write/close on a socket fd and it works). Basically avoid anything obviously OS specific and you will be okay.
Oh incidently to use newlib just dont define USE_PSPSDK_LIBC or USE_KERNEL_LIBC in your makefile and newlib is the default.
In theory newlib should do 95% of what you want, the remaining 5% tends to be OS specific stuff, newlib is designed as an embedded libc for specifically unix style platforms, the PSP is missing things like signals and alot of other unixy stuff, but if you stick to classic libc style things you should be okay. It even implements the Berkley style sockets library transparently (i.e. you can call read/write/close on a socket fd and it works). Basically avoid anything obviously OS specific and you will be okay.
Oh incidently to use newlib just dont define USE_PSPSDK_LIBC or USE_KERNEL_LIBC in your makefile and newlib is the default.
but it always doesn't work correctly in my programe, dit me forget anything?
it's my code:
when I set path as a very long path, this also returns -1.I think it should return -2. the value of errno always show 65535 when I use printf("%d\n",errno) after mkdir.
I think my code link to newlib defualt. but what's wrong?
perror also can't work.
should I initializate newlib by myself? and how to?
it's my code:
Code: Select all
if (mkdir(path, 0777) < 0)
{
if (errno == ENAMETOOLONG)
{
return -2;
}
return -1;
}
return 0;
I think my code link to newlib defualt. but what's wrong?
perror also can't work.
should I initializate newlib by myself? and how to?