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

Subversion Repositories openrisc_me

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

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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