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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib-1.10.0/] [newlib/] [libc/] [stdlib/] [mblen.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
<<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
#ifndef _REENT_ONLY
45
 
46
#include <stdlib.h>
47
 
48
int
49
_DEFUN (mblen, (s, n),
50
        const char *s _AND
51
        size_t n)
52
{
53
#ifdef MB_CAPABLE
54
        static int state;
55
 
56
        return _mbtowc_r (_REENT, NULL, s, n, &state);
57
#else /* not MB_CAPABLE */
58
        if (s == NULL || *s == '\0')
59
                return 0;
60
        if (n == 0)
61
                return -1;
62
        return 1;
63
#endif /* not MB_CAPABLE */
64
}
65
 
66
#endif /* !_REENT_ONLY */

powered by: WebSVN 2.1.0

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