Subversion Repositories Kolibri OS

Rev

Rev 4874 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4874 Rev 4921
1
/*
1
/*
2
FUNCTION
2
FUNCTION
3
<>---minimal multibyte to wide char converter
3
<>---minimal multibyte to wide char converter
4
 
4
 
5
INDEX
5
INDEX
6
	mbtowc
6
	mbtowc
7
 
7
 
8
ANSI_SYNOPSIS
8
ANSI_SYNOPSIS
9
	#include 
9
	#include 
10
	int mbtowc(wchar_t *<[pwc]>, const char *<[s]>, size_t <[n]>);
10
	int mbtowc(wchar_t *restrict <[pwc]>, const char *restrict <[s]>, size_t <[n]>);
11
 
11
 
12
TRAD_SYNOPSIS
12
TRAD_SYNOPSIS
13
	#include 
13
	#include 
14
	int mbtowc(<[pwc]>, <[s]>, <[n]>)
14
	int mbtowc(<[pwc]>, <[s]>, <[n]>)
15
	wchar_t *<[pwc]>;
15
	wchar_t *<[pwc]>;
16
	const char *<[s]>;
16
	const char *<[s]>;
17
	size_t <[n]>;
17
	size_t <[n]>;
18
 
18
 
19
DESCRIPTION
19
DESCRIPTION
20
When _MB_CAPABLE is not defined, this is a minimal ANSI-conforming 
20
When _MB_CAPABLE is not defined, this is a minimal ANSI-conforming 
21
implementation of <>.  In this case,
21
implementation of <>.  In this case,
22
only ``multi-byte character sequences'' recognized are single bytes,
22
only ``multi-byte character sequences'' recognized are single bytes,
23
and they are ``converted'' to themselves.
23
and they are ``converted'' to themselves.
24
Each call to <> copies one character from <<*<[s]>>> to
24
Each call to <> copies one character from <<*<[s]>>> to
25
<<*<[pwc]>>>, unless <[s]> is a null pointer.  The argument n
25
<<*<[pwc]>>>, unless <[s]> is a null pointer.  The argument n
26
is ignored.
26
is ignored.
27
 
27
 
28
When _MB_CAPABLE is defined, this routine calls <<_mbtowc_r>> to perform
28
When _MB_CAPABLE is defined, this routine calls <<_mbtowc_r>> to perform
29
the conversion, passing a state variable to allow state dependent
29
the conversion, passing a state variable to allow state dependent
30
decoding.  The result is based on the locale setting which may
30
decoding.  The result is based on the locale setting which may
31
be restricted to a defined set of locales.
31
be restricted to a defined set of locales.
32
 
32
 
33
RETURNS
33
RETURNS
34
This implementation of <> returns <<0>> if
34
This implementation of <> returns <<0>> if
35
<[s]> is <> or is the empty string; 
35
<[s]> is <> or is the empty string; 
36
it returns <<1>> if not _MB_CAPABLE or
36
it returns <<1>> if not _MB_CAPABLE or
37
the character is a single-byte character; it returns <<-1>>
37
the character is a single-byte character; it returns <<-1>>
38
if n is <<0>> or the multi-byte character is invalid; 
38
if n is <<0>> or the multi-byte character is invalid; 
39
otherwise it returns the number of bytes in the multibyte character.
39
otherwise it returns the number of bytes in the multibyte character.
40
If the return value is -1, no changes are made to the <>
40
If the return value is -1, no changes are made to the <>
41
output string.  If the input is the empty string, a wchar_t nul
41
output string.  If the input is the empty string, a wchar_t nul
42
is placed in the output string and 0 is returned.  If the input
42
is placed in the output string and 0 is returned.  If the input
43
has a length of 0, no changes are made to the <> output string.
43
has a length of 0, no changes are made to the <> output string.
44
 
44
 
45
PORTABILITY
45
PORTABILITY
46
<> is required in the ANSI C standard.  However, the precise
46
<> is required in the ANSI C standard.  However, the precise
47
effects vary with the locale.
47
effects vary with the locale.
48
 
48
 
49
<> requires no supporting OS subroutines.
49
<> requires no supporting OS subroutines.
50
*/
50
*/
51
 
51
 
52
#ifndef _REENT_ONLY
52
#ifndef _REENT_ONLY
53
 
53
 
54
#include 
54
#include 
55
#include 
55
#include 
56
#include 
56
#include 
57
#include "local.h"
57
#include "local.h"
58
 
58
 
59
int
59
int
60
_DEFUN (mbtowc, (pwc, s, n),
60
_DEFUN (mbtowc, (pwc, s, n),
61
        wchar_t *pwc _AND
61
        wchar_t *__restrict pwc _AND
62
        const char *s _AND
62
        const char *__restrict s _AND
63
        size_t n)
63
        size_t n)
64
{
64
{
65
#ifdef _MB_CAPABLE
65
#ifdef _MB_CAPABLE
66
  int retval = 0;
66
  int retval = 0;
-
 
67
  struct _reent *reent = _REENT;
67
  mbstate_t *ps;
68
  mbstate_t *ps;
68
 
69
 
69
  _REENT_CHECK_MISC(_REENT);
70
  _REENT_CHECK_MISC(reent);
70
  ps = &(_REENT_MBTOWC_STATE(_REENT));
71
  ps = &(_REENT_MBTOWC_STATE(reent));
71
  
72
  
72
  retval = __mbtowc (_REENT, pwc, s, n, __locale_charset (), ps);
73
  retval = __mbtowc (reent, pwc, s, n, __locale_charset (), ps);
73
  
74
  
74
  if (retval < 0)
75
  if (retval < 0)
75
    {
76
    {
76
      ps->__count = 0;
77
      ps->__count = 0;
77
      return -1;
78
      return -1;
78
    }
79
    }
79
  return retval;
80
  return retval;
80
#else /* not _MB_CAPABLE */
81
#else /* not _MB_CAPABLE */
81
  if (s == NULL)
82
  if (s == NULL)
82
    return 0;
83
    return 0;
83
  if (n == 0)
84
  if (n == 0)
84
    return -1;
85
    return -1;
85
  if (pwc)
86
  if (pwc)
86
    *pwc = (wchar_t) *s;
87
    *pwc = (wchar_t) *s;
87
  return (*s != '\0');
88
  return (*s != '\0');
88
#endif /* not _MB_CAPABLE */
89
#endif /* not _MB_CAPABLE */
89
}
90
}
90
 
91
 
91
#endif /* !_REENT_ONLY */
92
#endif /* !_REENT_ONLY */