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

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc2/] [newlib/] [libc/] [stdlib/] [wctomb.c] - Blame information for rev 520

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/*
2
FUNCTION
3
<<wctomb>>---minimal wide char to multibyte converter
4
 
5
INDEX
6
        wctomb
7
 
8
ANSI_SYNOPSIS
9
        #include <stdlib.h>
10
        int wctomb(char *<[s]>, wchar_t <[wchar]>);
11
 
12
TRAD_SYNOPSIS
13
        #include <stdlib.h>
14
        int wctomb(<[s]>, <[wchar]>)
15
        char *<[s]>;
16
        wchar_t <[wchar]>;
17
 
18
DESCRIPTION
19
When _MB_CAPABLE is not defined, this is a minimal ANSI-conforming
20
implementation of <<wctomb>>.  The
21
only ``wide characters'' recognized are single bytes,
22
and they are ``converted'' to themselves.
23
 
24
When _MB_CAPABLE is defined, this routine calls <<_wctomb_r>> to perform
25
the conversion, passing a state variable to allow state dependent
26
decoding.  The result is based on the locale setting which may
27
be restricted to a defined set of locales.
28
 
29
Each call to <<wctomb>> modifies <<*<[s]>>> unless <[s]> is a null
30
pointer or _MB_CAPABLE is defined and <[wchar]> is invalid.
31
 
32
RETURNS
33
This implementation of <<wctomb>> returns <<0>> if
34
<[s]> is <<NULL>>; it returns <<-1>> if _MB_CAPABLE is enabled
35
and the wchar is not a valid multi-byte character, it returns <<1>>
36
if _MB_CAPABLE is not defined or the wchar is in reality a single
37
byte character, otherwise it returns the number of bytes in the
38
multi-byte character.
39
 
40
PORTABILITY
41
<<wctomb>> is required in the ANSI C standard.  However, the precise
42
effects vary with the locale.
43
 
44
<<wctomb>> requires no supporting OS subroutines.
45
*/
46
 
47
#ifndef _REENT_ONLY
48
 
49
#include <newlib.h>
50
#include <stdlib.h>
51
#include <errno.h>
52
#include "local.h"
53
 
54
int
55
_DEFUN (wctomb, (s, wchar),
56
        char *s _AND
57
        wchar_t wchar)
58
{
59
#ifdef _MB_CAPABLE
60
        _REENT_CHECK_MISC(_REENT);
61
 
62
        return __wctomb (_REENT, s, wchar, __locale_charset (),
63
                         &(_REENT_WCTOMB_STATE(_REENT)));
64
#else /* not _MB_CAPABLE */
65
        if (s == NULL)
66
                return 0;
67
 
68
        /* Verify that wchar is a valid single-byte character.  */
69
        if ((size_t)wchar >= 0x100) {
70
                errno = EILSEQ;
71
                return -1;
72
        }
73
 
74
        *s = (char) wchar;
75
        return 1;
76
#endif /* not _MB_CAPABLE */
77
}
78
 
79
#endif /* !_REENT_ONLY */

powered by: WebSVN 2.1.0

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