Subject: Non-compliant strxfrm MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Date: Mon, 1 Sep 2003 10:56:07 +0100 content-class: urn:content-classes:message X-MimeOLE: Produced By Microsoft Exchange V6.0.4417.0 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Non-compliant strxfrm Thread-Index: AcNwbsY5Afc5D9xcEdeGDgBQvzMKIA== From: "Melvin Curran" To: Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id h81C6li14451 Reply-To: djgpp-workers AT delorie DOT com I found this when I was running the boost regex library though its regression tests - it was getting the wrong answers for some of them. I eventually tracked the problem down to some calls to strxfrm, and when I checked the C99 standard (sect. 7.21.4.5) I found that the DJGPP version was almost completely wrong. Below is a version that I believe follows the standard (although you should feel free to pick holes in it :), and allows the boost regex library to work properly. size_t strxfrm(dst, src, n) char *dst; const char *src; size_t n; { size_t r; int c; if (n != 0) { if (dst == 0) return (size_t)(-1); r = 0; while ((c = *src++) != 0) { if (--n == 0) break; else r++; *dst++ = c; } *dst = 0; return r; } else if (dst == 0) { for (dst = (char*)src; *dst; dst++) ; return dst-src; } else return (size_t)(-1); } -- || || |||||| | HME Ltd. | || ||| ||| | | |||||| | ||||| | | || || || | Melvin Curran | || || |||||| | melvin AT hme DOT ltd DOT uk |