OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

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

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

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

powered by: WebSVN 2.1.0

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