| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/lib/sh/shmbchar.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* Copyright (C) 2001, 2006, 2009, 2010, 2012, 2015 Free Software Foundation, Inc. | - | ||||||||||||||||||||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||||||||||||||||||||
| 3 | This program is free software: you can redistribute it and/or modify | - | ||||||||||||||||||||||||||||||||||||||||||
| 4 | it under the terms of the GNU General Public License as published by | - | ||||||||||||||||||||||||||||||||||||||||||
| 5 | the Free Software Foundation; either version 3 of the License, or | - | ||||||||||||||||||||||||||||||||||||||||||
| 6 | (at your option) any later version. | - | ||||||||||||||||||||||||||||||||||||||||||
| 7 | - | |||||||||||||||||||||||||||||||||||||||||||
| 8 | This program is distributed in the hope that it will be useful, | - | ||||||||||||||||||||||||||||||||||||||||||
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | ||||||||||||||||||||||||||||||||||||||||||
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | ||||||||||||||||||||||||||||||||||||||||||
| 11 | GNU General Public License for more details. | - | ||||||||||||||||||||||||||||||||||||||||||
| 12 | - | |||||||||||||||||||||||||||||||||||||||||||
| 13 | You should have received a copy of the GNU General Public License | - | ||||||||||||||||||||||||||||||||||||||||||
| 14 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 15 | - | |||||||||||||||||||||||||||||||||||||||||||
| 16 | - | |||||||||||||||||||||||||||||||||||||||||||
| 17 | #include <config.h> | - | ||||||||||||||||||||||||||||||||||||||||||
| 18 | - | |||||||||||||||||||||||||||||||||||||||||||
| 19 | #if defined (HANDLE_MULTIBYTE) | - | ||||||||||||||||||||||||||||||||||||||||||
| 20 | #include <stdlib.h> | - | ||||||||||||||||||||||||||||||||||||||||||
| 21 | #include <limits.h> | - | ||||||||||||||||||||||||||||||||||||||||||
| 22 | - | |||||||||||||||||||||||||||||||||||||||||||
| 23 | #include <errno.h> | - | ||||||||||||||||||||||||||||||||||||||||||
| 24 | - | |||||||||||||||||||||||||||||||||||||||||||
| 25 | #include <shmbutil.h> | - | ||||||||||||||||||||||||||||||||||||||||||
| 26 | #include <shmbchar.h> | - | ||||||||||||||||||||||||||||||||||||||||||
| 27 | - | |||||||||||||||||||||||||||||||||||||||||||
| 28 | #ifndef errno | - | ||||||||||||||||||||||||||||||||||||||||||
| 29 | extern int errno; | - | ||||||||||||||||||||||||||||||||||||||||||
| 30 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||
| 31 | - | |||||||||||||||||||||||||||||||||||||||||||
| 32 | #if IS_BASIC_ASCII | - | ||||||||||||||||||||||||||||||||||||||||||
| 33 | - | |||||||||||||||||||||||||||||||||||||||||||
| 34 | /* Bit table of characters in the ISO C "basic character set". */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 35 | const unsigned int is_basic_table [UCHAR_MAX / 32 + 1] = | - | ||||||||||||||||||||||||||||||||||||||||||
| 36 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 0x00001a00, /* '\t' '\v' '\f' */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 0xffffffef, /* ' '...'#' '%'...'?' */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0xfffffffe, /* 'A'...'Z' '[' '\\' ']' '^' '_' */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0x7ffffffe /* 'a'...'z' '{' '|' '}' '~' */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 41 | /* The remaining bits are 0. */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 42 | }; | - | ||||||||||||||||||||||||||||||||||||||||||
| 43 | - | |||||||||||||||||||||||||||||||||||||||||||
| 44 | #endif /* IS_BASIC_ASCII */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 45 | - | |||||||||||||||||||||||||||||||||||||||||||
| 46 | extern int locale_utf8locale; | - | ||||||||||||||||||||||||||||||||||||||||||
| 47 | - | |||||||||||||||||||||||||||||||||||||||||||
| 48 | /* We can optimize this if we know the locale is UTF-8, but needs to handle | - | ||||||||||||||||||||||||||||||||||||||||||
| 49 | malformed byte sequences. */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 50 | static inline size_t | - | ||||||||||||||||||||||||||||||||||||||||||
| 51 | utf8_mbstrlen(s) | - | ||||||||||||||||||||||||||||||||||||||||||
| 52 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||
| 53 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 54 | size_t num = 0; | - | ||||||||||||||||||||||||||||||||||||||||||
| 55 | register unsigned char c; | - | ||||||||||||||||||||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||||||||||||||||||||
| 57 | while ((c = *s++))
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 58 | /* bytes 0xc0 through 0xff are first byte of multi-byte sequence */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 59 | if ((c & 0xc0) != 0x80) /* skip continuation bytes */
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ++num; never executed: ++num; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 61 | return (num); never executed: return (num); | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } | - | ||||||||||||||||||||||||||||||||||||||||||
| 63 | - | |||||||||||||||||||||||||||||||||||||||||||
| 64 | /* Adapted from GNU libutf8 */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 65 | static inline int | - | ||||||||||||||||||||||||||||||||||||||||||
| 66 | utf8_mblen (s, n) | - | ||||||||||||||||||||||||||||||||||||||||||
| 67 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||
| 68 | int n; | - | ||||||||||||||||||||||||||||||||||||||||||
| 69 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 70 | unsigned char c; | - | ||||||||||||||||||||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||||||||||||||||||||
| 72 | if (s == 0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 73 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 74 | else if (n == 0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 75 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 76 | - | |||||||||||||||||||||||||||||||||||||||||||
| 77 | c = (unsigned char) *s; | - | ||||||||||||||||||||||||||||||||||||||||||
| 78 | if (c < 0x80)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 79 | return (c != 0); never executed: return (c != 0); | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 80 | else if (c < 0xc0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 81 | goto return_error; never executed: goto return_error; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 82 | else | - | ||||||||||||||||||||||||||||||||||||||||||
| 83 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 84 | const char *start = s; | - | ||||||||||||||||||||||||||||||||||||||||||
| 85 | size_t count; | - | ||||||||||||||||||||||||||||||||||||||||||
| 86 | int check_unsafe; | - | ||||||||||||||||||||||||||||||||||||||||||
| 87 | - | |||||||||||||||||||||||||||||||||||||||||||
| 88 | if (c < 0xe0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 89 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 90 | count = 1; | - | ||||||||||||||||||||||||||||||||||||||||||
| 91 | if (c < 0xc2)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 92 | goto return_error; never executed: goto return_error; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 93 | check_unsafe = 0; | - | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 95 | else if (c < 0xf0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 96 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 97 | count = 2; | - | ||||||||||||||||||||||||||||||||||||||||||
| 98 | check_unsafe = (c == 0xe0); | - | ||||||||||||||||||||||||||||||||||||||||||
| 99 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 100 | #if SIZEOF_WCHAR_T == 4 | - | ||||||||||||||||||||||||||||||||||||||||||
| 101 | else if (c < 0xf8)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 102 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 103 | count = 3; | - | ||||||||||||||||||||||||||||||||||||||||||
| 104 | check_unsafe = (c == 0xe0); | - | ||||||||||||||||||||||||||||||||||||||||||
| 105 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 106 | else if (c < 0xfc)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 107 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 108 | count = 4; | - | ||||||||||||||||||||||||||||||||||||||||||
| 109 | check_unsafe = (c == 0xf8); | - | ||||||||||||||||||||||||||||||||||||||||||
| 110 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 111 | else if (c < 0xfe)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 112 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 113 | count = 5; | - | ||||||||||||||||||||||||||||||||||||||||||
| 114 | check_unsafe = (c == 0xfc); | - | ||||||||||||||||||||||||||||||||||||||||||
| 115 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 116 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||
| 117 | else | - | ||||||||||||||||||||||||||||||||||||||||||
| 118 | goto return_error; never executed: goto return_error; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 119 | if (n <= count)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 120 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 121 | s++; | - | ||||||||||||||||||||||||||||||||||||||||||
| 122 | c = (unsigned char) *s++ ^ 0x80; | - | ||||||||||||||||||||||||||||||||||||||||||
| 123 | if (c >= 0x40)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 124 | goto return_error; never executed: goto return_error; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 125 | if (--count > 0)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 126 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 127 | if (check_unsafe && ((c >> (6 - count)) == 0))
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 128 | goto return_error; never executed: goto return_error; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 129 | do | - | ||||||||||||||||||||||||||||||||||||||||||
| 130 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 131 | c = (unsigned char) *s++ ^ 0x80; | - | ||||||||||||||||||||||||||||||||||||||||||
| 132 | if (c >= 0x40)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 133 | goto return_error; never executed: goto return_error; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 134 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 135 | while (--count > 0);
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 136 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 137 | return s - start; never executed: return s - start; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 138 | } | - | ||||||||||||||||||||||||||||||||||||||||||
| 139 | return_error: | - | ||||||||||||||||||||||||||||||||||||||||||
| 140 | errno = EILSEQ; | - | ||||||||||||||||||||||||||||||||||||||||||
| 141 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 142 | } | - | ||||||||||||||||||||||||||||||||||||||||||
| 143 | - | |||||||||||||||||||||||||||||||||||||||||||
| 144 | /* Count the number of characters in S, counting multi-byte characters as a | - | ||||||||||||||||||||||||||||||||||||||||||
| 145 | single character. */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 146 | size_t | - | ||||||||||||||||||||||||||||||||||||||||||
| 147 | mbstrlen (s) | - | ||||||||||||||||||||||||||||||||||||||||||
| 148 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||
| 149 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 150 | size_t clen, nc; | - | ||||||||||||||||||||||||||||||||||||||||||
| 151 | mbstate_t mbs = { 0 }, mbsbak = { 0 }; | - | ||||||||||||||||||||||||||||||||||||||||||
| 152 | int f, mb_cur_max; | - | ||||||||||||||||||||||||||||||||||||||||||
| 153 | - | |||||||||||||||||||||||||||||||||||||||||||
| 154 | nc = 0; | - | ||||||||||||||||||||||||||||||||||||||||||
| 155 | mb_cur_max = MB_CUR_MAX; | - | ||||||||||||||||||||||||||||||||||||||||||
| 156 | while (*s && (clen = (f = is_basic (*s)) ? 1 : mbrlen(s, mb_cur_max, &mbs)) != 0)
| 0-7495 | ||||||||||||||||||||||||||||||||||||||||||
| 157 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 158 | if (MB_INVALIDCH(clen))
| 0-7495 | ||||||||||||||||||||||||||||||||||||||||||
| 159 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 160 | clen = 1; /* assume single byte */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 161 | mbs = mbsbak; | - | ||||||||||||||||||||||||||||||||||||||||||
| 162 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||||||||||||||||||||
| 164 | if (f == 0)
| 321-7174 | ||||||||||||||||||||||||||||||||||||||||||
| 165 | mbsbak = mbs; executed 321 times by 1 test: mbsbak = mbs;Executed by:
| 321 | ||||||||||||||||||||||||||||||||||||||||||
| 166 | - | |||||||||||||||||||||||||||||||||||||||||||
| 167 | s += clen; | - | ||||||||||||||||||||||||||||||||||||||||||
| 168 | nc++; | - | ||||||||||||||||||||||||||||||||||||||||||
| 169 | } executed 7495 times by 1 test: end of blockExecuted by:
| 7495 | ||||||||||||||||||||||||||||||||||||||||||
| 170 | return nc; executed 650 times by 1 test: return nc;Executed by:
| 650 | ||||||||||||||||||||||||||||||||||||||||||
| 171 | } | - | ||||||||||||||||||||||||||||||||||||||||||
| 172 | - | |||||||||||||||||||||||||||||||||||||||||||
| 173 | static inline char * | - | ||||||||||||||||||||||||||||||||||||||||||
| 174 | utf8_mbsmbchar (str) | - | ||||||||||||||||||||||||||||||||||||||||||
| 175 | const char *str; | - | ||||||||||||||||||||||||||||||||||||||||||
| 176 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 177 | register char *s; | - | ||||||||||||||||||||||||||||||||||||||||||
| 178 | - | |||||||||||||||||||||||||||||||||||||||||||
| 179 | for (s = (char *)str; *s; s++)
| 98412726-678369198 | ||||||||||||||||||||||||||||||||||||||||||
| 180 | if ((*s & 0xc0) == 0x80)
| 19-678369179 | ||||||||||||||||||||||||||||||||||||||||||
| 181 | return s; executed 19 times by 1 test: return s;Executed by:
| 19 | ||||||||||||||||||||||||||||||||||||||||||
| 182 | return (0); executed 98412726 times by 1 test: return (0);Executed by:
| 98412726 | ||||||||||||||||||||||||||||||||||||||||||
| 183 | } | - | ||||||||||||||||||||||||||||||||||||||||||
| 184 | - | |||||||||||||||||||||||||||||||||||||||||||
| 185 | /* Return pointer to first multibyte char in S, or NULL if none. */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 186 | /* XXX - if we know that the locale is UTF-8, we can just check whether or | - | ||||||||||||||||||||||||||||||||||||||||||
| 187 | not any byte has the eighth bit turned on */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 188 | char * | - | ||||||||||||||||||||||||||||||||||||||||||
| 189 | mbsmbchar (s) | - | ||||||||||||||||||||||||||||||||||||||||||
| 190 | const char *s; | - | ||||||||||||||||||||||||||||||||||||||||||
| 191 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 192 | char *t; | - | ||||||||||||||||||||||||||||||||||||||||||
| 193 | size_t clen; | - | ||||||||||||||||||||||||||||||||||||||||||
| 194 | mbstate_t mbs = { 0 }; | - | ||||||||||||||||||||||||||||||||||||||||||
| 195 | int mb_cur_max; | - | ||||||||||||||||||||||||||||||||||||||||||
| 196 | - | |||||||||||||||||||||||||||||||||||||||||||
| 197 | if (locale_utf8locale)
| 4506-98412745 | ||||||||||||||||||||||||||||||||||||||||||
| 198 | return (utf8_mbsmbchar (s)); /* XXX */ executed 98412745 times by 1 test: return (utf8_mbsmbchar (s));Executed by:
| 98412745 | ||||||||||||||||||||||||||||||||||||||||||
| 199 | - | |||||||||||||||||||||||||||||||||||||||||||
| 200 | mb_cur_max = MB_CUR_MAX; | - | ||||||||||||||||||||||||||||||||||||||||||
| 201 | for (t = (char *)s; *t; t++)
| 4506-40022 | ||||||||||||||||||||||||||||||||||||||||||
| 202 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 203 | if (is_basic (*t))
| 226-39796 | ||||||||||||||||||||||||||||||||||||||||||
| 204 | continue; executed 39796 times by 1 test: continue;Executed by:
| 39796 | ||||||||||||||||||||||||||||||||||||||||||
| 205 | - | |||||||||||||||||||||||||||||||||||||||||||
| 206 | if (locale_utf8locale) /* not used if above code active */
| 0-226 | ||||||||||||||||||||||||||||||||||||||||||
| 207 | clen = utf8_mblen (t, mb_cur_max); never executed: clen = utf8_mblen (t, mb_cur_max); | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 208 | else | - | ||||||||||||||||||||||||||||||||||||||||||
| 209 | clen = mbrlen (t, mb_cur_max, &mbs); executed 226 times by 1 test: clen = mbrlen (t, mb_cur_max, &mbs);Executed by:
| 226 | ||||||||||||||||||||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||||||||||||||||||||
| 211 | if (clen == 0)
| 0-226 | ||||||||||||||||||||||||||||||||||||||||||
| 212 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 213 | if (MB_INVALIDCH(clen))
| 0-226 | ||||||||||||||||||||||||||||||||||||||||||
| 214 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 215 | - | |||||||||||||||||||||||||||||||||||||||||||
| 216 | if (clen > 1)
| 0-226 | ||||||||||||||||||||||||||||||||||||||||||
| 217 | return t; never executed: return t; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 218 | } executed 226 times by 1 test: end of blockExecuted by:
| 226 | ||||||||||||||||||||||||||||||||||||||||||
| 219 | return 0; executed 4506 times by 1 test: return 0;Executed by:
| 4506 | ||||||||||||||||||||||||||||||||||||||||||
| 220 | } | - | ||||||||||||||||||||||||||||||||||||||||||
| 221 | - | |||||||||||||||||||||||||||||||||||||||||||
| 222 | static inline int | - | ||||||||||||||||||||||||||||||||||||||||||
| 223 | utf_mbsnlen(src, srclen, maxlen) | - | ||||||||||||||||||||||||||||||||||||||||||
| 224 | const char *src; | - | ||||||||||||||||||||||||||||||||||||||||||
| 225 | size_t srclen; | - | ||||||||||||||||||||||||||||||||||||||||||
| 226 | int maxlen; | - | ||||||||||||||||||||||||||||||||||||||||||
| 227 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 228 | register int sind, count; | - | ||||||||||||||||||||||||||||||||||||||||||
| 229 | - | |||||||||||||||||||||||||||||||||||||||||||
| 230 | for (sind = count = 0; src[sind] && sind <= maxlen; sind++)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 231 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 232 | if ((src[sind] & 0xc0) != 0x80)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 233 | count++; never executed: count++; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 234 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 235 | return (count); never executed: return (count); | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 236 | } | - | ||||||||||||||||||||||||||||||||||||||||||
| 237 | - | |||||||||||||||||||||||||||||||||||||||||||
| 238 | int | - | ||||||||||||||||||||||||||||||||||||||||||
| 239 | sh_mbsnlen(src, srclen, maxlen) | - | ||||||||||||||||||||||||||||||||||||||||||
| 240 | const char *src; | - | ||||||||||||||||||||||||||||||||||||||||||
| 241 | size_t srclen; | - | ||||||||||||||||||||||||||||||||||||||||||
| 242 | int maxlen; | - | ||||||||||||||||||||||||||||||||||||||||||
| 243 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 244 | int count; | - | ||||||||||||||||||||||||||||||||||||||||||
| 245 | int sind; | - | ||||||||||||||||||||||||||||||||||||||||||
| 246 | DECLARE_MBSTATE; | - | ||||||||||||||||||||||||||||||||||||||||||
| 247 | - | |||||||||||||||||||||||||||||||||||||||||||
| 248 | for (sind = count = 0; src[sind]; )
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 249 | { | - | ||||||||||||||||||||||||||||||||||||||||||
| 250 | count++; /* number of multibyte characters */ | - | ||||||||||||||||||||||||||||||||||||||||||
| 251 | ADVANCE_CHAR (src, srclen, sind); never executed: mblength = 1;never executed: mblength = 1;never executed: end of blocknever executed: end of blocknever executed: (sind)++;never executed: (sind) += mblength;never executed: (sind)++;
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 252 | if (sind > maxlen)
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| 253 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 254 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 255 | - | |||||||||||||||||||||||||||||||||||||||||||
| 256 | return count; never executed: return count; | 0 | ||||||||||||||||||||||||||||||||||||||||||
| 257 | } | - | ||||||||||||||||||||||||||||||||||||||||||
| 258 | #endif | - | ||||||||||||||||||||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |