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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [stdlib/] [mblen.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
<<mblen>>---minimal multibyte length function
4
 
5
INDEX
6
        mblen
7
 
8
ANSI_SYNOPSIS
9
        #include <stdlib.h>
10
        int mblen(const char *<[s]>, size_t <[n]>);
11
 
12
TRAD_SYNOPSIS
13
        #include <stdlib.h>
14
        int mblen(<[s]>, <[n]>)
15
        const char *<[s]>;
16
        size_t <[n]>;
17
 
18
DESCRIPTION
19
When MB_CAPABLE is not defined, this is a minimal ANSI-conforming
20
implementation of <<mblen>>.  In this case, the
21
only ``multi-byte character sequences'' recognized are single bytes,
22
and thus <<1>> is returned unless <[s]> is the null pointer or
23
has a length of 0 or is the empty string.
24
 
25
When MB_CAPABLE is defined, this routine calls <<_mbtowc_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 <<mblen>> returns <<0>> if
32
<[s]> is <<NULL>> or the empty string; it returns <<1>> if not MB_CAPABLE or
33
the character is a single-byte character; it returns <<-1>>
34
if the multi-byte character is invalid; otherwise it returns
35
the number of bytes in the multibyte character.
36
 
37
PORTABILITY
38
<<mblen>> is required in the ANSI C standard.  However, the precise
39
effects vary with the locale.
40
 
41
<<mblen>> requires no supporting OS subroutines.
42
*/
43
 
44
#include <stdlib.h>
45
 
46
int
47
_DEFUN (mblen, (s, n),
48
        const char *s _AND
49
        size_t n)
50
{
51
#ifdef MB_CAPABLE
52
        static int state;
53
 
54
        return _mbtowc_r (_REENT, NULL, s, n, &state);
55
#else /* not MB_CAPABLE */
56
        if (s == NULL || *s == '\0')
57
                return 0;
58
        if (n == 0)
59
                return -1;
60
        return 1;
61
#endif /* not MB_CAPABLE */
62
}
63
 

powered by: WebSVN 2.1.0

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