Index: stable/10/sys/libkern/bcmp.c =================================================================== --- stable/10/sys/libkern/bcmp.c (revision 319285) +++ stable/10/sys/libkern/bcmp.c (revision 319286) @@ -1,146 +1,146 @@ /*- * Copyright (c) 1987, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include typedef const void *cvp; typedef const unsigned char *ustring; typedef unsigned long ul; typedef const unsigned long *culp; /* * bcmp -- vax cmpc3 instruction */ int bcmp(b1, b2, length) const void *b1, *b2; - register size_t length; + size_t length; { #if BYTE_ORDER == LITTLE_ENDIAN /* * The following code is endian specific. Changing it from * little-endian to big-endian is fairly trivial, but making * it do both is more difficult. * * Note that this code will reference the entire longword which * includes the final byte to compare. I don't believe this is * a problem since AFAIK, objects are not protected at smaller * than longword boundaries. */ int shl, shr, len = length; ustring p1 = b1, p2 = b2; ul va, vb; if (len == 0) return (0); /* * align p1 to a longword boundary */ while ((long)p1 & (sizeof(long) - 1)) { if (*p1++ != *p2++) return (1); if (--len <= 0) return (0); } /* * align p2 to longword boundary and calculate the shift required to * align p1 and p2 */ shr = (long)p2 & (sizeof(long) - 1); if (shr != 0) { p2 -= shr; /* p2 now longword aligned */ shr <<= 3; /* offset in bits */ shl = (sizeof(long) << 3) - shr; va = *(culp)p2; p2 += sizeof(long); while ((len -= sizeof(long)) >= 0) { vb = *(culp)p2; p2 += sizeof(long); if (*(culp)p1 != (va >> shr | vb << shl)) return (1); p1 += sizeof(long); va = vb; } /* * At this point, len is between -sizeof(long) and -1, * representing 0 .. sizeof(long)-1 bytes remaining. */ if (!(len += sizeof(long))) return (0); len <<= 3; /* remaining length in bits */ /* * The following is similar to the `if' condition * inside the above while loop. The ?: is necessary * to avoid accessing the longword after the longword * containing the last byte to be compared. */ return ((((va >> shr | ((shl < len) ? *(culp)p2 << shl : 0)) ^ *(culp)p1) & ((1L << len) - 1)) != 0); } else { /* p1 and p2 have common alignment so no shifting needed */ while ((len -= sizeof(long)) >= 0) { if (*(culp)p1 != *(culp)p2) return (1); p1 += sizeof(long); p2 += sizeof(long); } /* * At this point, len is between -sizeof(long) and -1, * representing 0 .. sizeof(long)-1 bytes remaining. */ if (!(len += sizeof(long))) return (0); return (((*(culp)p1 ^ *(culp)p2) & ((1L << (len << 3)) - 1)) != 0); } #else const char *p1, *p2; if (length == 0) return(0); p1 = b1; p2 = b2; do if (*p1++ != *p2++) break; while (--length); return(length); #endif } Index: stable/10/sys/libkern/bsearch.c =================================================================== --- stable/10/sys/libkern/bsearch.c (revision 319285) +++ stable/10/sys/libkern/bsearch.c (revision 319286) @@ -1,79 +1,79 @@ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)bsearch.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include __FBSDID("$FreeBSD$"); #include #include /* * Perform a binary search. * * The code below is a bit sneaky. After a comparison fails, we * divide the work in half by moving either left or right. If lim * is odd, moving left simply involves halving lim: e.g., when lim * is 5 we look at item 2, so we change lim to 2 so that we will * look at items 0 & 1. If lim is even, the same applies. If lim * is odd, moving right again involes halving lim, this time moving * the base up one item past p: e.g., when lim is 5 we change base * to item 3 and make lim 2 so that we will look at items 3 and 4. * If lim is even, however, we have to shrink it by one before * halving: e.g., when lim is 4, we still looked at item 2, so we * have to make lim 3, then halve, obtaining 1, so that we will only * look at item 3. */ void * bsearch(key, base0, nmemb, size, compar) - register const void *key; + const void *key; const void *base0; size_t nmemb; - register size_t size; - register int (*compar)(const void *, const void *); + size_t size; + int (*compar)(const void *, const void *); { - register const char *base = base0; - register size_t lim; - register int cmp; - register const void *p; + const char *base = base0; + size_t lim; + int cmp; + const void *p; for (lim = nmemb; lim != 0; lim >>= 1) { p = base + (lim >> 1) * size; cmp = (*compar)(key, p); if (cmp == 0) return ((void *)(uintptr_t)p); if (cmp > 0) { /* key > p: move right */ base = (const char *)p + size; lim--; } /* else move left */ } return (NULL); } Index: stable/10/sys/libkern/iconv_ucs.c =================================================================== --- stable/10/sys/libkern/iconv_ucs.c (revision 319285) +++ stable/10/sys/libkern/iconv_ucs.c (revision 319286) @@ -1,538 +1,538 @@ /*- * Copyright (c) 2003, 2005 Ryuichiro Imura * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include "iconv_converter_if.h" /* * "UCS" converter */ #define KICONV_UCS_COMBINE 0x1 #define KICONV_UCS_FROM_UTF8 0x2 #define KICONV_UCS_TO_UTF8 0x4 #define KICONV_UCS_FROM_LE 0x8 #define KICONV_UCS_TO_LE 0x10 #define KICONV_UCS_FROM_UTF16 0x20 #define KICONV_UCS_TO_UTF16 0x40 #define KICONV_UCS_UCS4 0x80 #define ENCODING_UTF16 "UTF-16BE" #define ENCODING_UTF8 "UTF-8" static struct { const char *name; int from_flag, to_flag; } unicode_family[] = { { "UTF-8", KICONV_UCS_FROM_UTF8, KICONV_UCS_TO_UTF8 }, { "UCS-2LE", KICONV_UCS_FROM_LE, KICONV_UCS_TO_LE }, { "UTF-16BE", KICONV_UCS_FROM_UTF16, KICONV_UCS_TO_UTF16 }, { "UTF-16LE", KICONV_UCS_FROM_UTF16|KICONV_UCS_FROM_LE, KICONV_UCS_TO_UTF16|KICONV_UCS_TO_LE }, { NULL, 0, 0 } }; static uint32_t utf8_to_ucs4(const char *src, size_t *utf8width, size_t srclen); static u_char *ucs4_to_utf8(uint32_t ucs4, char * dst, size_t *utf8width, size_t dstlen); static uint32_t encode_surrogate(uint32_t code); static uint32_t decode_surrogate(const u_char *ucs); #ifdef MODULE_DEPEND MODULE_DEPEND(iconv_ucs, libiconv, 2, 2, 2); #endif /* * UCS converter instance */ struct iconv_ucs { KOBJ_FIELDS; int convtype; struct iconv_cspair * d_csp; struct iconv_cspair * d_cspf; void * f_ctp; void * t_ctp; void * ctype; }; static int iconv_ucs_open(struct iconv_converter_class *dcp, struct iconv_cspair *csp, struct iconv_cspair *cspf, void **dpp) { struct iconv_ucs *dp; int i; const char *from, *to; dp = (struct iconv_ucs *)kobj_create((struct kobj_class*)dcp, M_ICONV, M_WAITOK); to = csp->cp_to; from = cspf ? cspf->cp_from : csp->cp_from; dp->convtype = 0; if (cspf) dp->convtype |= KICONV_UCS_COMBINE; for (i = 0; unicode_family[i].name; i++) { if (strcasecmp(from, unicode_family[i].name) == 0) dp->convtype |= unicode_family[i].from_flag; if (strcasecmp(to, unicode_family[i].name) == 0) dp->convtype |= unicode_family[i].to_flag; } if (strcmp(ENCODING_UNICODE, ENCODING_UTF16) == 0) dp->convtype |= KICONV_UCS_UCS4; else dp->convtype &= ~KICONV_UCS_UCS4; dp->f_ctp = dp->t_ctp = NULL; if (dp->convtype & KICONV_UCS_COMBINE) { if ((dp->convtype & KICONV_UCS_FROM_UTF8) == 0 && (dp->convtype & KICONV_UCS_FROM_LE) == 0) { iconv_open(ENCODING_UNICODE, from, &dp->f_ctp); } if ((dp->convtype & KICONV_UCS_TO_UTF8) == 0 && (dp->convtype & KICONV_UCS_TO_LE) == 0) { iconv_open(to, ENCODING_UNICODE, &dp->t_ctp); } } dp->ctype = NULL; if (dp->convtype & (KICONV_UCS_FROM_UTF8 | KICONV_UCS_TO_UTF8)) iconv_open(KICONV_WCTYPE_NAME, ENCODING_UTF8, &dp->ctype); dp->d_csp = csp; if (dp->convtype & (KICONV_UCS_FROM_UTF8 | KICONV_UCS_FROM_LE)) { if (cspf) { dp->d_cspf = cspf; cspf->cp_refcount++; } else csp->cp_refcount++; } if (dp->convtype & (KICONV_UCS_TO_UTF8 | KICONV_UCS_TO_LE)) csp->cp_refcount++; *dpp = (void*)dp; return 0; } static int iconv_ucs_close(void *data) { struct iconv_ucs *dp = data; if (dp->f_ctp) iconv_close(dp->f_ctp); if (dp->t_ctp) iconv_close(dp->t_ctp); if (dp->ctype) iconv_close(dp->ctype); if (dp->d_cspf) dp->d_cspf->cp_refcount--; else if (dp->convtype & (KICONV_UCS_FROM_UTF8 | KICONV_UCS_FROM_LE)) dp->d_csp->cp_refcount--; if (dp->convtype & (KICONV_UCS_TO_UTF8 | KICONV_UCS_TO_LE)) dp->d_csp->cp_refcount--; kobj_delete((struct kobj*)data, M_ICONV); return 0; } static int iconv_ucs_conv(void *d2p, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int convchar, int casetype) { struct iconv_ucs *dp = (struct iconv_ucs*)d2p; int ret = 0, i; size_t in, on, ir, or, inlen, outlen, ucslen; const char *src, *p; char *dst; u_char ucs[4], *q; uint32_t code; if (inbuf == NULL || *inbuf == NULL || outbuf == NULL || *outbuf == NULL) return 0; ir = in = *inbytesleft; or = on = *outbytesleft; src = *inbuf; dst = *outbuf; while (ir > 0 && or > 0) { /* * The first half of conversion. * (convert any code into ENCODING_UNICODE) */ code = 0; p = src; if (dp->convtype & KICONV_UCS_FROM_UTF8) { /* convert UTF-8 to ENCODING_UNICODE */ inlen = 0; code = utf8_to_ucs4(p, &inlen, ir); if (code == 0) { ret = -1; break; } if (casetype == KICONV_FROM_LOWER && dp->ctype) { code = towlower(code, dp->ctype); } else if (casetype == KICONV_FROM_UPPER && dp->ctype) { code = towupper(code, dp->ctype); } if ((code >= 0xd800 && code < 0xe000) || code >= 0x110000 ) { /* reserved for utf-16 surrogate pair */ /* invalid unicode */ ret = -1; break; } if (inlen == 4) { if (dp->convtype & KICONV_UCS_UCS4) { ucslen = 4; code = encode_surrogate(code); } else { /* can't handle with ucs-2 */ ret = -1; break; } } else { ucslen = 2; } /* save UCS-4 into ucs[] */ for (q = ucs, i = ucslen - 1 ; i >= 0 ; i--) *q++ = (code >> (i << 3)) & 0xff; } else if (dp->convtype & KICONV_UCS_COMBINE && dp->f_ctp) { /* convert local code to ENCODING_UNICODE */ ucslen = 4; inlen = ir; q = ucs; ret = iconv_convchr_case(dp->f_ctp, &p, &inlen, (char **)&q, &ucslen, casetype & (KICONV_FROM_LOWER | KICONV_FROM_UPPER)); if (ret) break; inlen = ir - inlen; ucslen = 4 - ucslen; } else { /* src code is a proper subset of ENCODING_UNICODE */ q = ucs; if (dp->convtype & KICONV_UCS_FROM_LE) { *q = *(p + 1); *(q + 1) = *p; p += 2; } else { *q = *p++; *(q + 1) = *p++; } if ((*q & 0xfc) == 0xd8) { if (dp->convtype & KICONV_UCS_UCS4 && dp->convtype & KICONV_UCS_FROM_UTF16) { inlen = ucslen = 4; } else { /* invalid unicode */ ret = -1; break; } } else { inlen = ucslen = 2; } if (ir < inlen) { ret = -1; break; } if (ucslen == 4) { q += 2; if (dp->convtype & KICONV_UCS_FROM_LE) { *q = *(p + 1); *(q + 1) = *p; } else { *q = *p++; *(q + 1) = *p; } if ((*q & 0xfc) != 0xdc) { /* invalid unicode */ ret = -1; break; } } } /* * The second half of conversion. * (convert ENCODING_UNICODE into any code) */ p = ucs; if (dp->convtype & KICONV_UCS_TO_UTF8) { q = (u_char *)dst; if (ucslen == 4 && dp->convtype & KICONV_UCS_UCS4) { /* decode surrogate pair */ code = decode_surrogate(p); } else { code = (ucs[0] << 8) | ucs[1]; } if (casetype == KICONV_LOWER && dp->ctype) { code = towlower(code, dp->ctype); } else if (casetype == KICONV_UPPER && dp->ctype) { code = towupper(code, dp->ctype); } outlen = 0; if (ucs4_to_utf8(code, q, &outlen, or) == NULL) { ret = -1; break; } src += inlen; ir -= inlen; dst += outlen; or -= outlen; } else if (dp->convtype & KICONV_UCS_COMBINE && dp->t_ctp) { ret = iconv_convchr_case(dp->t_ctp, &p, &ucslen, &dst, &or, casetype & (KICONV_LOWER | KICONV_UPPER)); if (ret) break; src += inlen; ir -= inlen; } else { /* dst code is a proper subset of ENCODING_UNICODE */ if (or < ucslen) { ret = -1; break; } src += inlen; ir -= inlen; or -= ucslen; if (dp->convtype & KICONV_UCS_TO_LE) { *dst++ = *(p + 1); *dst++ = *p; p += 2; } else { *dst++ = *p++; *dst++ = *p++; } if (ucslen == 4) { if ((dp->convtype & KICONV_UCS_UCS4) == 0 || (dp->convtype & KICONV_UCS_TO_UTF16) == 0) { ret = -1; break; } if (dp->convtype & KICONV_UCS_TO_LE) { *dst++ = *(p + 1); *dst++ = *p; } else { *dst++ = *p++; *dst++ = *p; } } } if (convchar == 1) break; } *inbuf += in - ir; *outbuf += on - or; *inbytesleft -= in - ir; *outbytesleft -= on - or; return (ret); } static int iconv_ucs_init(struct iconv_converter_class *dcp) { int error; error = iconv_add(ENCODING_UNICODE, ENCODING_UNICODE, ENCODING_UTF8); if (error) return (error); error = iconv_add(ENCODING_UNICODE, ENCODING_UTF8, ENCODING_UNICODE); if (error) return (error); return (0); } static int iconv_ucs_done(struct iconv_converter_class *dcp) { return (0); } static const char * iconv_ucs_name(struct iconv_converter_class *dcp) { return (ENCODING_UNICODE); } static kobj_method_t iconv_ucs_methods[] = { KOBJMETHOD(iconv_converter_open, iconv_ucs_open), KOBJMETHOD(iconv_converter_close, iconv_ucs_close), KOBJMETHOD(iconv_converter_conv, iconv_ucs_conv), KOBJMETHOD(iconv_converter_init, iconv_ucs_init), KOBJMETHOD(iconv_converter_done, iconv_ucs_done), KOBJMETHOD(iconv_converter_name, iconv_ucs_name), {0, 0} }; KICONV_CONVERTER(ucs, sizeof(struct iconv_ucs)); static uint32_t utf8_to_ucs4(const char *src, size_t *utf8width, size_t srclen) { size_t i, w = 0; uint32_t ucs4 = 0; /* * get leading 1 byte from utf-8 */ if ((*src & 0x80) == 0) { /* * leading 1 bit is "0" * utf-8: 0xxxxxxx * ucs-4: 00000000 00000000 00000000 0xxxxxxx */ w = 1; /* get trailing 7 bits */ ucs4 = *src & 0x7f; } else if ((*src & 0xe0) == 0xc0) { /* * leading 3 bits are "110" * utf-8: 110xxxxx 10yyyyyy * ucs-4: 00000000 00000000 00000xxx xxyyyyyy */ w = 2; /* get trailing 5 bits */ ucs4 = *src & 0x1f; } else if ((*src & 0xf0) == 0xe0) { /* * leading 4 bits are "1110" * utf-8: 1110xxxx 10yyyyyy 10zzzzzz * ucs-4: 00000000 00000000 xxxxyyyy yyzzzzzz */ w = 3; /* get trailing 4 bits */ ucs4 = *src & 0x0f; } else if ((*src & 0xf8) == 0xf0) { /* * leading 5 bits are "11110" * utf-8: 11110www 10xxxxxx 10yyyyyy 10zzzzzz * ucs-4: 00000000 000wwwxx xxxxyyyy yyzzzzzz */ w = 4; /* get trailing 3 bits */ ucs4 = *src & 0x07; } else { /* out of utf-16 range or having illegal bits */ return (0); } if (srclen < w) return (0); /* * get left parts from utf-8 */ for (i = 1 ; i < w ; i++) { if ((*(src + i) & 0xc0) != 0x80) { /* invalid: leading 2 bits are not "10" */ return (0); } /* concatenate trailing 6 bits into ucs4 */ ucs4 <<= 6; ucs4 |= *(src + i) & 0x3f; } *utf8width = w; return (ucs4); } static u_char * ucs4_to_utf8(uint32_t ucs4, char *dst, size_t *utf8width, size_t dstlen) { u_char lead, *p; size_t i, w; /* * determine utf-8 width and leading bits */ if (ucs4 < 0x80) { w = 1; lead = 0; /* "0" */ } else if (ucs4 < 0x800) { w = 2; lead = 0xc0; /* "11" */ } else if (ucs4 < 0x10000) { w = 3; lead = 0xe0; /* "111" */ } else if (ucs4 < 0x200000) { w = 4; lead = 0xf0; /* "1111" */ } else { return (NULL); } if (dstlen < w) return (NULL); /* * construct utf-8 */ p = dst; for (i = w - 1 ; i >= 1 ; i--) { /* get trailing 6 bits and put it with leading bit as "1" */ *(p + i) = (ucs4 & 0x3f) | 0x80; ucs4 >>= 6; } *p = ucs4 | lead; *utf8width = w; return (p); } static uint32_t -encode_surrogate(register uint32_t code) +encode_surrogate(uint32_t code) { return ((((code - 0x10000) << 6) & 0x3ff0000) | ((code - 0x10000) & 0x3ff) | 0xd800dc00); } static uint32_t -decode_surrogate(register const u_char *ucs) +decode_surrogate(const u_char *ucs) { return ((((ucs[0] & 0x3) << 18) | (ucs[1] << 10) | ((ucs[2] & 0x3) << 8) | ucs[3]) + 0x10000); } Index: stable/10/sys/libkern/iconv_xlat16.c =================================================================== --- stable/10/sys/libkern/iconv_xlat16.c (revision 319285) +++ stable/10/sys/libkern/iconv_xlat16.c (revision 319286) @@ -1,363 +1,363 @@ /*- * Copyright (c) 2003, 2005 Ryuichiro Imura * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include "iconv_converter_if.h" /* * "XLAT16" converter */ #ifdef MODULE_DEPEND MODULE_DEPEND(iconv_xlat16, libiconv, 2, 2, 2); #endif #define C2I1(c) ((c) & 0x8000 ? ((c) & 0xff) | 0x100 : (c) & 0xff) #define C2I2(c) ((c) & 0x8000 ? ((c) >> 8) & 0x7f : ((c) >> 8) & 0xff) /* * XLAT16 converter instance */ struct iconv_xlat16 { KOBJ_FIELDS; uint32_t * d_table[0x200]; void * f_ctp; void * t_ctp; struct iconv_cspair * d_csp; }; static int iconv_xlat16_open(struct iconv_converter_class *dcp, struct iconv_cspair *csp, struct iconv_cspair *cspf, void **dpp) { struct iconv_xlat16 *dp; uint32_t *headp, **idxp; int i; dp = (struct iconv_xlat16 *)kobj_create((struct kobj_class*)dcp, M_ICONV, M_WAITOK); headp = (uint32_t *)((caddr_t)csp->cp_data + sizeof(dp->d_table)); idxp = (uint32_t **)csp->cp_data; for (i = 0 ; i < 0x200 ; i++) { if (*idxp) { dp->d_table[i] = headp; headp += 0x80; } else { dp->d_table[i] = NULL; } idxp++; } if (strcmp(csp->cp_to, KICONV_WCTYPE_NAME) != 0) { if (iconv_open(KICONV_WCTYPE_NAME, csp->cp_from, &dp->f_ctp) != 0) dp->f_ctp = NULL; if (iconv_open(KICONV_WCTYPE_NAME, csp->cp_to, &dp->t_ctp) != 0) dp->t_ctp = NULL; } else { dp->f_ctp = dp->t_ctp = dp; } dp->d_csp = csp; csp->cp_refcount++; *dpp = (void*)dp; return (0); } static int iconv_xlat16_close(void *data) { struct iconv_xlat16 *dp = data; if (dp->f_ctp && dp->f_ctp != data) iconv_close(dp->f_ctp); if (dp->t_ctp && dp->t_ctp != data) iconv_close(dp->t_ctp); dp->d_csp->cp_refcount--; kobj_delete((struct kobj*)data, M_ICONV); return (0); } static int iconv_xlat16_conv(void *d2p, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft, int convchar, int casetype) { struct iconv_xlat16 *dp = (struct iconv_xlat16*)d2p; const char *src; char *dst; int nullin, ret = 0; size_t in, on, ir, or, inlen; uint32_t code; u_char u, l; uint16_t c1, c2, ctmp; if (inbuf == NULL || *inbuf == NULL || outbuf == NULL || *outbuf == NULL) return (0); ir = in = *inbytesleft; or = on = *outbytesleft; src = *inbuf; dst = *outbuf; while(ir > 0 && or > 0) { inlen = 0; code = 0; c1 = ir > 1 ? *(src+1) & 0xff : 0; c2 = *src & 0xff; ctmp = 0; c1 = c2 & 0x80 ? c1 | 0x100 : c1; c2 = c2 & 0x80 ? c2 & 0x7f : c2; if (ir > 1 && dp->d_table[c1] && dp->d_table[c1][c2]) { /* * inbuf char is a double byte char */ inlen = 2; /* toupper,tolower */ if (casetype == KICONV_FROM_LOWER && dp->f_ctp) ctmp = towlower(((u_char)*src << 8) | (u_char)*(src + 1), dp->f_ctp); else if (casetype == KICONV_FROM_UPPER && dp->f_ctp) ctmp = towupper(((u_char)*src << 8) | (u_char)*(src + 1), dp->f_ctp); if (ctmp) { c1 = C2I1(ctmp); c2 = C2I2(ctmp); } } if (inlen == 0) { c1 &= 0xff00; if (!dp->d_table[c1]) { ret = -1; break; } /* * inbuf char is a single byte char */ inlen = 1; if (casetype & (KICONV_FROM_LOWER|KICONV_FROM_UPPER)) code = dp->d_table[c1][c2]; if (casetype == KICONV_FROM_LOWER) { if (dp->f_ctp) ctmp = towlower((u_char)*src, dp->f_ctp); else if (code & XLAT16_HAS_FROM_LOWER_CASE) ctmp = (u_char)(code >> 16); } else if (casetype == KICONV_FROM_UPPER) { if (dp->f_ctp) ctmp = towupper((u_char)*src, dp->f_ctp); else if (code & XLAT16_HAS_FROM_UPPER_CASE) ctmp = (u_char)(code >> 16); } if (ctmp) { c1 = C2I1(ctmp << 8); c2 = C2I2(ctmp << 8); } } code = dp->d_table[c1][c2]; if (!code) { ret = -1; break; } nullin = (code & XLAT16_ACCEPT_NULL_IN) ? 1 : 0; if (inlen == 1 && nullin) { /* * XLAT16_ACCEPT_NULL_IN requires inbuf has 2byte */ ret = -1; break; } /* * now start translation */ u = (u_char)(code >> 8); l = (u_char)code; #ifdef XLAT16_ACCEPT_3BYTE_CHR if (code & XLAT16_IS_3BYTE_CHR) { if (or < 3) { ret = -1; break; } *dst++ = u; *dst++ = l; *dst++ = (u_char)(code >> 16); or -= 3; } else #endif if (u || code & XLAT16_ACCEPT_NULL_OUT) { if (or < 2) { ret = -1; break; } /* toupper,tolower */ if (casetype == KICONV_LOWER && dp->t_ctp) { code = towlower((uint16_t)code, dp->t_ctp); u = (u_char)(code >> 8); l = (u_char)code; } if (casetype == KICONV_UPPER && dp->t_ctp) { code = towupper((uint16_t)code, dp->t_ctp); u = (u_char)(code >> 8); l = (u_char)code; } *dst++ = u; *dst++ = l; or -= 2; } else { /* toupper,tolower */ if (casetype == KICONV_LOWER) { if (dp->t_ctp) l = (u_char)towlower(l, dp->t_ctp); else if (code & XLAT16_HAS_LOWER_CASE) l = (u_char)(code >> 16); } if (casetype == KICONV_UPPER) { if (dp->t_ctp) l = (u_char)towupper(l, dp->t_ctp); else if (code & XLAT16_HAS_UPPER_CASE) l = (u_char)(code >> 16); } *dst++ = l; or--; } if (inlen == 2) { /* * there is a case that inbuf char is a single * byte char while inlen == 2 */ if ((u_char)*(src+1) == 0 && !nullin ) { src++; ir--; } else { src += 2; ir -= 2; } } else { src++; ir--; } if (convchar == 1) break; } *inbuf += in - ir; *outbuf += on - or; *inbytesleft -= in - ir; *outbytesleft -= on - or; return (ret); } static const char * iconv_xlat16_name(struct iconv_converter_class *dcp) { return ("xlat16"); } static int -iconv_xlat16_tolower(void *d2p, register int c) +iconv_xlat16_tolower(void *d2p, int c) { struct iconv_xlat16 *dp = (struct iconv_xlat16*)d2p; - register int c1, c2, out; + int c1, c2, out; if (c < 0x100) { c1 = C2I1(c << 8); c2 = C2I2(c << 8); } else if (c < 0x10000) { c1 = C2I1(c); c2 = C2I2(c); } else return (c); if (dp->d_table[c1] && dp->d_table[c1][c2] & XLAT16_HAS_LOWER_CASE) { /*return (int)(dp->d_table[c1][c2] & 0xffff);*/ out = dp->d_table[c1][c2] & 0xffff; if ((out & 0xff) == 0) out = (out >> 8) & 0xff; return (out); } else return (c); } static int -iconv_xlat16_toupper(void *d2p, register int c) +iconv_xlat16_toupper(void *d2p, int c) { struct iconv_xlat16 *dp = (struct iconv_xlat16*)d2p; - register int c1, c2, out; + int c1, c2, out; if (c < 0x100) { c1 = C2I1(c << 8); c2 = C2I2(c << 8); } else if (c < 0x10000) { c1 = C2I1(c); c2 = C2I2(c); } else return (c); if (dp->d_table[c1] && dp->d_table[c1][c2] & XLAT16_HAS_UPPER_CASE) { out = dp->d_table[c1][c2] & 0xffff; if ((out & 0xff) == 0) out = (out >> 8) & 0xff; return (out); } else return (c); } static kobj_method_t iconv_xlat16_methods[] = { KOBJMETHOD(iconv_converter_open, iconv_xlat16_open), KOBJMETHOD(iconv_converter_close, iconv_xlat16_close), KOBJMETHOD(iconv_converter_conv, iconv_xlat16_conv), #if 0 KOBJMETHOD(iconv_converter_init, iconv_xlat16_init), KOBJMETHOD(iconv_converter_done, iconv_xlat16_done), #endif KOBJMETHOD(iconv_converter_name, iconv_xlat16_name), KOBJMETHOD(iconv_converter_tolower, iconv_xlat16_tolower), KOBJMETHOD(iconv_converter_toupper, iconv_xlat16_toupper), {0, 0} }; KICONV_CONVERTER(xlat16, sizeof(struct iconv_xlat16)); Index: stable/10/sys/libkern/qdivrem.c =================================================================== --- stable/10/sys/libkern/qdivrem.c (revision 319285) +++ stable/10/sys/libkern/qdivrem.c (revision 319286) @@ -1,274 +1,274 @@ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * This software was developed by the Computer Systems Engineering group * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and * contributed to Berkeley. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); /* * Multiprecision divide. This algorithm is from Knuth vol. 2 (2nd ed), * section 4.3.1, pp. 257--259. */ #include #define B (1 << HALF_BITS) /* digit base */ /* Combine two `digits' to make a single two-digit number. */ #define COMBINE(a, b) (((u_long)(a) << HALF_BITS) | (b)) /* select a type for digits in base B: use unsigned short if they fit */ #if ULONG_MAX == 0xffffffff && USHRT_MAX >= 0xffff typedef unsigned short digit; #else typedef u_long digit; #endif /* * Shift p[0]..p[len] left `sh' bits, ignoring any bits that * `fall out' the left (there never will be any such anyway). * We may assume len >= 0. NOTE THAT THIS WRITES len+1 DIGITS. */ static void -__shl(register digit *p, register int len, register int sh) +__shl(digit *p, int len, int sh) { - register int i; + int i; for (i = 0; i < len; i++) p[i] = LHALF(p[i] << sh) | (p[i + 1] >> (HALF_BITS - sh)); p[i] = LHALF(p[i] << sh); } /* * __qdivrem(u, v, rem) returns u/v and, optionally, sets *rem to u%v. * * We do this in base 2-sup-HALF_BITS, so that all intermediate products * fit within u_long. As a consequence, the maximum length dividend and * divisor are 4 `digits' in this base (they are shorter if they have * leading zeros). */ u_quad_t __qdivrem(uq, vq, arq) u_quad_t uq, vq, *arq; { union uu tmp; digit *u, *v, *q; - register digit v1, v2; + digit v1, v2; u_long qhat, rhat, t; int m, n, d, j, i; digit uspace[5], vspace[5], qspace[5]; /* * Take care of special cases: divide by zero, and u < v. */ if (vq == 0) { /* divide by zero. */ static volatile const unsigned int zero = 0; tmp.ul[H] = tmp.ul[L] = 1 / zero; if (arq) *arq = uq; return (tmp.q); } if (uq < vq) { if (arq) *arq = uq; return (0); } u = &uspace[0]; v = &vspace[0]; q = &qspace[0]; /* * Break dividend and divisor into digits in base B, then * count leading zeros to determine m and n. When done, we * will have: * u = (u[1]u[2]...u[m+n]) sub B * v = (v[1]v[2]...v[n]) sub B * v[1] != 0 * 1 < n <= 4 (if n = 1, we use a different division algorithm) * m >= 0 (otherwise u < v, which we already checked) * m + n = 4 * and thus * m = 4 - n <= 2 */ tmp.uq = uq; u[0] = 0; u[1] = HHALF(tmp.ul[H]); u[2] = LHALF(tmp.ul[H]); u[3] = HHALF(tmp.ul[L]); u[4] = LHALF(tmp.ul[L]); tmp.uq = vq; v[1] = HHALF(tmp.ul[H]); v[2] = LHALF(tmp.ul[H]); v[3] = HHALF(tmp.ul[L]); v[4] = LHALF(tmp.ul[L]); for (n = 4; v[1] == 0; v++) { if (--n == 1) { u_long rbj; /* r*B+u[j] (not root boy jim) */ digit q1, q2, q3, q4; /* * Change of plan, per exercise 16. * r = 0; * for j = 1..4: * q[j] = floor((r*B + u[j]) / v), * r = (r*B + u[j]) % v; * We unroll this completely here. */ t = v[2]; /* nonzero, by definition */ q1 = u[1] / t; rbj = COMBINE(u[1] % t, u[2]); q2 = rbj / t; rbj = COMBINE(rbj % t, u[3]); q3 = rbj / t; rbj = COMBINE(rbj % t, u[4]); q4 = rbj / t; if (arq) *arq = rbj % t; tmp.ul[H] = COMBINE(q1, q2); tmp.ul[L] = COMBINE(q3, q4); return (tmp.q); } } /* * By adjusting q once we determine m, we can guarantee that * there is a complete four-digit quotient at &qspace[1] when * we finally stop. */ for (m = 4 - n; u[1] == 0; u++) m--; for (i = 4 - m; --i >= 0;) q[i] = 0; q += 4 - m; /* * Here we run Program D, translated from MIX to C and acquiring * a few minor changes. * * D1: choose multiplier 1 << d to ensure v[1] >= B/2. */ d = 0; for (t = v[1]; t < B / 2; t <<= 1) d++; if (d > 0) { __shl(&u[0], m + n, d); /* u <<= d */ __shl(&v[1], n - 1, d); /* v <<= d */ } /* * D2: j = 0. */ j = 0; v1 = v[1]; /* for D3 -- note that v[1..n] are constant */ v2 = v[2]; /* for D3 */ do { - register digit uj0, uj1, uj2; + digit uj0, uj1, uj2; /* * D3: Calculate qhat (\^q, in TeX notation). * Let qhat = min((u[j]*B + u[j+1])/v[1], B-1), and * let rhat = (u[j]*B + u[j+1]) mod v[1]. * While rhat < B and v[2]*qhat > rhat*B+u[j+2], * decrement qhat and increase rhat correspondingly. * Note that if rhat >= B, v[2]*qhat < rhat*B. */ uj0 = u[j + 0]; /* for D3 only -- note that u[j+...] change */ uj1 = u[j + 1]; /* for D3 only */ uj2 = u[j + 2]; /* for D3 only */ if (uj0 == v1) { qhat = B; rhat = uj1; goto qhat_too_big; } else { u_long nn = COMBINE(uj0, uj1); qhat = nn / v1; rhat = nn % v1; } while (v2 * qhat > COMBINE(rhat, uj2)) { qhat_too_big: qhat--; if ((rhat += v1) >= B) break; } /* * D4: Multiply and subtract. * The variable `t' holds any borrows across the loop. * We split this up so that we do not require v[0] = 0, * and to eliminate a final special case. */ for (t = 0, i = n; i > 0; i--) { t = u[i + j] - v[i] * qhat - t; u[i + j] = LHALF(t); t = (B - HHALF(t)) & (B - 1); } t = u[j] - t; u[j] = LHALF(t); /* * D5: test remainder. * There is a borrow if and only if HHALF(t) is nonzero; * in that (rare) case, qhat was too large (by exactly 1). * Fix it by adding v[1..n] to u[j..j+n]. */ if (HHALF(t)) { qhat--; for (t = 0, i = n; i > 0; i--) { /* D6: add back. */ t += u[i + j] + v[i]; u[i + j] = LHALF(t); t = HHALF(t); } u[j] = LHALF(u[j] + t); } q[j] = qhat; } while (++j <= m); /* D7: loop on j. */ /* * If caller wants the remainder, we have to calculate it as * u[m..m+n] >> d (this is at most n digits and thus fits in * u[m+1..m+n], but we may need more source digits). */ if (arq) { if (d) { for (i = m + n; i > m; --i) u[i] = (u[i] >> d) | LHALF(u[i - 1] << (HALF_BITS - d)); u[i] = 0; } tmp.ul[H] = COMBINE(uspace[1], uspace[2]); tmp.ul[L] = COMBINE(uspace[3], uspace[4]); *arq = tmp.q; } tmp.ul[H] = COMBINE(qspace[1], qspace[2]); tmp.ul[L] = COMBINE(qspace[3], qspace[4]); return (tmp.q); } Index: stable/10/sys/libkern/qsort.c =================================================================== --- stable/10/sys/libkern/qsort.c (revision 319285) +++ stable/10/sys/libkern/qsort.c (revision 319286) @@ -1,186 +1,186 @@ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include #include #ifdef I_AM_QSORT_R typedef int cmp_t(void *, const void *, const void *); #else typedef int cmp_t(const void *, const void *); #endif static __inline char *med3(char *, char *, char *, cmp_t *, void *); static __inline void swapfunc(char *, char *, int, int); #define min(a, b) (a) < (b) ? (a) : (b) /* * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function". */ #define swapcode(TYPE, parmi, parmj, n) { \ long i = (n) / sizeof (TYPE); \ - register TYPE *pi = (TYPE *) (parmi); \ - register TYPE *pj = (TYPE *) (parmj); \ + TYPE *pi = (TYPE *) (parmi); \ + TYPE *pj = (TYPE *) (parmj); \ do { \ - register TYPE t = *pi; \ + TYPE t = *pi; \ *pi++ = *pj; \ *pj++ = t; \ } while (--i > 0); \ } #define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \ es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1; static __inline void swapfunc(char *a, char *b, int n, int swaptype) { if(swaptype <= 1) swapcode(long, a, b, n) else swapcode(char, a, b, n) } #define swap(a, b) \ if (swaptype == 0) { \ long t = *(long *)(a); \ *(long *)(a) = *(long *)(b); \ *(long *)(b) = t; \ } else \ swapfunc(a, b, es, swaptype) #define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype) #ifdef I_AM_QSORT_R #define CMP(t, x, y) (cmp((t), (x), (y))) #else #define CMP(t, x, y) (cmp((x), (y))) #endif static __inline char * med3(char *a, char *b, char *c, cmp_t *cmp, void *thunk #ifndef I_AM_QSORT_R __unused #endif ) { return CMP(thunk, a, b) < 0 ? (CMP(thunk, b, c) < 0 ? b : (CMP(thunk, a, c) < 0 ? c : a )) :(CMP(thunk, b, c) > 0 ? b : (CMP(thunk, a, c) < 0 ? a : c )); } #ifdef I_AM_QSORT_R void qsort_r(void *a, size_t n, size_t es, void *thunk, cmp_t *cmp) #else #define thunk NULL void qsort(void *a, size_t n, size_t es, cmp_t *cmp) #endif { char *pa, *pb, *pc, *pd, *pl, *pm, *pn; int d, r, swaptype, swap_cnt; loop: SWAPINIT(a, es); swap_cnt = 0; if (n < 7) { for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) for (pl = pm; pl > (char *)a && CMP(thunk, pl - es, pl) > 0; pl -= es) swap(pl, pl - es); return; } pm = (char *)a + (n / 2) * es; if (n > 7) { pl = a; pn = (char *)a + (n - 1) * es; if (n > 40) { d = (n / 8) * es; pl = med3(pl, pl + d, pl + 2 * d, cmp, thunk); pm = med3(pm - d, pm, pm + d, cmp, thunk); pn = med3(pn - 2 * d, pn - d, pn, cmp, thunk); } pm = med3(pl, pm, pn, cmp, thunk); } swap(a, pm); pa = pb = (char *)a + es; pc = pd = (char *)a + (n - 1) * es; for (;;) { while (pb <= pc && (r = CMP(thunk, pb, a)) <= 0) { if (r == 0) { swap_cnt = 1; swap(pa, pb); pa += es; } pb += es; } while (pb <= pc && (r = CMP(thunk, pc, a)) >= 0) { if (r == 0) { swap_cnt = 1; swap(pc, pd); pd -= es; } pc -= es; } if (pb > pc) break; swap(pb, pc); swap_cnt = 1; pb += es; pc -= es; } if (swap_cnt == 0) { /* Switch to insertion sort */ for (pm = (char *)a + es; pm < (char *)a + n * es; pm += es) for (pl = pm; pl > (char *)a && CMP(thunk, pl - es, pl) > 0; pl -= es) swap(pl, pl - es); return; } pn = (char *)a + n * es; r = min(pa - (char *)a, pb - pa); vecswap(a, pb - r, r); r = min(pd - pc, pn - pd - es); vecswap(pb, pn - r, r); if ((r = pb - pa) > es) #ifdef I_AM_QSORT_R qsort_r(a, r / es, es, thunk, cmp); #else qsort(a, r / es, es, cmp); #endif if ((r = pd - pc) > es) { /* Iterate rather than recurse to save stack space */ a = pn - r; n = r / es; goto loop; } } Index: stable/10/sys/libkern/random.c =================================================================== --- stable/10/sys/libkern/random.c (revision 319285) +++ stable/10/sys/libkern/random.c (revision 319286) @@ -1,78 +1,78 @@ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)random.c 8.1 (Berkeley) 6/10/93 */ #include __FBSDID("$FreeBSD$"); #include #define NSHUFF 50 /* to drop some "seed -> 1st value" linearity */ static u_long randseed = 937186357; /* after srandom(1), NSHUFF counted */ void srandom(seed) u_long seed; { int i; randseed = seed; for (i = 0; i < NSHUFF; i++) (void)random(); } /* * Pseudo-random number generator for randomizing the profiling clock, * and whatever else we might use it for. The result is uniform on * [0, 2^31 - 1]. */ u_long random() { - register long x, hi, lo, t; + long x, hi, lo, t; /* * Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1). * From "Random number generators: good ones are hard to find", * Park and Miller, Communications of the ACM, vol. 31, no. 10, * October 1988, p. 1195. */ /* Can't be initialized with 0, so use another value. */ if ((x = randseed) == 0) x = 123459876; hi = x / 127773; lo = x % 127773; t = 16807 * lo - 2836 * hi; if (t < 0) t += 0x7fffffff; randseed = t; return (t); } Index: stable/10/sys/libkern/scanc.c =================================================================== --- stable/10/sys/libkern/scanc.c (revision 319285) +++ stable/10/sys/libkern/scanc.c (revision 319286) @@ -1,52 +1,52 @@ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @(#)scanc.c 8.1 (Berkeley) 6/10/93 */ #include __FBSDID("$FreeBSD$"); #include int scanc(size, cp, table, mask0) u_int size; - register const u_char *cp, table[]; + const u_char *cp, table[]; int mask0; { - register const u_char *end; - register u_char mask; + const u_char *end; + u_char mask; mask = mask0; for (end = &cp[size]; cp < end; ++cp) { if (table[*cp] & mask) break; } return (end - cp); } Index: stable/10/sys/libkern/strcmp.c =================================================================== --- stable/10/sys/libkern/strcmp.c (revision 319285) +++ stable/10/sys/libkern/strcmp.c (revision 319286) @@ -1,49 +1,49 @@ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Chris Torek. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include /* * Compare strings. */ int strcmp(s1, s2) - register const char *s1, *s2; + const char *s1, *s2; { while (*s1 == *s2++) if (*s1++ == 0) return (0); return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1)); } Index: stable/10/sys/libkern/strncpy.c =================================================================== --- stable/10/sys/libkern/strncpy.c (revision 319285) +++ stable/10/sys/libkern/strncpy.c (revision 319286) @@ -1,59 +1,59 @@ /*- * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Chris Torek. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include /* * Copy src to dst, truncating or null-padding to always copy n bytes. * Return dst. */ char * strncpy(char * __restrict dst, const char * __restrict src, size_t n) { if (n != 0) { - register char *d = dst; - register const char *s = src; + char *d = dst; + const char *s = src; do { if ((*d++ = *s++) == 0) { /* NUL pad the remaining n-1 bytes */ while (--n != 0) *d++ = 0; break; } } while (--n != 0); } return (dst); } Index: stable/10 =================================================================== --- stable/10 (revision 319285) +++ stable/10 (revision 319286) Property changes on: stable/10 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r311989