gonzui


Format: Advanced Search

t2ex/bsd_source/lib/libc/src_bsd/stdio/multibyte_citrus.cbare sourcepermlink (0.01 seconds)

Search this content:

    1: /*      $OpenBSD: multibyte_citrus.c,v 1.1 2010/07/27 16:59:04 stsp Exp $ */
    2: /*      $NetBSD: multibyte_amd1.c,v 1.7 2009/01/11 02:46:28 christos Exp $ */
    3: 
    4: /*-
    5:  * Copyright (c)2002, 2008 Citrus Project,
    6:  * All rights reserved.
    7:  *
    8:  * Redistribution and use in source and binary forms, with or without
    9:  * modification, are permitted provided that the following conditions
   10:  * are met:
   11:  * 1. Redistributions of source code must retain the above copyright
   12:  *    notice, this list of conditions and the following disclaimer.
   13:  * 2. Redistributions in binary form must reproduce the above copyright
   14:  *    notice, this list of conditions and the following disclaimer in the
   15:  *    documentation and/or other materials provided with the distribution.
   16:  *
   17:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   18:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   21:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   23:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   24:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   25:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   26:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27:  * SUCH DAMAGE.
   28:  */
   29: 
   30: #include <sys/cdefs.h>
   31: #include <sys/types.h>
   32: #include <errno.h>
   33: #include <wchar.h>
   34: 
   35: #include "citrus_ctype.h"
   36: #include "rune.h"
   37: #include "multibyte.h"
   38: 
   39: int
   40: mbsinit(const mbstate_t *ps)
   41: {
   42:         struct _citrus_ctype_rec *cc;
   43:         _RuneLocale *rl;
   44: 
   45:         if (ps == NULL)
   46:                 return 1;
   47: 
   48:         rl = _ps_to_runelocale(ps);
   49:         if (rl == NULL)
   50:                 rl = _CurrentRuneLocale;
   51:         cc = rl->rl_citrus_ctype;
   52:         return (*cc->cc_ops->co_mbsinit)(ps);
   53: }
   54: 
   55: size_t
   56: mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
   57: {
   58:         static mbstate_t mbs;
   59:         struct _citrus_ctype_rec *cc;
   60: 
   61:         if (ps == NULL)
   62:                 ps = &mbs;
   63:         cc = _CurrentRuneLocale->rl_citrus_ctype;
   64:         return (*cc->cc_ops->co_mbrtowc)(pwc, s, n, _ps_to_private(ps));
   65: }
   66: 
   67: size_t
   68: mbsrtowcs(wchar_t *pwcs, const char **s, size_t n, mbstate_t *ps)
   69: {
   70:         static mbstate_t mbs;
   71:         struct _citrus_ctype_rec *cc;
   72: 
   73:         if (ps == NULL)
   74:                 ps = &mbs;
   75:         cc = _CurrentRuneLocale->rl_citrus_ctype;
   76:         return (*cc->cc_ops->co_mbsrtowcs)(pwcs, s, n, _ps_to_private(ps));
   77: }
   78: 
   79: size_t
   80: wcrtomb(char *s, wchar_t wc, mbstate_t *ps)
   81: {
   82:         static mbstate_t mbs;
   83:         struct _citrus_ctype_rec *cc;
   84: 
   85:         if (ps == NULL)
   86:                 ps = &mbs;
   87:         cc = _CurrentRuneLocale->rl_citrus_ctype;
   88:         return (*cc->cc_ops->co_wcrtomb)(s, wc, _ps_to_private(ps));
   89: }
   90: 
   91: size_t
   92: wcsrtombs(char *s, const wchar_t **ppwcs, size_t n, mbstate_t *ps)
   93: {
   94:         static mbstate_t mbs;
   95:         struct _citrus_ctype_rec *cc;
   96: 
   97:         if (ps == NULL)
   98:                 ps = &mbs;
   99:         cc = _CurrentRuneLocale->rl_citrus_ctype;
  100:         return (*cc->cc_ops->co_wcsrtombs)(s, ppwcs, n, _ps_to_private(ps));
  101: }