delorie.com/archives/browse.cgi | search |
Subject: | Non-compliant strxfrm |
MIME-Version: | 1.0 |
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: | <F1A9C8D7A58D1B45A9C16FE7E3DA83D702188D@server.HME.hme.ltd.uk> |
X-MS-Has-Attach: | |
X-MS-TNEF-Correlator: | |
Thread-Topic: | Non-compliant strxfrm |
Thread-Index: | AcNwbsY5Afc5D9xcEdeGDgBQvzMKIA== |
From: | "Melvin Curran" <Melvin AT HME DOT Ltd DOT uk> |
To: | <djgpp-workers AT delorie DOT com> |
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 |
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |