Add an empty hook function for WSASetBlockingHook to return.
[wine] / dlls / kernel / string.c
1 /*
2  * Kernel string functions
3  *
4  * Copyright 2001 Dmitry Timoshkov for Codeweavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <ctype.h>
22 #include <string.h>
23
24 #include "winbase.h"
25 #include "wine/winbase16.h"
26
27
28 static INT (WINAPI *pLoadStringA)(HINSTANCE, UINT, LPSTR, INT);
29 static INT (WINAPI *pwvsprintfA)(LPSTR, LPCSTR, va_list);
30
31 /***********************************************************************
32  * Helper for k32 family functions
33  */
34 static void *user32_proc_address(const char *proc_name)
35 {
36     static HMODULE hUser32;
37
38     if(!hUser32) hUser32 = LoadLibraryA("user32.dll");
39     return GetProcAddress(hUser32, proc_name);
40 }
41
42
43 /***********************************************************************
44  *              k32CharToOemBuffA   (KERNEL32.11)
45  */
46 BOOL WINAPI k32CharToOemBuffA(LPCSTR s, LPSTR d, DWORD len)
47 {
48     WCHAR *bufW;
49
50     if ((bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
51     {
52         MultiByteToWideChar( CP_ACP, 0, s, len, bufW, len );
53         WideCharToMultiByte( CP_OEMCP, 0, bufW, len, d, len, NULL, NULL );
54         HeapFree( GetProcessHeap(), 0, bufW );
55     }
56     return TRUE;
57 }
58
59
60 /***********************************************************************
61  *              k32CharToOemA   (KERNEL32.10)
62  */
63 BOOL WINAPI k32CharToOemA(LPCSTR s, LPSTR d)
64 {
65     if (!s || !d) return TRUE;
66     return k32CharToOemBuffA( s, d, strlen(s) + 1 );
67 }
68
69
70 /***********************************************************************
71  *              k32OemToCharBuffA   (KERNEL32.13)
72  */
73 BOOL WINAPI k32OemToCharBuffA(LPCSTR s, LPSTR d, DWORD len)
74 {
75     WCHAR *bufW;
76
77     if ((bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
78     {
79         MultiByteToWideChar( CP_OEMCP, 0, s, len, bufW, len );
80         WideCharToMultiByte( CP_ACP, 0, bufW, len, d, len, NULL, NULL );
81         HeapFree( GetProcessHeap(), 0, bufW );
82     }
83     return TRUE;
84 }
85
86
87 /***********************************************************************
88  *              k32OemToCharA   (KERNEL32.12)
89  */
90 BOOL WINAPI k32OemToCharA(LPCSTR s, LPSTR d)
91 {
92     return k32OemToCharBuffA( s, d, strlen(s) + 1 );
93 }
94
95
96 /**********************************************************************
97  *              k32LoadStringA   (KERNEL32.14)
98  */
99 INT WINAPI k32LoadStringA(HINSTANCE instance, UINT resource_id,
100                           LPSTR buffer, INT buflen)
101 {
102     if(!pLoadStringA) pLoadStringA = user32_proc_address("LoadStringA");
103     return pLoadStringA(instance, resource_id, buffer, buflen);
104 }
105
106
107 /***********************************************************************
108  *              k32wvsprintfA   (KERNEL32.16)
109  */
110 INT WINAPI k32wvsprintfA(LPSTR buffer, LPCSTR spec, va_list args)
111 {
112     if(!pwvsprintfA) pwvsprintfA = user32_proc_address("wvsprintfA");
113     return (*pwvsprintfA)(buffer, spec, args);
114 }
115
116
117 /***********************************************************************
118  *              k32wsprintfA   (KERNEL32.15)
119  */
120 INT WINAPIV k32wsprintfA(LPSTR buffer, LPCSTR spec, ...)
121 {
122     va_list args;
123     INT res;
124
125     va_start(args, spec);
126     res = k32wvsprintfA(buffer, spec, args);
127     va_end(args);
128     return res;
129 }
130
131
132 /***************************************************************************
133  *
134  * Win 2.x string functions now moved to USER
135  *
136  * We rather want to implement them here instead of doing Callouts
137  */
138
139 /***********************************************************************
140  *              Reserved1 (KERNEL.77)
141  */
142 SEGPTR WINAPI KERNEL_AnsiNext16(SEGPTR current)
143 {
144     return (*(char *)MapSL(current)) ? current + 1 : current;
145 }
146
147 /***********************************************************************
148  *              Reserved2(KERNEL.78)
149  */
150 SEGPTR WINAPI KERNEL_AnsiPrev16( SEGPTR start, SEGPTR current )
151 {
152     return (current==start)?start:current-1;
153 }
154
155 /***********************************************************************
156  *              Reserved3 (KERNEL.79)
157  */
158 SEGPTR WINAPI KERNEL_AnsiUpper16( SEGPTR strOrChar )
159 {
160     /* uppercase only one char if strOrChar < 0x10000 */
161     if (HIWORD(strOrChar))
162     {
163         char *s = MapSL(strOrChar);
164         while (*s)
165         {
166             *s = toupper(*s);
167             s++;
168         }
169         return strOrChar;
170     }
171     else return toupper((char)strOrChar);
172 }
173
174 /***********************************************************************
175  *              Reserved4 (KERNEL.80)
176  */
177 SEGPTR WINAPI KERNEL_AnsiLower16( SEGPTR strOrChar )
178 {
179     /* lowercase only one char if strOrChar < 0x10000 */
180     if (HIWORD(strOrChar))
181     {
182         char *s = MapSL(strOrChar);
183         while (*s)
184         {
185             *s = tolower(*s);
186             s++;
187         }
188         return strOrChar;
189     }
190     else return tolower((char)strOrChar);
191 }
192
193
194 /***********************************************************************
195  *              Reserved5 (KERNEL.87)
196  */
197 INT16 WINAPI KERNEL_lstrcmp16( LPCSTR str1, LPCSTR str2 )
198 {
199     return (INT16)strcmp( str1, str2 );
200 }