Implemented _read and _lseek.
[wine] / dlls / crtdll / mbstring.c
1 /*
2  * CRTDLL multi-byte string functions
3  *
4  * Copyright 1999 Alexandre Julliard
5  */
6
7 #include "config.h"
8
9 #include <ctype.h>
10 #include <limits.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #ifdef HAVE_WCTYPE_H
14 #include <wctype.h>
15 #endif
16
17 #include "windef.h"
18 #include "crtdll.h"
19
20
21 /*********************************************************************
22  *           CRTDLL__mbsinc    (CRTDLL.205)
23  */
24 LPSTR __cdecl CRTDLL__mbsinc( LPCSTR str )
25 {
26     int len = mblen( str, MB_LEN_MAX );
27     if (len < 1) len = 1;
28     return (LPSTR)(str + len);
29 }
30
31
32 /*********************************************************************
33  *           CRTDLL__mbslen    (CRTDLL.206)
34  */
35 INT __cdecl CRTDLL__mbslen( LPCSTR str )
36 {
37     INT len, total = 0;
38     while ((len = mblen( str, MB_LEN_MAX )) > 0)
39     {
40         str += len;
41         total++;
42     }
43     return total;
44 }
45
46
47 /*********************************************************************
48  *           CRTDLL_mbstowcs    (CRTDLL.429)
49  */
50 INT __cdecl CRTDLL_mbstowcs( LPWSTR dst, LPCSTR src, INT n )
51 {
52     wchar_t *buffer, *p;
53     int ret;
54
55     if (!(buffer = CRTDLL_malloc( n * sizeof(wchar_t) ))) return -1;
56     ret = mbstowcs( buffer, src, n );
57     if (ret < n) n = ret + 1;  /* nb of chars to copy (including terminating null) */
58     p = buffer;
59     while (n-- > 0) *dst++ = (WCHAR)*p++;
60     CRTDLL_free( buffer );
61     return ret;
62 }
63
64
65 /*********************************************************************
66  *           CRTDLL_mbtowc    (CRTDLL.430)
67  */
68 INT __cdecl CRTDLL_mbtowc( WCHAR *dst, LPCSTR str, INT n )
69 {
70     wchar_t res;
71     int ret = mbtowc( &res, str, n );
72     if (dst) *dst = (WCHAR)res;
73     return ret;
74 }