2 * Kernel string functions
9 #include "wine/winbase16.h"
12 static INT WINAPI (*pLoadStringA)(HINSTANCE, UINT, LPSTR, INT);
13 static INT WINAPI (*pwvsprintfA)(LPSTR, LPCSTR, va_list);
15 /***********************************************************************
16 * Helper for k32 family functions
18 static void *user32_proc_address(const char *proc_name)
20 static HMODULE hUser32;
22 if(!hUser32) hUser32 = LoadLibraryA("user32.dll");
23 return GetProcAddress(hUser32, proc_name);
27 /***********************************************************************
28 * KERNEL_lstrcmp16 (KERNEL.87)
30 INT16 WINAPI KERNEL_lstrcmp16( LPCSTR str1, LPCSTR str2 )
32 return (INT16)strcmp( str1, str2 );
36 /***********************************************************************
37 * k32CharToOemBuffA (KERNEL32.@)
39 BOOL WINAPI k32CharToOemBuffA(LPCSTR s, LPSTR d, DWORD len)
43 if ((bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
45 MultiByteToWideChar( CP_ACP, 0, s, len, bufW, len );
46 WideCharToMultiByte( CP_OEMCP, 0, bufW, len, d, len, NULL, NULL );
47 HeapFree( GetProcessHeap(), 0, bufW );
53 /***********************************************************************
54 * k32CharToOemA (KERNEL32.@)
56 BOOL WINAPI k32CharToOemA(LPCSTR s, LPSTR d)
58 if (!s || !d) return TRUE;
59 return k32CharToOemBuffA( s, d, strlen(s) + 1 );
63 /***********************************************************************
64 * k32OemToCharBuffA (KERNEL32.@)
66 BOOL WINAPI k32OemToCharBuffA(LPCSTR s, LPSTR d, DWORD len)
70 if ((bufW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
72 MultiByteToWideChar( CP_OEMCP, 0, s, len, bufW, len );
73 WideCharToMultiByte( CP_ACP, 0, bufW, len, d, len, NULL, NULL );
74 HeapFree( GetProcessHeap(), 0, bufW );
80 /***********************************************************************
81 * k32OemToCharA (KERNEL32.@)
83 BOOL WINAPI k32OemToCharA(LPCSTR s, LPSTR d)
85 return k32OemToCharBuffA( s, d, strlen(s) + 1 );
89 /**********************************************************************
90 * k32LoadStringA (KERNEL32.@)
92 INT WINAPI k32LoadStringA(HINSTANCE instance, UINT resource_id,
93 LPSTR buffer, INT buflen)
95 if(!pLoadStringA) pLoadStringA = user32_proc_address("LoadStringA");
96 return pLoadStringA(instance, resource_id, buffer, buflen);
100 /***********************************************************************
101 * k32wvsprintfA (KERNEL32.@)
103 INT WINAPI k32wvsprintfA(LPSTR buffer, LPCSTR spec, va_list args)
105 if(!pwvsprintfA) pwvsprintfA = user32_proc_address("wvsprintfA");
106 return (*pwvsprintfA)(buffer, spec, args);
110 /***********************************************************************
111 * k32wsprintfA (KERNEL32.@)
113 INT WINAPIV k32wsprintfA(LPSTR buffer, LPCSTR spec, ...)
118 va_start(args, spec);
119 res = k32wvsprintfA(buffer, spec, args);
125 /***************************************************************************
127 * Win 2.x string functions now moved to USER
129 * We rather want to implement them here instead of doing Callouts
132 /***********************************************************************
133 * KERNEL_AnsiNext16 (KERNEL.77)
135 SEGPTR WINAPI KERNEL_AnsiNext16(SEGPTR current)
137 return (*(char *)MapSL(current)) ? current + 1 : current;
140 /***********************************************************************
141 * KERNEL_AnsiPrev16(KERNEL.78)
143 SEGPTR WINAPI KERNEL_AnsiPrev16( SEGPTR start, SEGPTR current )
145 return (current==start)?start:current-1;
148 /***********************************************************************
149 * KERNEL_AnsiUpper16 (KERNEL.79)
151 SEGPTR WINAPI KERNEL_AnsiUpper16( SEGPTR strOrChar )
153 /* uppercase only one char if strOrChar < 0x10000 */
154 if (HIWORD(strOrChar))
156 char *s = MapSL(strOrChar);
164 else return toupper((char)strOrChar);
167 /***********************************************************************
168 * KERNEL_AnsiLower16 (KERNEL.80)
170 SEGPTR WINAPI KERNEL_AnsiLower16( SEGPTR strOrChar )
172 /* lowercase only one char if strOrChar < 0x10000 */
173 if (HIWORD(strOrChar))
175 char *s = MapSL(strOrChar);
183 else return tolower((char)strOrChar);