[BACK]Return to vis.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / gen

Annotation of src/lib/libc/gen/vis.c, Revision 1.49

1.49    ! christos    1: /*     $NetBSD: vis.c,v 1.48 2013/02/13 12:15:09 pooka Exp $   */
1.6       cgd         2:
1.1       cgd         3: /*-
1.6       cgd         4:  * Copyright (c) 1989, 1993
1.16      wennmach    5:  *     The Regents of the University of California.  All rights reserved.
1.1       cgd         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.
1.29      lukem      15:  * 3. Neither the name of the University nor the names of its contributors
1.1       cgd        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:
1.26      agc        32: /*-
1.31      lukem      33:  * Copyright (c) 1999, 2005 The NetBSD Foundation, Inc.
1.30      lukem      34:  * All rights reserved.
1.26      agc        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:  *
1.30      lukem      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.
1.26      agc        56:  */
                     57:
1.7       christos   58: #include <sys/cdefs.h>
1.21      tv         59: #if defined(LIBC_SCCS) && !defined(lint)
1.49    ! christos   60: __RCSID("$NetBSD: vis.c,v 1.48 2013/02/13 12:15:09 pooka Exp $");
1.21      tv         61: #endif /* LIBC_SCCS and not lint */
1.46      christos   62: #ifdef __FBSDID
                     63: __FBSDID("$FreeBSD$");
                     64: #define        _DIAGASSERT(x)  assert(x)
                     65: #endif
1.1       cgd        66:
1.8       jtc        67: #include "namespace.h"
1.1       cgd        68: #include <sys/types.h>
1.12      lukem      69:
                     70: #include <assert.h>
1.1       cgd        71: #include <vis.h>
1.44      christos   72: #include <errno.h>
1.22      christos   73: #include <stdlib.h>
1.46      christos   74: #include <wchar.h>
                     75: #include <wctype.h>
1.8       jtc        76:
                     77: #ifdef __weak_alias
1.18      mycroft    78: __weak_alias(strvisx,_strvisx)
1.20      tv         79: #endif
                     80:
1.24      pooka      81: #if !HAVE_VIS || !HAVE_SVIS
1.20      tv         82: #include <ctype.h>
                     83: #include <limits.h>
                     84: #include <stdio.h>
                     85: #include <string.h>
1.1       cgd        86:
1.47      christos   87: /*
                     88:  * The reason for going through the trouble to deal with character encodings
                     89:  * in vis(3), is that we use this to safe encode output of commands. This
                     90:  * safe encoding varies depending on the character set. For example if we
                     91:  * display ps output in French, we don't want to display French characters
                     92:  * as M-foo.
                     93:  */
                     94:
1.48      pooka      95: static wchar_t *do_svis(wchar_t *, wint_t, int, wint_t, const wchar_t *);
1.37      dsl        96:
1.15      wennmach   97: #undef BELL
1.46      christos   98: #define BELL L'\a'
1.15      wennmach   99:
1.46      christos  100: #define iswoctal(c)    (((u_char)(c)) >= L'0' && ((u_char)(c)) <= L'7')
                    101: #define iswwhite(c)    (c == L' ' || c == L'\t' || c == L'\n')
                    102: #define iswsafe(c)     (c == L'\b' || c == BELL || c == L'\r')
                    103: #define xtoa(c)                L"0123456789abcdef"[c]
                    104: #define XTOA(c)                L"0123456789ABCDEF"[c]
1.16      wennmach  105:
1.45      christos  106: #define MAXEXTRAS      9
1.15      wennmach  107:
1.34      martin    108: #define MAKEEXTRALIST(flag, extra, orig_str)                                 \
1.16      wennmach  109: do {                                                                         \
1.46      christos  110:        const wchar_t *orig = orig_str;                                       \
                    111:        const wchar_t *o = orig;                                              \
                    112:        wchar_t *e;                                                           \
1.22      christos  113:        while (*o++)                                                          \
                    114:                continue;                                                     \
1.46      christos  115:        extra = calloc((size_t)((o - orig) + MAXEXTRAS), sizeof(*extra));    \
1.31      lukem     116:        if (!extra) break;                                                    \
1.46      christos  117:        for (o = orig, e = extra; (*e++ = *o++) != L'\0';)                    \
1.22      christos  118:                continue;                                                     \
                    119:        e--;                                                                  \
1.45      christos  120:        if (flag & VIS_GLOB) {                                                \
1.46      christos  121:                *e++ = L'*';                                                  \
                    122:                *e++ = L'?';                                                  \
                    123:                *e++ = L'[';                                                  \
                    124:                *e++ = L'#';                                                  \
1.45      christos  125:        }                                                                     \
1.46      christos  126:        if (flag & VIS_SP) *e++ = L' ';                                       \
                    127:        if (flag & VIS_TAB) *e++ = L'\t';                                     \
                    128:        if (flag & VIS_NL) *e++ = L'\n';                                      \
                    129:        if ((flag & VIS_NOSLASH) == 0) *e++ = L'\\';                          \
                    130:        *e = L'\0';                                                           \
1.19      mycroft   131: } while (/*CONSTCOND*/0)
1.15      wennmach  132:
1.22      christos  133: /*
1.37      dsl       134:  * This is do_hvis, for HTTP style (RFC 1808)
1.22      christos  135:  */
1.46      christos  136: static wchar_t *
                    137: do_hvis(wchar_t *dst, wint_t c, int flag, wint_t nextc, const wchar_t *extra)
