vis.c revision 1.65 1 /* $NetBSD: vis.c,v 1.65 2014/09/26 13:48:00 roy Exp $ */
2
3 /*-
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 /*-
33 * Copyright (c) 1999, 2005 The NetBSD Foundation, Inc.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 *
45 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
46 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
47 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
49 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55 * POSSIBILITY OF SUCH DAMAGE.
56 */
57
58 #include <sys/cdefs.h>
59 #if defined(LIBC_SCCS) && !defined(lint)
60 __RCSID("$NetBSD: vis.c,v 1.65 2014/09/26 13:48:00 roy Exp $");
61 #endif /* LIBC_SCCS and not lint */
62 #ifdef __FBSDID
63 __FBSDID("$FreeBSD$");
64 #define _DIAGASSERT(x) assert(x)
65 #endif
66
67 #include "namespace.h"
68 #include <sys/types.h>
69 #include <sys/param.h>
70
71 #include <assert.h>
72 #include <vis.h>
73 #include <errno.h>
74 #include <stdlib.h>
75 #include <wchar.h>
76 #include <wctype.h>
77
78 #ifdef __weak_alias
79 __weak_alias(strvisx,_strvisx)
80 #endif
81
82 #if !HAVE_VIS || !HAVE_SVIS
83 #include <ctype.h>
84 #include <limits.h>
85 #include <stdio.h>
86 #include <string.h>
87
88 /*
89 * The reason for going through the trouble to deal with character encodings
90 * in vis(3), is that we use this to safe encode output of commands. This
91 * safe encoding varies depending on the character set. For example if we
92 * display ps output in French, we don't want to display French characters
93 * as M-foo.
94 */
95
96 static wchar_t *do_svis(wchar_t *, wint_t, int, wint_t, const wchar_t *);
97
98 #undef BELL
99 #define BELL L'\a'
100
101 #define iswoctal(c) (((u_char)(c)) >= L'0' && ((u_char)(c)) <= L'7')
102 #define iswwhite(c) (c == L' ' || c == L'\t' || c == L'\n')
103 #define iswsafe(c) (c == L'\b' || c == BELL || c == L'\r')
104 #define xtoa(c) L"0123456789abcdef"[c]
105 #define XTOA(c) L"0123456789ABCDEF"[c]
106
107 #define MAXEXTRAS 30
108
109 static const wchar_t char_shell[] = L"'`\";&<>()|{}]\\$!^~";
110 static const wchar_t char_glob[] = L"*?[#";
111
112 #if !HAVE_NBTOOL_CONFIG_H
113 #ifndef __NetBSD__
114 /*
115 * On NetBSD MB_LEN_MAX is currently 32 which does not fit on any integer
116 * integral type and it is probably wrong, since currently the maximum
117 * number of bytes and character needs is 6. Until this is fixed, the
118 * loops below are using sizeof(uint64_t) - 1 instead of MB_LEN_MAX, and
119 * the assertion is commented out.
120 */
121 #ifdef __FreeBSD__
122 /*
123 * On FreeBSD including <sys/systm.h> for CTASSERT only works in kernel
124 * mode.
125 */
126 #ifndef CTASSERT
127 #define CTASSERT(x) _CTASSERT(x, __LINE__)
128 #define _CTASSERT(x, y) __CTASSERT(x, y)
129 #define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1]
130 #endif
131 #endif /* __FreeBSD__ */
132 CTASSERT(MB_LEN_MAX <= sizeof(uint64_t));
133 #endif /* !__NetBSD__ */
134 #endif
135
136 /*
137 * This is do_hvis, for HTTP style (RFC 1808)
138 */
139 static wchar_t *
140 do_hvis(wchar_t *dst, wint_t c, int flags, wint_t nextc, const wchar_t *extra)
141 {
142 if (iswalnum(c)
143 /* safe */
144 || c == L'$' || c == L'-' || c == L'_' || c == L'.' || c == L'+'
145 /* extra */
146 || c == L'!' || c == L'*' || c == L'\'' || c == L'(' || c == L')'
147 || c == L',')
148 dst = do_svis(dst, c, flags, nextc, extra);
149 else {
150 *dst++ = L'%';
151 *dst++ = xtoa(((unsigned int)c >> 4) & 0xf);
152 *dst++ = xtoa((unsigned int)c & 0xf);
153 }
154
155 return dst;
156 }
157
158 /*
159 * This is do_mvis, for Quoted-Printable MIME (RFC 2045)
160 * NB: No handling of long lines or CRLF.
161 */
162 static wchar_t *
163 do_mvis(wchar_t *dst, wint_t c, int flags, wint_t nextc, const wchar_t *extra)
164 {
165 if ((c != L'\n') &&
166 /* Space at the end of the line */
167 ((iswspace(c) && (nextc == L'\r' || nextc == L'\n')) ||
168 /* Out of range */
169 (!iswspace(c) && (c < 33 || (c > 60 && c < 62) || c > 126)) ||
170 /* Specific char to be escaped */
171 wcschr(L"#$@[\\]^`{|}~", c) != NULL)) {
172 *dst++ = L'=';
173 *dst++ = XTOA(((unsigned int)c >> 4) & 0xf);
174 *dst++ = XTOA((unsigned int)c & 0xf);
175 } else
176 dst = do_svis(dst, c, flags, nextc, extra);
177 return dst;
178 }
179
180 /*
181 * Output single byte of multibyte character.
182 */
183 static wchar_t *
184 do_mbyte(wchar_t *dst, wint_t c, int flags, wint_t nextc, int iswextra)
185 {
186 if (flags & VIS_CSTYLE) {
187 switch (c) {
188 case L'\n':
189 *dst++ = L'\\'; *dst++ = L'n';
190 return dst;
191 case L'\r':
192 *dst++ = L'\\'; *dst++ = L'r';
193 return dst;
194 case L'\b':
195 *dst++ = L'\\'; *dst++ = L'b';
196 return dst;
197 case BELL:
198 *dst++ = L'\\'; *dst++ = L'a';
199 return dst;
200 case L'\v':
201 *dst++ = L'\\'; *dst++ = L'v';
202 return dst;
203 case L'\t':
204 *dst++ = L'\\'; *dst++ = L't';
205 return dst;
206 case L'\f':
207 *dst++ = L'\\'; *dst++ = L'f';
208 return dst;
209 case L' ':
210 *dst++ = L'\\'; *dst++ = L's';
211 return dst;
212 case L'\0':
213 *dst++ = L'\\'; *dst++ = L'0';
214 if (iswoctal(nextc)) {
215 *dst++ = L'0';
216 *dst++ = L'0';
217 }
218 return dst;
219 /* We cannot encode these characters in VIS_CSTYLE
220 * because they special meaning */
221 case L'n':
222 case L'r':
223 case L'b':
224 case L'a':
225 case L'v':
226 case L't':
227 case L'f':
228 case L's':
229 case L'0':
230 case L'M':
231 case L'^':
232 break;
233 default:
234 if (iswgraph(c) && !iswoctal(c)) {
235 *dst++ = L'\\';
236 *dst++ = c;
237 return dst;
238 }
239 }
240 }
241 if (iswextra || ((c & 0177) == L' ') || (flags & VIS_OCTAL)) {
242 *dst++ = L'\\';
243 *dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + L'0';
244 *dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + L'0';
245 *dst++ = (c & 07) + L'0';
246 } else {
247 if ((flags & VIS_NOSLASH) == 0)
248 *dst++ = L'\\';
249
250 if (c & 0200) {
251 c &= 0177;
252 *dst++ = L'M';
253 }
254
255 if (iswcntrl(c)) {
256 *dst++ = L'^';
257 if (c == 0177)
258 *dst++ = L'?';
259 else
260 *dst++ = c + L'@';
261 } else {
262 *dst++ = L'-';
263 *dst++ = c;
264 }
265 }
266
267 return dst;
268 }
269
270 /*
271 * This is do_vis, the central code of vis.
272 * dst: Pointer to the destination buffer
273 * c: Character to encode
274 * flags: Flags word
275 * nextc: The character following 'c'
276 * extra: Pointer to the list of extra characters to be
277 * backslash-protected.
278 */
279 static wchar_t *
280 do_svis(wchar_t *dst, wint_t c, int flags, wint_t nextc, const wchar_t *extra)
281 {
282 int iswextra, i, shft;
283 uint64_t bmsk, wmsk;
284
285 iswextra = wcschr(extra, c) != NULL;
286 if (!iswextra && (iswgraph(c) || iswwhite(c) ||
287 ((flags & VIS_SAFE) && iswsafe(c)))) {
288 *dst++ = c;
289 return dst;
290 }
291
292 /* See comment in istrsenvisx() output loop, below. */
293 wmsk = 0;
294 for (i = sizeof(wmsk) - 1; i >= 0; i--) {
295 shft = i * NBBY;
296 bmsk = (uint64_t)0xffLL << shft;
297 wmsk |= bmsk;
298 if ((c & wmsk) || i == 0)
299 dst = do_mbyte(dst, (wint_t)(
300 (uint64_t)(c & bmsk) >> shft),
301 flags, nextc, iswextra);
302 }
303
304 return dst;
305 }
306
307 typedef wchar_t *(*visfun_t)(wchar_t *, wint_t, int, wint_t, const wchar_t *);
308
309 /*
310 * Return the appropriate encoding function depending on the flags given.
311 */
312 static visfun_t
313 getvisfun(int flags)
314 {
315 if (flags & VIS_HTTPSTYLE)
316 return do_hvis;
317 if (flags & VIS_MIMESTYLE)
318 return do_mvis;
319 return do_svis;
320 }
321
322 /*
323 * Expand list of extra characters to not visually encode.
324 */
325 static wchar_t *
326 makeextralist(int flags, const char *src)
327 {
328 wchar_t *dst, *d;
329 size_t len;
330 const wchar_t *s;
331
332 len = strlen(src);
333 if ((dst = calloc(len + MAXEXTRAS, sizeof(*dst))) == NULL)
334 return NULL;
335
336 if (mbstowcs(dst, src, len) == (size_t)-1) {
337 size_t i;
338 for (i = 0; i < len; i++)
339 dst[i] = (wchar_t)(u_char)src[i];
340 d = dst + len;
341 } else
342 d = dst + wcslen(dst);
343
344 if (flags & VIS_GLOB)
345 for (s = char_glob; *s; *d++ = *s++)
346 continue;
347
348 if (flags & VIS_SHELL)
349 for (s = char_shell; *s; *d++ = *s++)
350 continue;
351
352 if (flags & VIS_SP) *d++ = L' ';
353 if (flags & VIS_TAB) *d++ = L'\t';
354 if (flags & VIS_NL) *d++ = L'\n';
355 if ((flags & VIS_NOSLASH) == 0) *d++ = L'\\';
356 *d = L'\0';
357
358 return dst;
359 }
360
361 /*
362 * istrsenvisx()
363 * The main internal function.
364 * All user-visible functions call this one.
365 */
366 static int
367 istrsenvisx(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength,
368 int flags, const char *mbextra, int *cerr_ptr)
369 {
370 wchar_t *dst, *src, *pdst, *psrc, *start, *extra;
371 size_t len, olen;
372 uint64_t bmsk, wmsk;
373 wint_t c;
374 visfun_t f;
375 int clen = 0, cerr = 0, error = -1, i, shft;
376 ssize_t mbslength, maxolen;
377
378 _DIAGASSERT(mbdst != NULL);
379 _DIAGASSERT(mbsrc != NULL || mblength == 0);
380 _DIAGASSERT(mbextra != NULL);
381
382 /*
383 * Input (mbsrc) is a char string considered to be multibyte
384 * characters. The input loop will read this string pulling
385 * one character, possibly multiple bytes, from mbsrc and
386 * converting each to wchar_t in src.
387 *
388 * The vis conversion will be done using the wide char
389 * wchar_t string.
390 *
391 * This will then be converted back to a multibyte string to
392 * return to the caller.
393 */
394
395 /* Allocate space for the wide char strings */
396 psrc = pdst = extra = NULL;
397 if ((psrc = calloc(mblength + 1, sizeof(*psrc))) == NULL)
398 return -1;
399 if ((pdst = calloc((4 * mblength) + 1, sizeof(*pdst))) == NULL)
400 goto out;
401 dst = pdst;
402 src = psrc;
403
404 /* Use caller's multibyte conversion error flag. */
405 if (cerr_ptr)
406 cerr = *cerr_ptr;
407
408 /*
409 * Input loop.
410 * Handle up to mblength characters (not bytes). We do not
411 * stop at NULs because we may be processing a block of data
412 * that includes NULs.
413 */
414 mbslength = (ssize_t)mblength;
415 /*
416 * When inputing a single character, must also read in the
417 * next character for nextc, the look-ahead character.
418 */
419 if (mbslength == 1)
420 mbslength++;
421 while (mbslength > 0) {
422 /* Convert one multibyte character to wchar_t. */
423 if (!cerr)
424 clen = mbtowc(src, mbsrc, MB_LEN_MAX);
425 if (cerr || clen < 0) {
426 /* Conversion error, process as a byte instead. */
427 *src = (wint_t)(u_char)*mbsrc;
428 clen = 1;
429 cerr = 1;
430 }
431 if (clen == 0)
432 /*
433 * NUL in input gives 0 return value. process
434 * as single NUL byte and keep going.
435 */
436 clen = 1;
437 /* Advance buffer character pointer. */
438 src++;
439 /* Advance input pointer by number of bytes read. */
440 mbsrc += clen;
441 /* Decrement input byte count. */
442 mbslength -= clen;
443 }
444 len = src - psrc;
445 src = psrc;
446 /*
447 * In the single character input case, we will have actually
448 * processed two characters, c and nextc. Reset len back to
449 * just a single character.
450 */
451 if (mblength < len)
452 len = mblength;
453
454 /* Convert extra argument to list of characters for this mode. */
455 extra = makeextralist(flags, mbextra);
456 if (!extra) {
457 if (dlen && *dlen == 0) {
458 errno = ENOSPC;
459 goto out;
460 }
461 *mbdst = '\0'; /* can't create extra, return "" */
462 error = 0;
463 goto out;
464 }
465
466 /* Look up which processing function to call. */
467 f = getvisfun(flags);
468
469 /*
470 * Main processing loop.
471 * Call do_Xvis processing function one character at a time
472 * with next character available for look-ahead.
473 */
474 for (start = dst; len > 0; len--) {
475 c = *src++;
476 dst = (*f)(dst, c, flags, len >= 1 ? *src : L'\0', extra);
477 if (dst == NULL) {
478 errno = ENOSPC;
479 goto out;
480 }
481 }
482
483 /* Terminate the string in the buffer. */
484 *dst = L'\0';
485
486 /*
487 * Output loop.
488 * Convert wchar_t string back to multibyte output string.
489 * If we have hit a multi-byte conversion error on input,
490 * output byte-by-byte here. Else use wctomb().
491 */
492 len = wcslen(start);
493 maxolen = dlen ? *dlen : (wcslen(start) * MB_LEN_MAX + 1);
494 olen = 0;
495 for (dst = start; len > 0; len--) {
496 if (!cerr)
497 clen = wctomb(mbdst, *dst);
498 if (cerr || clen < 0) {
499 /*
500 * Conversion error, process as a byte(s) instead.
501 * Examine each byte and higher-order bytes for
502 * data. E.g.,
503 * 0x000000000000a264 -> a2 64
504 * 0x000000001f00a264 -> 1f 00 a2 64
505 */
506 clen = 0;
507 wmsk = 0;
508 for (i = sizeof(wmsk) - 1; i >= 0; i--) {
509 shft = i * NBBY;
510 bmsk = (uint64_t)0xffLL << shft;
511 wmsk |= bmsk;
512 if ((*dst & wmsk) || i == 0)
513 mbdst[clen++] = (char)(
514 (uint64_t)(*dst & bmsk) >>
515 shft);
516 }
517 cerr = 1;
518 }
519 /* If this character would exceed our output limit, stop. */
520 if (olen + clen > (size_t)maxolen)
521 break;
522 /* Advance output pointer by number of bytes written. */
523 mbdst += clen;
524 /* Advance buffer character pointer. */
525 dst++;
526 /* Incrment output character count. */
527 olen += clen;
528 }
529
530 /* Terminate the output string. */
531 *mbdst = '\0';
532
533 /* Pass conversion error flag out. */
534 if (cerr_ptr)
535 *cerr_ptr = cerr;
536
537 free(extra);
538 free(pdst);
539 free(psrc);
540
541 return (int)olen;
542 out:
543 free(extra);
544 free(pdst);
545 free(psrc);
546 return error;
547 }
548
549 static int
550 istrsenvisxl(char *mbdst, size_t *dlen, const char *mbsrc,
551 int flags, const char *mbextra, int *cerr_ptr)
552 {
553 return istrsenvisx(mbdst, dlen, mbsrc,
554 mbsrc != NULL ? strlen(mbsrc) : 0, flags, mbextra, cerr_ptr);
555 }
556
557 #endif
558
559 #if !HAVE_SVIS
560 /*
561 * The "svis" variants all take an "extra" arg that is a pointer
562 * to a NUL-terminated list of characters to be encoded, too.
563 * These functions are useful e. g. to encode strings in such a
564 * way so that they are not interpreted by a shell.
565 */
566
567 char *
568 svis(char *mbdst, int c, int flags, int nextc, const char *mbextra)
569 {
570 char cc[2];
571 int ret;
572
573 cc[0] = c;
574 cc[1] = nextc;
575
576 ret = istrsenvisx(mbdst, NULL, cc, 1, flags, mbextra, NULL);
577 if (ret < 0)
578 return NULL;
579 return mbdst + ret;
580 }
581
582 char *
583 snvis(char *mbdst, size_t dlen, int c, int flags, int nextc, const char *mbextra)
584 {
585 char cc[2];
586 int ret;
587
588 cc[0] = c;
589 cc[1] = nextc;
590
591 ret = istrsenvisx(mbdst, &dlen, cc, 1, flags, mbextra, NULL);
592 if (ret < 0)
593 return NULL;
594 return mbdst + ret;
595 }
596
597 int
598 strsvis(char *mbdst, const char *mbsrc, int flags, const char *mbextra)
599 {
600 return istrsenvisxl(mbdst, NULL, mbsrc, flags, mbextra, NULL);
601 }
602
603 int
604 strsnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags, const char *mbextra)
605 {
606 return istrsenvisxl(mbdst, &dlen, mbsrc, flags, mbextra, NULL);
607 }
608
609 int
610 strsvisx(char *mbdst, const char *mbsrc, size_t len, int flags, const char *mbextra)
611 {
612 return istrsenvisx(mbdst, NULL, mbsrc, len, flags, mbextra, NULL);
613 }
614
615 int
616 strsnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
617 const char *mbextra)
618 {
619 return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, mbextra, NULL);
620 }
621
622 int
623 strsenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
624 const char *mbextra, int *cerr_ptr)
625 {
626 return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr);
627 }
628 #endif
629
630 #if !HAVE_VIS
631 /*
632 * vis - visually encode characters
633 */
634 char *
635 vis(char *mbdst, int c, int flags, int nextc)
636 {
637 char cc[2];
638 int ret;
639
640 cc[0] = c;
641 cc[1] = nextc;
642
643 ret = istrsenvisx(mbdst, NULL, cc, 1, flags, "", NULL);
644 if (ret < 0)
645 return NULL;
646 return mbdst + ret;
647 }
648
649 char *
650 nvis(char *mbdst, size_t dlen, int c, int flags, int nextc)
651 {
652 char cc[2];
653 int ret;
654
655 cc[0] = c;
656 cc[1] = nextc;
657
658 ret = istrsenvisx(mbdst, &dlen, cc, 1, flags, "", NULL);
659 if (ret < 0)
660 return NULL;
661 return mbdst + ret;
662 }
663
664 /*
665 * strvis - visually encode characters from src into dst
666 *
667 * Dst must be 4 times the size of src to account for possible
668 * expansion. The length of dst, not including the trailing NULL,
669 * is returned.
670 */
671
672 int
673 strvis(char *mbdst, const char *mbsrc, int flags)
674 {
675 return istrsenvisxl(mbdst, NULL, mbsrc, flags, "", NULL);
676 }
677
678 int
679 strnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags)
680 {
681 return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
682 }
683
684 /*
685 * strvisx - visually encode characters from src into dst
686 *
687 * Dst must be 4 times the size of src to account for possible
688 * expansion. The length of dst, not including the trailing NULL,
689 * is returned.
690 *
691 * Strvisx encodes exactly len characters from src into dst.
692 * This is useful for encoding a block of data.
693 */
694
695 int
696 strvisx(char *mbdst, const char *mbsrc, size_t len, int flags)
697 {
698 return istrsenvisx(mbdst, NULL, mbsrc, len, flags, "", NULL);
699 }
700
701 int
702 strnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags)
703 {
704 return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, "", NULL);
705 }
706
707 int
708 strenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
709 int *cerr_ptr)
710 {
711 return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr);
712 }
713 #endif
714