2 * Kernel string functions
4 * Copyright 2001 Dmitry Timoshkov for Codeweavers
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.
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.
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
27 #include "wine/winbase16.h"
30 static INT (WINAPI *pLoadStringA)(HINSTANCE, UINT, LPSTR, INT);
31 static INT (WINAPI *pwvsprintfA)(LPSTR, LPCSTR, va_list);
33 /***********************************************************************
34 * Helper for k32 family functions
36 static void *user32_proc_address(const char *proc_name)
38 static HMODULE hUser32;
40 if(!hUser32) hUser32 = LoadLibraryA("user32.dll");
41 return GetProcAddress(hUser32, proc_name);
45 /***********************************************************************
46 * k32CharToOemBuffA (KERNEL32.11)
48 BOOL WINAPI k32CharToOemBuffA(LPCSTR s, LPSTR d, DWORD len)
52 if ((bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
54 MultiByteToWideChar( CP_ACP, 0, s, len, bufW, len );
55 WideCharToMultiByte( CP_OEMCP, 0, bufW, len, d, len, NULL, NULL );
56 HeapFree( GetProcessHeap(), 0, bufW );
62 /***********************************************************************
63 * k32CharToOemA (KERNEL32.10)
65 BOOL WINAPI k32CharToOemA(LPCSTR s, LPSTR d)
67 if (!s || !d) return TRUE;
68 return k32CharToOemBuffA( s, d, strlen(s) + 1 );
72 /***********************************************************************
73 * k32OemToCharBuffA (KERNEL32.13)
75 BOOL WINAPI k32OemToCharBuffA(LPCSTR s, LPSTR d, DWORD len)
79 if ((bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
81 MultiByteToWideChar( CP_OEMCP, 0, s, len, bufW, len );
82 WideCharToMultiByte( CP_ACP, 0, bufW, len, d, len, NULL, NULL );
83 HeapFree( GetProcessHeap(), 0, bufW );
89 /***********************************************************************
90 * k32OemToCharA (KERNEL32.12)
92 BOOL WINAPI k32OemToCharA(LPCSTR s, LPSTR d)
94 return k32OemToCharBuffA( s, d, strlen(s) + 1 );
98 /**********************************************************************
99 * k32LoadStringA (KERNEL32.14)
101 INT WINAPI k32LoadStringA(HINSTANCE instance, UINT resource_id,
102 LPSTR buffer, INT buflen)
104 if(!pLoadStringA) pLoadStringA = user32_proc_address("LoadStringA");
105 return pLoadStringA(instance, resource_id, buffer, buflen);
109 /***********************************************************************
110 * k32wvsprintfA (KERNEL32.16)
112 INT WINAPI k32wvsprintfA(LPSTR buffer, LPCSTR spec, va_list args)
114 if(!pwvsprintfA) pwvsprintfA = user32_proc_address("wvsprintfA");
115 return (*pwvsprintfA)(buffer, spec, args);
119 /***********************************************************************
120 * k32wsprintfA (KERNEL32.15)
122 INT WINAPIV k32wsprintfA(LPSTR buffer, LPCSTR spec, ...)
127 va_start(args, spec);
128 res = k32wvsprintfA(buffer, spec, args);
134 /***************************************************************************
136 * Win 2.x string functions now moved to USER
138 * We rather want to implement them here instead of doing Callouts
141 /***********************************************************************
142 * Reserved1 (KERNEL.77)
144 SEGPTR WINAPI KERNEL_AnsiNext16(SEGPTR current)
146 return (*(char *)MapSL(current)) ? current + 1 : current;
149 /***********************************************************************
150 * Reserved2(KERNEL.78)
152 SEGPTR WINAPI KERNEL_AnsiPrev16( SEGPTR start, SEGPTR current )
154 return (current==start)?start:current-1;
157 /***********************************************************************
158 * Reserved3 (KERNEL.79)
160 SEGPTR WINAPI KERNEL_AnsiUpper16( SEGPTR strOrChar )
162 /* uppercase only one char if strOrChar < 0x10000 */
163 if (HIWORD(strOrChar))
165 char *s = MapSL(strOrChar);
173 else return toupper((char)strOrChar);
176 /***********************************************************************
177 * Reserved4 (KERNEL.80)
179 SEGPTR WINAPI KERNEL_AnsiLower16( SEGPTR strOrChar )
181 /* lowercase only one char if strOrChar < 0x10000 */
182 if (HIWORD(strOrChar))
184 char *s = MapSL(strOrChar);
192 else return tolower((char)strOrChar);
196 /***********************************************************************
197 * Reserved5 (KERNEL.87)
199 INT16 WINAPI KERNEL_lstrcmp16( LPCSTR str1, LPCSTR str2 )
201 return (INT16)strcmp( str1, str2 );