1.37      dsl       138: {
1.46      christos  139:        if (iswalnum(c)
1.41      plunky    140:            /* safe */
1.46      christos  141:            || c == L'$' || c == L'-' || c == L'_' || c == L'.' || c == L'+'
1.41      plunky    142:            /* extra */
1.46      christos  143:            || c == L'!' || c == L'*' || c == L'\'' || c == L'(' || c == L')'
                    144:            || c == L',')
                    145:                dst = do_svis(dst, c, flag, nextc, extra);
                    146:        else {
                    147:                *dst++ = L'%';
1.37      dsl       148:                *dst++ = xtoa(((unsigned int)c >> 4) & 0xf);
                    149:                *dst++ = xtoa((unsigned int)c & 0xf);
                    150:        }
1.41      plunky    151:
1.37      dsl       152:        return dst;
                    153: }
1.27      enami     154:
1.15      wennmach  155: /*
1.39      christos  156:  * This is do_mvis, for Quoted-Printable MIME (RFC 2045)
                    157:  * NB: No handling of long lines or CRLF.
                    158:  */
1.46      christos  159: static wchar_t *
                    160: do_mvis(wchar_t *dst, wint_t c, int flag, wint_t nextc, const wchar_t *extra)
1.39      christos  161: {
1.46      christos  162:        if ((c != L'\n') &&
1.39      christos  163:            /* Space at the end of the line */
1.46      christos  164:            ((iswspace(c) && (nextc == L'\r' || nextc == L'\n')) ||
1.39      christos  165:            /* Out of range */
1.46      christos  166:            (!iswspace(c) && (c < 33 || (c > 60 && c < 62) || c > 126)) ||
1.39      christos  167:            /* Specific char to be escaped */
1.46      christos  168:            wcschr(L"#$@[\\]^`{|}~", c) != NULL)) {
                    169:                *dst++ = L'=';
1.39      christos  170:                *dst++ = XTOA(((unsigned int)c >> 4) & 0xf);
                    171:                *dst++ = XTOA((unsigned int)c & 0xf);
1.46      christos  172:        } else
                    173:                dst = do_svis(dst, c, flag, nextc, extra);
1.39      christos  174:        return dst;
                    175: }
                    176:
                    177: /*
1.37      dsl       178:  * This is do_vis, the central code of vis.
1.16      wennmach  179:  * dst:              Pointer to the destination buffer
                    180:  * c:        Character to encode
1.15      wennmach  181:  * flag:      Flag word
                    182:  * nextc:     The character following 'c'
                    183:  * extra:     Pointer to the list of extra characters to be
1.16      wennmach  184:  *           backslash-protected.
1.15      wennmach  185:  */
1.46      christos  186: static wchar_t *
                    187: do_svis(wchar_t *dst, wint_t c, int flag, wint_t nextc, const wchar_t *extra)
