gonzui


Format: Advanced Search

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

Search this content:

    1: /*      $OpenBSD: citrus_none.c,v 1.2 2010/08/03 11:23:37 stsp Exp $ */
    2: /*      $NetBSD: citrus_none.c,v 1.18 2008/06/14 16:01:07 tnozaki Exp $      */
    3: 
    4: /*-
    5:  * Copyright (c)2002 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: 
   33: #include <errno.h>
   34: #include <string.h>
   35: #include <stdio.h>
   36: #include <stdlib.h>
   37: #include <stddef.h>
   38: #include <wchar.h>
   39: 
   40: #include "citrus_ctype.h"
   41: #include "citrus_none.h"
   42: 
   43: _CITRUS_CTYPE_DEF_OPS(none);
   44: 
   45: size_t
   46: /*ARGSUSED*/
   47: _citrus_none_ctype_mbrtowc(wchar_t * __restrict pwc,
   48:                            const char * __restrict s, size_t n,
   49:                            void * __restrict pspriv)
   50: {
   51:         /* pwc may be NULL */
   52:         /* s may be NULL */
   53:         /* pspriv appears to be unused */
   54: 
   55:         if (s == NULL)
   56:                 return 0;
   57:         if (n == 0)
   58:                 return (size_t)-2;
   59:         if (pwc)
   60:                 *pwc = (wchar_t)(unsigned char)*s;
   61:         return (*s != '\0');
   62: }
   63: 
   64: int
   65: /*ARGSUSED*/
   66: _citrus_none_ctype_mbsinit(const void * __restrict pspriv)
   67: {
   68:         return (1);  /* always initial state */
   69: }
   70: 
   71: size_t
   72: /*ARGSUSED*/
   73: _citrus_none_ctype_mbsrtowcs(wchar_t * __restrict pwcs,
   74:                              const char ** __restrict s, size_t n,
   75:                              void * __restrict pspriv)
   76: {
   77:         int count = 0;
   78: 
   79:         /* pwcs may be NULL */
   80:         /* s may be NULL */
   81:         /* pspriv appears to be unused */
   82: 
   83:         if (!s || !*s)
   84:                 return 0;
   85: 
   86:         if (pwcs == NULL)
   87:                 return strlen(*s);
   88: 
   89:         while (n > 0) {
   90:                 if ((*pwcs++ = (wchar_t)(unsigned char)*(*s)++) == 0)
   91:                         break;
   92:                 count++;
   93:                 n--;
   94:         }
   95:         
   96:         return count;
   97: }
   98: 
   99: size_t
  100: /*ARGSUSED*/
  101: _citrus_none_ctype_wcrtomb(char * __restrict s,
  102:                            wchar_t wc, void * __restrict pspriv)
  103: {
  104:         /* s may be NULL */
  105:         /* ps appears to be unused */
  106: 
  107:         if (s == NULL)
  108:                 return 0;
  109: 
  110:         *s = (char) wc;
  111:         return 1;
  112: }
  113: 
  114: size_t
  115: /*ARGSUSED*/
  116: _citrus_none_ctype_wcsrtombs(char * __restrict s,
  117:                              const wchar_t ** __restrict pwcs, size_t n,
  118:                              void * __restrict pspriv)
  119: {
  120:         int count = 0;
  121: 
  122:         /* s may be NULL */
  123:         /* pwcs may be NULL */
  124:         /* pspriv appears to be unused */
  125: 
  126:         if (pwcs == NULL || *pwcs == NULL)
  127:                 return (0);
  128: 
  129:         if (s == NULL) {
  130:                 while (*(*pwcs)++ != 0)
  131:                         count++;
  132:                 return(count);
  133:         }
  134: 
  135:         if (n != 0) {
  136:                 do {
  137:                         if ((*s++ = (char) *(*pwcs)++) == 0)
  138:                                 break;
  139:                         count++;
  140:                 } while (--n != 0);
  141:         }
  142: 
  143:         return count;
  144: }