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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [stdlib/] [wcstombs.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
<<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
#ifndef _REENT_ONLY
52
 
53
#include <stdlib.h>
54
 
55
size_t
56
_DEFUN (wcstombs, (s, pwcs, n),
57
        char          *s    _AND
58
        const wchar_t *pwcs _AND
59
        size_t         n)
60
{
61
#ifdef MB_CAPABLE
62
        int state = 0;
63
 
64
        return _wcstombs_r (_REENT, s, pwcs, n, &state);
65
#else /* not MB_CAPABLE */
66
        int count = 0;
67
 
68
        if (n != 0) {
69
                do {
70
                        if ((*s++ = (char) *pwcs++) == 0)
71
                                break;
72
                        count++;
73
                } while (--n != 0);
74
        }
75
 
76
        return count;
77
#endif /* not MB_CAPABLE */
78
}
79
 
80
#endif /* !_REENT_ONLY */

powered by: WebSVN 2.1.0

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