File: mbstowcs.c

package info (click to toggle)
dictd 1.13.1%2Bdfsg-1.1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,940 kB
  • sloc: ansic: 12,523; sh: 4,435; yacc: 512; makefile: 442; cpp: 277; lex: 256; perl: 175; awk: 12
file content (50 lines) | stat: -rw-r--r-- 844 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
  partial mbstowcs implementation:
  - doesn't change *ps
  - ignores n
  - dest should always be NULL
  - src should NOT be NULL
*/

#include "dictP.h"

#include <wchar.h>
#include <assert.h>

size_t mbstowcs__ (wchar_t *dest, const char *src, size_t n)
{
   int ret = 0;
   int len = 0;
   int c;

   assert (src);   /* not implemented */
   assert (!dest); /* not implemented */

   while (*src){
      c = *(const unsigned char *)src;

      if (c <= 0x7F)
	 len = 1;
      else if (MB_CUR_MAX__ == 1)
	 len = 1;
      else if (c <= 0xBF)
	 return (size_t) -1;
      else if (c <= 0xDF)
	 len = 2;
      else if (c <= 0xEF)
	 len = 3;
      else if (c <= 0xF7)
	 len = 4;
      else if (c <= 0xFB)
	 len = 5;
      else if (c <= 0xFD)
	 len = 6;
      else
	 return (size_t) -1;

      ret += 1;
      src += len;
   }

   return ret;
}