| View previous topic :: View next topic |
| Author |
Message |
robif
Joined: 15 Oct 2005 Posts: 6 Location: Maribor
|
Posted: Sun Oct 16, 2005 12:20 am Post subject: errno & libc |
|
|
Hi everybody,
first i would like to say hello as i'm new here (been lurking for some time).
Recently i started to mess with Python port and noticed that functions in libc do not set
errno when sce* functions fail. I think this is not ok as it may break programs that expect
non zero value in errno when function fails (it also helps to debug).
I implemented a naive approach to solve this problem in libcglue.c.
I implemented this function:
| Code: |
#define __PSP_FACILITY_ERRNO (0x80010000)
static int psp_set_errno(int code)
{
if (code & 0x80000000)
{
if (code & __PSP_FACILITY_ERRNO)
{
code &= 0x0000FFFF;
switch(code)
{
case 0x24:
code = ENAMETOOLONG;
break;
case 0x62:
code = EADDRINUSE;
break;
case 0x67:
code = ECONNABORTED;
break;
case 0x6E:
code = ETIMEDOUT;
break;
case 0x7B:
code = ENOMEDIUM;
break;
}
}
errno = code;
return -1;
}
else
{
return code;
}
}
|
then wrapped most sce* calls like that:
| Code: |
int mkdir(const char *pathname, mode_t mode)
{
char dest[MAXPATHLEN + 1];
if(__psp_path_absolute(pathname, dest, MAXPATHLEN) < 0) {
errno = ENAMETOOLONG;
return -1;
}
return psp_set_errno(sceIoMkdir(dest, mode));
}
|
I tested this with Python and it seems to work fine.
Would that be acceptable approach, or is there another way?
BR,
Robert |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Sun Oct 16, 2005 4:29 am Post subject: Re: errno & libc |
|
|
I'd rather see something without a lookup: | Code: | static int psp_set_errno(int code)
{
if (code & 0x80010000) {
errno = code & 0xFFFF;
return -1;
}
return code;
}
| and then modify our newlib errno.h to use errno codes that match up with Sony's. I think most of the errno codes match up anyway; changing those that don't shouldn't hurt anything.
BTW, the errno variable in pspsdk isn't thread-local. I'm not sure of the best way to fix that. |
|
| Back to top |
|
 |
robif
Joined: 15 Oct 2005 Posts: 6 Location: Maribor
|
Posted: Sun Oct 16, 2005 5:18 am Post subject: Re: Lookup |
|
|
I agree that it would be better to change newlib's error codes than to perform lookup, as there
are only few values (that i know of) that differ.
Regarding thread safety i'm not sure either. Currently when i compile thread code into Python
PSP seems to freeze. This could be for many reasons... |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Tue Oct 25, 2005 8:01 pm Post subject: |
|
|
| OK, I've cleaned up the errno handling in r1223. It should be more or less correct now, except that the actual errno values still need to get fixed up. |
|
| Back to top |
|
 |
robif
Joined: 15 Oct 2005 Posts: 6 Location: Maribor
|
Posted: Wed Oct 26, 2005 4:08 am Post subject: |
|
|
Thanks Jim,
this looks great.
Robert |
|
| Back to top |
|
 |
|