1.37      dsl       188: {
1.46      christos  189:        int iswextra;
1.43      christos  190:
1.46      christos  191:        iswextra = wcschr(extra, c) != NULL;
                    192:        if (!iswextra && (iswgraph(c) || iswwhite(c) ||
                    193:            ((flag & VIS_SAFE) && iswsafe(c)))) {
1.37      dsl       194:                *dst++ = c;
                    195:                return dst;
                    196:        }
                    197:        if (flag & VIS_CSTYLE) {
                    198:                switch (c) {
1.46      christos  199:                case L'\n':
                    200:                        *dst++ = L'\\'; *dst++ = L'n';
1.37      dsl       201:                        return dst;
1.46      christos  202:                case L'\r':
                    203:                        *dst++ = L'\\'; *dst++ = L'r';
1.37      dsl       204:                        return dst;
1.46      christos  205:                case L'\b':
                    206:                        *dst++ = L'\\'; *dst++ = L'b';
1.37      dsl       207:                        return dst;
                    208:                case BELL:
1.46      christos  209:                        *dst++ = L'\\'; *dst++ = L'a';
1.37      dsl       210:                        return dst;
1.46      christos  211:                case L'\v':
                    212:                        *dst++ = L'\\'; *dst++ = L'v';
1.37      dsl       213:                        return dst;
1.46      christos  214:                case L'\t':
                    215:                        *dst++ = L'\\'; *dst++ = L't';
1.37      dsl       216:                        return dst;
1.46      christos  217:                case L'\f':
                    218:                        *dst++ = L'\\'; *dst++ = L'f';
1.37      dsl       219:                        return dst;
1.46      christos  220:                case L' ':
                    221:                        *dst++ = L'\\'; *dst++ = L's';
1.37      dsl       222:                        return dst;
1.46      christos  223:                case L'\0':
                    224:                        *dst++ = L'\\'; *dst++ = L'0';
                    225:                        if (iswoctal(nextc)) {
                    226:                                *dst++ = L'0';
                    227:                                *dst++ = L'0';
1.37      dsl       228:                        }
                    229:                        return dst;
                    230:                default:
1.46      christos  231:                        if (iswgraph(c)) {
                    232:                                *dst++ = L'\\';
                    233:                                *dst++ = c;
1.37      dsl       234:                                return dst;
                    235:                        }
                    236:                }
                    237:        }
1.46      christos  238:        if (iswextra || ((c & 0177) == L' ') || (flag & VIS_OCTAL)) {
                    239:                *dst++ = L'\\';
                    240:                *dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + L'0';
                    241:                *dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + L'0';
                    242:                *dst++ =                             (c       & 07) + L'0';
1.37      dsl       243:        } else {
1.46      christos  244:                if ((flag & VIS_NOSLASH) == 0)
                    245:                        *dst++ = L'\\';
1.42      christos  246:
1.37      dsl       247:                if (c & 0200) {
1.46      christos  248:                        c &= 0177;
                    249:                        *dst++ = L'M';
1.37      dsl       250:                }
1.42      christos  251:
1.46      christos  252:                if (iswcntrl(c)) {
                    253:                        *dst++ = L'^';
1.37      dsl       254:                        if (c == 0177)
1.46      christos  255:                                *dst++ = L'?';
1.37      dsl       256:                        else
1.46      christos  257:                                *dst++ = c + L'@';
1.37      dsl       258:                } else {
1.46      christos  259:                        *dst++ = L'-';
                    260:                        *dst++ = c;
1.37      dsl       261:                }
                    262:        }
                    263:        return dst;
                    264: }
1.15      wennmach  265:
1.46      christos  266: typedef wchar_t *(*visfun_t)(wchar_t *, wint_t, int, wint_t, const wchar_t *);
1.39      christos  267:
                    268: /*
                    269:  * Return the appropriate encoding function depending on the flags given.
                    270:  */
                    271: static visfun_t
                    272: getvisfun(int flag)
                    273: {
                    274:        if (flag & VIS_HTTPSTYLE)
                    275:                return do_hvis;
1.40      christos  276:        if (flag & VIS_MIMESTYLE)
1.39      christos  277:                return do_mvis;
                    278:        return do_svis;
                    279: }
1.15      wennmach  280:
                    281: /*
1.46      christos  282:  * istrsnvisx()
                    283:  *     The main internal function.
                    284:  *     All user-visible functions call this one.
1.15      wennmach  285:  */
1.46      christos  286: static int
                    287: istrsnvisx(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength,
                    288:     int flag, const char *mbextra)
