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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [stdlib/] [mblen.c] - Blame information for rev 816

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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