OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [stdlib/] [mbtowc.c] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1010 ivang
/*
2
FUNCTION
3
<<mbtowc>>---minimal multibyte to wide char converter
4
 
5
INDEX
6
        mbtowc
7
 
8
ANSI_SYNOPSIS
9
        #include <stdlib.h>
10
        int mbtowc(wchar_t *<[pwc]>, const char *<[s]>, size_t <[n]>);
11
 
12
TRAD_SYNOPSIS
13
        #include <stdlib.h>
14
        int mbtowc(<[pwc]>, <[s]>, <[n]>)
15
        wchar_t *<[pwc]>;
16
        const char *<[s]>;
17
        size_t <[n]>;
18
 
19
DESCRIPTION
20
When MB_CAPABLE is not defined, this is a minimal ANSI-conforming
21
implementation of <<mbtowc>>.  In this case,
22
only ``multi-byte character sequences'' recognized are single bytes,
23
and they are ``converted'' to themselves.
24
Each call to <<mbtowc>> copies one character from <<*<[s]>>> to
25
<<*<[pwc]>>>, unless <[s]> is a null pointer.  The argument n
26
is ignored.
27
 
28
When MB_CAPABLE is defined, this routine calls <<_mbtowc_r>> to perform
29
the conversion, passing a state variable to allow state dependent
30
decoding.  The result is based on the locale setting which may
31
be restricted to a defined set of locales.
32
 
33
RETURNS
34
This implementation of <<mbtowc>> returns <<0>> if
35
<[s]> is <<NULL>> or is the empty string;
36
it returns <<1>> if not MB_CAPABLE or
37
the character is a single-byte character; it returns <<-1>>
38
if n is <<0>> or the multi-byte character is invalid;
39
otherwise it returns the number of bytes in the multibyte character.
40
If the return value is -1, no changes are made to the <<pwc>>
41
output string.  If the input is the empty string, a wchar_t nul
42
is placed in the output string and 0 is returned.  If the input
43
has a length of 0, no changes are made to the <<pwc>> output string.
44
 
45
PORTABILITY
46
<<mbtowc>> is required in the ANSI C standard.  However, the precise
47
effects vary with the locale.
48
 
49
<<mbtowc>> requires no supporting OS subroutines.
50
*/
51
 
52
#ifndef _REENT_ONLY
53
 
54
#include <stdlib.h>
55
 
56
int
57
_DEFUN (mbtowc, (pwc, s, n),
58
        wchar_t *pwc _AND
59
        const char *s _AND
60
        size_t n)
61
{
62
#ifdef MB_CAPABLE
63
        static int state;
64
 
65
        return _mbtowc_r (_REENT, pwc, s, n, &state);
66
#else /* not MB_CAPABLE */
67
        if (s == NULL)
68
                return 0;
69
        if (n == 0)
70
                return -1;
71
        if (pwc)
72
                *pwc = (wchar_t) *s;
73
        return (*s != '\0');
74
#endif /* not MB_CAPABLE */
75
}
76
 
77
#endif /* !_REENT_ONLY */
78
 
79
 
80
 
81
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.