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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [stdlib/] [mbstowcs.c] - Blame information for rev 1774

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

Line No. Rev Author Line
1 39 lampret
/*
2
FUNCTION
3
<<mbstowcs>>---minimal multibyte string to wide char converter
4
 
5
INDEX
6
        mbstowcs
7
 
8
ANSI_SYNOPSIS
9
        #include <stdlib.h>
10
        int mbstowcs(wchar_t *<[pwc]>, const char *<[s]>, size_t <[n]>);
11
 
12
TRAD_SYNOPSIS
13
        #include <stdlib.h>
14
        int mbstowcs(<[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 <<mbstowcs>>.  In this case, the
22
only ``multi-byte character sequences'' recognized are single bytes,
23
and they are ``converted'' to wide-char versions simply by byte
24
extension.
25
 
26
When MB_CAPABLE is defined, this routine calls <<_mbstowcs_r>> to perform
27
the conversion, passing a state variable to allow state dependent
28
decoding.  The result is based on the locale setting which may
29
be restricted to a defined set of locales.
30
 
31
RETURNS
32
This implementation of <<mbstowcs>> returns <<0>> if
33
<[s]> is <<NULL>> or is the empty string;
34
it returns <<-1>> if MB_CAPABLE and one of the
35
multi-byte characters is invalid or incomplete;
36
otherwise it returns the minimum of: <<n>> or the
37
number of multi-byte characters in <<s>> plus 1 (to
38
compensate for the nul character).
39
If the return value is -1, the state of the <<pwc>> string is
40
indeterminate.  If the input has a length of 0, the output
41
string will be modified to contain a wchar_t nul terminator.
42
 
43
PORTABILITY
44
<<mbstowcs>> is required in the ANSI C standard.  However, the precise
45
effects vary with the locale.
46
 
47
<<mbstowcs>> requires no supporting OS subroutines.
48
*/
49
 
50
#include <stdlib.h>
51
 
52
size_t
53
_DEFUN (mbstowcs, (pwcs, s, n),
54
        wchar_t *pwcs _AND
55
        const char *s _AND
56
        size_t n)
57
{
58
#ifdef MB_CAPABLE
59
        int state = 0;
60
 
61
        return _mbstowcs_r (_REENT, pwcs, s, n, &state);
62
#else /* not MB_CAPABLE */
63
 
64
        int count = 0;
65
 
66
        if (n != 0) {
67
                do {
68
                        if ((*pwcs++ = (wchar_t) *s++) == 0)
69
                                break;
70
                        count++;
71
                } while (--n != 0);
72
        }
73
 
74
        return count;
75
#endif /* not MB_CAPABLE */
76
}

powered by: WebSVN 2.1.0

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