1.15      wennmach  289: {
1.46      christos  290:        wchar_t *dst, *src, *pdst, *psrc, *start, *extra, *nextra;
                    291:        size_t len, olen, mbslength;
                    292:        wint_t c;
1.39      christos  293:        visfun_t f;
1.46      christos  294:        int clen, error = -1;
                    295:
                    296:        _DIAGASSERT(mbdst != NULL);
                    297:        _DIAGASSERT(mbsrc != NULL);
                    298:        _DIAGASSERT(mbextra != NULL);
                    299:
                    300:        psrc = pdst = extra = nextra = NULL;
                    301:        if (!mblength)
                    302:                mblength = strlen(mbsrc);
1.31      lukem     303:
1.46      christos  304:        if ((psrc = calloc(mblength + 1, sizeof(*psrc))) == NULL)
                    305:                return -1;
                    306:        if ((pdst = calloc((4 * mblength) + 1, sizeof(*pdst))) == NULL)
                    307:                goto out;
                    308:        if ((extra = calloc((strlen(mbextra) + 1), sizeof(*extra))) == NULL)
                    309:                goto out;
                    310:
                    311:        dst = pdst;
                    312:        src = psrc;
                    313:
                    314:        if (mblength > 1) {
                    315:                mbslength = mblength;
                    316:                while (mbslength) {
                    317:                        clen = mbtowc(src, mbsrc, mbslength);
1.49    ! christos  318:                        if (clen < 0) {
        !           319:                                *src = (wint_t)(u_char)*mbsrc;
        !           320:                                clen = 1;
        !           321:                        }
1.46      christos  322:                        if (clen == 0)
                    323:                                clen = 1;
                    324:                        src++;
                    325:                        mbsrc += clen;
                    326:                        mbslength -= clen;
                    327:                }
                    328:                len = src - psrc;
                    329:                src = psrc;
                    330:        } else {
                    331:                len = mblength;
                    332:                src[0] = (wint_t)(u_char)mbsrc[0];
                    333:                src[1] = (wint_t)(u_char)mbsrc[1];
                    334:        }
                    335:        if (mblength < len)
                    336:                len = mblength;
                    337:
                    338:        mbstowcs(extra, mbextra, strlen(mbextra));
1.22      christos  339:        MAKEEXTRALIST(flag, nextra, extra);
1.31      lukem     340:        if (!nextra) {
1.44      christos  341:                if (dlen && *dlen == 0) {
                    342:                        errno = ENOSPC;
1.46      christos  343:                        goto out;
1.44      christos  344:                }
1.46      christos  345:                *mbdst = '\0';          /* can't create nextra, return "" */
                    346:                error = 0;
                    347:                goto out;
1.31      lukem     348:        }
1.46      christos  349:
1.39      christos  350:        f = getvisfun(flag);
1.46      christos  351:
                    352:        for (start = dst; len > 0; len--) {
                    353:                c = *src++;
                    354:                dst = (*f)(dst, c, flag, len >= 1 ? *src : L'\0', nextra);
                    355:                if (dst == NULL) {
                    356:                        errno = ENOSPC;
                    357:                        goto out;
                    358:                }
                    359:        }
                    360:
                    361:        *dst = L'\0';
                    362:
                    363:        len = dlen ? *dlen : ((wcslen(start) + 1) * MB_LEN_MAX);
                    364:        olen = wcstombs(mbdst, start, len * sizeof(*mbdst));
                    365:
                    366:        free(nextra);
                    367:        free(extra);
                    368:        free(pdst);
                    369:        free(psrc);
                    370:
                    371:        return (int)olen;
                    372: out:
1.31      lukem     373:        free(nextra);
1.46      christos  374:        free(extra);
                    375:        free(pdst);
                    376:        free(psrc);
                    377:        return error;
1.15      wennmach  378: }
1.46      christos  379: #endif
                    380:
                    381: #if !HAVE_SVIS
                    382: /*
                    383:  *     The "svis" variants all take an "extra" arg that is a pointer
                    384:  *     to a NUL-terminated list of characters to be encoded, too.
                    385:  *     These functions are useful e. g. to encode strings in such a
                    386:  *     way so that they are not interpreted by a shell.
                    387:  */
1.15      wennmach  388:
1.44      christos  389: char *
1.46      christos  390: svis(char *mbdst, int c, int flag, int nextc, const char *mbextra)
1.44      christos  391: {
1.46      christos  392:        char cc[2];
                    393:        int ret;
                    394:
                    395:        cc[0] = c;
                    396:        cc[1] = nextc;
                    397:
                    398:        ret = istrsnvisx(mbdst, NULL, cc, 1, flag, mbextra);
                    399:        if (ret < 0)
                    400:                return NULL;
                    401:        return mbdst + ret;
1.44      christos  402: }
                    403:
                    404: char *
1.46      christos  405: snvis(char *mbdst, size_t dlen, int c, int flag, int nextc, const char *mbextra)
1.44      christos  406: {
1.46      christos  407:        char cc[2];
                    408:        int ret;
1.44      christos  409:
1.46      christos  410:        cc[0] = c;
                    411:        cc[1] = nextc;
1.15      wennmach  412:
1.46      christos  413:        ret = istrsnvisx(mbdst, &dlen, cc, 1, flag, mbextra);
                    414:        if (ret < 0)
                    415:                return NULL;
                    416:        return mbdst + ret;
1.15      wennmach  417: }
                    418:
