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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [stdlib/] [mblen_r.c] - Blame information for rev 158

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/*
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 <newlib.h>
47
#include <stdlib.h>
48
#include <wchar.h>
49
 
50
int
51
_DEFUN (_mblen_r, (r, s, n, state),
52
        struct _reent *r    _AND
53
        const char *s _AND
54
        size_t n _AND
55
        mbstate_t *state)
56
{
57
#ifdef _MB_CAPABLE
58
  int retval;
59
  retval = _mbtowc_r (r, NULL, s, n, state);
60
 
61
  if (retval < 0)
62
    {
63
      state->__count = 0;
64
      return -1;
65
    }
66
 
67
  return retval;
68
#else /* not _MB_CAPABLE */
69
  if (s == NULL || *s == '\0')
70
    return 0;
71
  if (n == 0)
72
    return -1;
73
  return 1;
74
#endif /* not _MB_CAPABLE */
75
}
76
 

powered by: WebSVN 2.1.0

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