From: Ilya Zakharevich Date: Mon, 25 Jun 2001 05:02:36 +0000 (-0400) Subject: Re: [PATCH 5.6.1] $^E on OS/2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9fed8b87f0e66c26a1acaf42431d99e8f98aed9b;p=p5sagit%2Fp5-mst-13.2.git Re: [PATCH 5.6.1] $^E on OS/2 Message-ID: <20010625050235.A24046@math.ohio-state.edu> p4raw-id: //depot/perl@10917 --- diff --git a/mg.c b/mg.c index 8e0f7cb..5963335 100644 --- a/mg.c +++ b/mg.c @@ -1734,7 +1734,9 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) # ifdef WIN32 SetLastError( SvIV(sv) ); # else -# ifndef OS2 +# ifdef OS2 + os2_setsyserrno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)); +# else /* will anyone ever use this? */ SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv), 4); # endif diff --git a/os2/dl_os2.c b/os2/dl_os2.c index 02ca2ef..aaeeb58 100644 --- a/os2/dl_os2.c +++ b/os2/dl_os2.c @@ -8,6 +8,8 @@ static ULONG retcode; static char fail[300]; +char *os2error(int rc); + void * dlopen(char *path, int mode) { @@ -62,29 +64,17 @@ dlerror(void) { static char buf[700]; ULONG len; + char *err; if (retcode == 0) return NULL; - if (DosGetMessage(NULL, 0, buf, sizeof buf - 1, retcode, - "OSO001.MSG", &len)) { - if (fail[0]) - sprintf(buf, -"OS/2 system error code %lu, possible problematic module: '%s'", - retcode, fail); - else - sprintf(buf, "OS/2 system error code %lu", retcode); - } else { - buf[len] = '\0'; - if (len && buf[len - 1] == '\n') - buf[--len] = 0; - if (len && buf[len - 1] == '\r') - buf[--len] = 0; - if (len && buf[len - 1] == '.') - buf[--len] = 0; - if (fail[0] && len < 300) - sprintf(buf + len, ", possible problematic module: '%s'", - fail); - } + err = os2error(retcode); + len = strlen(err); + if (len > sizeof(buf) - 1) + len = sizeof(buf) - 1; + strncpy(buf, err, len+1); + if (fail[0] && len < 300) + sprintf(buf + len, ", possible problematic module: '%s'", fail); retcode = 0; return buf; } diff --git a/os2/os2.c b/os2/os2.c index 1016d9b..9cb0dd7 100644 --- a/os2/os2.c +++ b/os2/os2.c @@ -1356,20 +1356,36 @@ os2error(int rc) { static char buf[300]; ULONG len; + char *s; + int number = SvTRUE(get_sv("OS2::nsyserror", TRUE)); if (!(_emx_env & 0x200)) return ""; /* Nop if not OS/2. */ if (rc == 0) - return NULL; - if (DosGetMessage(NULL, 0, buf, sizeof buf - 1, rc, "OSO001.MSG", &len)) - sprintf(buf, "OS/2 system error code %d=0x%x", rc, rc); - else { - buf[len] = '\0'; - if (len && buf[len - 1] == '\n') - buf[--len] = 0; - if (len && buf[len - 1] == '\r') - buf[--len] = 0; - if (len && buf[len - 1] == '.') - buf[--len] = 0; + return ""; + if (number) { + sprintf(buf, "SYS%04d=%#x: ", rc, rc); + s = buf + strlen(buf); + } else + s = buf; + if (DosGetMessage(NULL, 0, s, sizeof(buf) - 1 - (s-buf), + rc, "OSO001.MSG", &len)) { + if (!number) { + sprintf(buf, "SYS%04d=%#x: ", rc, rc); + s = buf + strlen(buf); + } + sprintf(s, "[No description found in OSO001.MSG]"); + } else { + s[len] = '\0'; + if (len && s[len - 1] == '\n') + s[--len] = 0; + if (len && s[len - 1] == '\r') + s[--len] = 0; + if (len && s[len - 1] == '.') + s[--len] = 0; + if (len >= 10 && number && strnEQ(s, buf, 7) + && s[7] == ':' && s[8] == ' ') + /* Some messages start with SYSdddd:, some not */ + Move(s + 9, s, (len -= 9) + 1, char); } return buf; } @@ -2186,6 +2202,9 @@ Xs_OS2_init(pTHX) gv = gv_fetchpv("OS2::os_ver", TRUE, SVt_PV); GvMULTI_on(gv); sv_setnv(GvSV(gv), _osmajor + 0.001 * _osminor); + gv = gv_fetchpv("OS2::nsyserror", TRUE, SVt_PV); + GvMULTI_on(gv); + sv_setiv(GvSV(gv), 1); /* DEFAULT: Show number on syserror */ } return 0; }