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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [stdlib/] [wcstombs.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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