summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/ap/plan9
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2016-05-04 00:23:48 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2016-05-04 00:23:48 +0200
commit14685d65958bed4d68b9c60564fa8d09aa746462 (patch)
treef2480af19061f27c67a36a2bb8fd7f41d047732a /sys/src/ape/lib/ap/plan9
parent7657312dcf5b9435ff848b20dfc3a0546ab8a500 (diff)
ape: return plan9 error strings from strerror()
when _syserrno() fails to map a plan9 error string to a unix error number, we copy the plan9 error string to the per process error buffer "plan9err" and set errno = EPLAN9. when strerror() is called with EPLAN9, it returns a pointer to the plan9err buffer.
Diffstat (limited to 'sys/src/ape/lib/ap/plan9')
-rw-r--r--sys/src/ape/lib/ap/plan9/_errno.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/sys/src/ape/lib/ap/plan9/_errno.c b/sys/src/ape/lib/ap/plan9/_errno.c
index e7e1e355b..a02ec4e4b 100644
--- a/sys/src/ape/lib/ap/plan9/_errno.c
+++ b/sys/src/ape/lib/ap/plan9/_errno.c
@@ -7,7 +7,7 @@
/* see also: ../stdio/strerror.c, with errno-> string mapping */
-char _plan9err[ERRMAX];
+extern char *_plan9err;
static struct errmap {
int num;
@@ -110,15 +110,19 @@ static struct errmap {
void
_syserrno(void)
{
+ char err[ERRMAX];
int i;
- if(_ERRSTR(_plan9err, sizeof _plan9err) < 0)
- errno = EINVAL;
- else{
- for(i = 0; i < NERRMAP; i++)
- if(strstr(_plan9err, map[i].ename) != 0)
- break;
- _ERRSTR(_plan9err, sizeof _plan9err);
- errno = (i < NERRMAP)? map[i].num : EINVAL;
+ err[0] = 0;
+ _ERRSTR(err, sizeof err);
+ strncpy(_plan9err, err, sizeof err);
+ _plan9err[sizeof err-1] = 0;
+ errno = EPLAN9;
+ for(i = 0; i < NERRMAP; i++){
+ if(strstr(err, map[i].ename) != 0){
+ errno = map[i].num;
+ break;
+ }
}
+ _ERRSTR(err, sizeof err);
}