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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 56 joel
/*
2
FUNCTION
3
<<_mblen_r>>---reentrant minimal multibyte length function
4
 
5
INDEX
6
        _mblen_r
7
 
8
ANSI_SYNOPSIS
9
        #include <stdlib.h>
10
        int _mblen_r(struct _reent *<[r]>, const char *<[s]>, size_t <[n]>, int *<[state]>);
11
 
12
TRAD_SYNOPSIS
13
        #include <stdlib.h>
14
        int _mblen_r(<[r]>, <[s]>, <[n]>, <[state]>)
15
        struct _reent *<[r]>;
16
        const char *<[s]>;
17
        size_t <[n]>;
18
        int *<[state]>;
19
 
20
DESCRIPTION
21
When MB_CAPABLE is not defined, this is a minimal ANSI-conforming
22
implementation of <<_mblen_r>>.  In this case, the
23
only ``multi-byte character sequences'' recognized are single bytes,
24
and thus <<1>> is returned unless <[s]> is the null pointer or
25
has a length of 0 or is the empty string.
26
 
27
When MB_CAPABLE is defined, this routine calls <<_mbtowc_r>> to perform
28
the conversion, passing a state variable to allow state dependent
29
decoding.  The result is based on the locale setting which may
30
be restricted to a defined set of locales.
31
 
32
RETURNS
33
This implementation of <<_mblen_r>> returns <<0>> if
34
<[s]> is <<NULL>> or the empty string; it returns <<1>> if not MB_CAPABLE or
35
the character is a single-byte character; it returns <<-1>>
36
if the multi-byte character is invalid; otherwise it returns
37
the number of bytes in the multibyte character.
38
 
39
PORTABILITY
40
<<_mblen>> is required in the ANSI C standard.  However, the precise
41
effects vary with the locale.
42
 
43
<<_mblen_r>> requires no supporting OS subroutines.
44
*/
45
 
46
#include <stdlib.h>
47
 
48
int
49
_DEFUN (_mblen_r, (r, s, n, state),
50
        struct _reent *r    _AND
51
        const char *s _AND
52
        size_t n _AND
53
        int *state)
54
{
55
#ifdef MB_CAPABLE
56
 
57
        return _mbtowc_r (r, NULL, s, n, state);
58
#else /* not MB_CAPABLE */
59
        if (s == NULL || *s == '\0')
60
                return 0;
61
        if (n == 0)
62
                return -1;
63
        return 1;
64
#endif /* not MB_CAPABLE */
65
}
66
 

powered by: WebSVN 2.1.0

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