1.44      christos  419: int
1.46      christos  420: strsvis(char *mbdst, const char *mbsrc, int flag, const char *mbextra)
1.44      christos  421: {
1.46      christos  422:        return istrsnvisx(mbdst, NULL, mbsrc, 0, flag, mbextra);
1.44      christos  423: }
1.15      wennmach  424:
                    425: int
1.46      christos  426: strsnvis(char *mbdst, size_t dlen, const char *mbsrc, int flag, const char *mbextra)
1.44      christos  427: {
1.46      christos  428:        return istrsnvisx(mbdst, &dlen, mbsrc, 0, flag, mbextra);
1.15      wennmach  429: }
1.44      christos  430:
                    431: int
1.46      christos  432: strsvisx(char *mbdst, const char *mbsrc, size_t len, int flag, const char *mbextra)
1.44      christos  433: {
1.46      christos  434:        return istrsnvisx(mbdst, NULL, mbsrc, len, flag, mbextra);
1.44      christos  435: }
                    436:
                    437: int
1.46      christos  438: strsnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flag,
                    439:     const char *mbextra)
1.44      christos  440: {
1.46      christos  441:        return istrsnvisx(mbdst, &dlen, mbsrc, len, flag, mbextra);
1.44      christos  442: }
1.24      pooka     443: #endif
1.15      wennmach  444:
1.24      pooka     445: #if !HAVE_VIS
1.1       cgd       446: /*
                    447:  * vis - visually encode characters
                    448:  */
1.46      christos  449: char *
                    450: vis(char *mbdst, int c, int flag, int nextc)
1.15      wennmach  451: {
1.46      christos  452:        char cc[2];
                    453:        int ret;
1.15      wennmach  454:
1.46      christos  455:        cc[0] = c;
                    456:        cc[1] = nextc;
1.15      wennmach  457:
1.46      christos  458:        ret = istrsnvisx(mbdst, NULL, cc, 1, flag, "");
                    459:        if (ret < 0)
1.44      christos  460:                return NULL;
1.46      christos  461:        return mbdst + ret;
1.1       cgd       462: }
                    463:
1.44      christos  464: char *
1.46      christos  465: nvis(char *mbdst, size_t dlen, int c, int flag, int nextc)
1.44      christos  466: {
1.46      christos  467:        char cc[2];
                    468:        int ret;
                    469:
                    470:        cc[0] = c;
                    471:        cc[1] = nextc;
1.44      christos  472:
1.46      christos  473:        ret = istrsnvisx(mbdst, &dlen, cc, 1, flag, "");
                    474:        if (ret < 0)
                    475:                return NULL;
                    476:        return mbdst + ret;
1.44      christos  477: }
                    478:
1.1       cgd       479: /*
1.46      christos  480:  * strvis - visually encode characters from src into dst
1.27      enami     481:  *
1.16      wennmach  482:  *     Dst must be 4 times the size of src to account for possible
                    483:  *     expansion.  The length of dst, not including the trailing NULL,
1.27      enami     484:  *     is returned.
1.1       cgd       485:  */
                    486:
1.44      christos  487: int
1.46      christos  488: strvis(char *mbdst, const char *mbsrc, int flag)
1.44      christos  489: {
1.46      christos  490:        return istrsnvisx(mbdst, NULL, mbsrc, 0, flag, "");
1.44      christos  491: }
1.15      wennmach  492:
1.1       cgd       493: int
1.46      christos  494: strnvis(char *mbdst, size_t dlen, const char *mbsrc, int flag)
1.44      christos  495: {
1.46      christos  496:        return istrsnvisx(mbdst, &dlen, mbsrc, 0, flag, "");
1.44      christos  497: }
                    498:
1.46      christos  499: /*
                    500:  * strvisx - visually encode characters from src into dst
                    501:  *
                    502:  *     Dst must be 4 times the size of src to account for possible
                    503:  *     expansion.  The length of dst, not including the trailing NULL,
                    504:  *     is returned.
                    505:  *
                    506:  *     Strvisx encodes exactly len characters from src into dst.
                    507:  *     This is useful for encoding a block of data.
                    508:  */
1.44      christos  509:
                    510: int
1.46      christos  511: strvisx(char *mbdst, const char *mbsrc, size_t len, int flag)
1.44      christos  512: {
1.46      christos  513:        return istrsnvisx(mbdst, NULL, mbsrc, len, flag, "");
1.44      christos  514: }
                    515:
                    516: int
1.46      christos  517: strnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flag)
1.44      christos  518: {
1.46      christos  519:        return istrsnvisx(mbdst, &dlen, mbsrc, len, flag, "");
1.44      christos  520: }
1.20      tv        521: #endif

CVSweb <webmaster@jp.NetBSD.org>