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
25 #include "wine/winbase16.h"
28 static INT (WINAPI
*pLoadStringA
)(HINSTANCE
, UINT
, LPSTR
, INT
);
29 static INT (WINAPI
*pwvsprintfA
)(LPSTR
, LPCSTR
, va_list);
31 /***********************************************************************
32 * Helper for k32 family functions
34 static void *user32_proc_address(const char *proc_name
)
36 static HMODULE hUser32
;
38 if(!hUser32
) hUser32
= LoadLibraryA("user32.dll");
39 return GetProcAddress(hUser32
, proc_name
);
43 /***********************************************************************
44 * k32CharToOemBuffA (KERNEL32.11)
46 BOOL WINAPI
k32CharToOemBuffA(LPCSTR s
, LPSTR d
, DWORD len
)
50 if ((bufW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
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
);
60 /***********************************************************************
61 * k32CharToOemA (KERNEL32.10)
63 BOOL WINAPI
k32CharToOemA(LPCSTR s
, LPSTR d
)
65 if (!s
|| !d
) return TRUE
;
66 return k32CharToOemBuffA( s
, d
, strlen(s
) + 1 );
70 /***********************************************************************
71 * k32OemToCharBuffA (KERNEL32.13)
73 BOOL WINAPI
k32OemToCharBuffA(LPCSTR s
, LPSTR d
, DWORD len
)
77 if ((bufW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
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
);
87 /***********************************************************************
88 * k32OemToCharA (KERNEL32.12)
90 BOOL WINAPI
k32OemToCharA(LPCSTR s
, LPSTR d
)
92 return k32OemToCharBuffA( s
, d
, strlen(s
) + 1 );
96 /**********************************************************************
97 * k32LoadStringA (KERNEL32.14)
99 INT WINAPI
k32LoadStringA(HINSTANCE instance
, UINT resource_id
,
100 LPSTR buffer
, INT buflen
)
102 if(!pLoadStringA
) pLoadStringA
= user32_proc_address("LoadStringA");
103 return pLoadStringA(instance
, resource_id
, buffer
, buflen
);
107 /***********************************************************************
108 * k32wvsprintfA (KERNEL32.16)
110 INT WINAPI
k32wvsprintfA(LPSTR buffer
, LPCSTR spec
, va_list args
)
112 if(!pwvsprintfA
) pwvsprintfA
= user32_proc_address("wvsprintfA");
113 return (*pwvsprintfA
)(buffer
, spec
, args
);
117 /***********************************************************************
118 * k32wsprintfA (KERNEL32.15)
120 INT WINAPIV
k32wsprintfA(LPSTR buffer
, LPCSTR spec
, ...)
125 va_start(args
, spec
);
126 res
= k32wvsprintfA(buffer
, spec
, args
);
132 /***************************************************************************
134 * Win 2.x string functions now moved to USER
136 * We rather want to implement them here instead of doing Callouts
139 /***********************************************************************
140 * Reserved1 (KERNEL.77)
142 SEGPTR WINAPI
KERNEL_AnsiNext16(SEGPTR current
)
144 return (*(char *)MapSL(current
)) ? current
+ 1 : current
;
147 /***********************************************************************
148 * Reserved2(KERNEL.78)
150 SEGPTR WINAPI
KERNEL_AnsiPrev16( SEGPTR start
, SEGPTR current
)
152 return (current
==start
)?start
:current
-1;
155 /***********************************************************************
156 * Reserved3 (KERNEL.79)
158 SEGPTR WINAPI
KERNEL_AnsiUpper16( SEGPTR strOrChar
)
160 /* uppercase only one char if strOrChar < 0x10000 */
161 if (HIWORD(strOrChar
))
163 char *s
= MapSL(strOrChar
);
171 else return toupper((char)strOrChar
);
174 /***********************************************************************
175 * Reserved4 (KERNEL.80)
177 SEGPTR WINAPI
KERNEL_AnsiLower16( SEGPTR strOrChar
)
179 /* lowercase only one char if strOrChar < 0x10000 */
180 if (HIWORD(strOrChar
))
182 char *s
= MapSL(strOrChar
);
190 else return tolower((char)strOrChar
);
194 /***********************************************************************
195 * Reserved5 (KERNEL.87)
197 INT16 WINAPI
KERNEL_lstrcmp16( LPCSTR str1
, LPCSTR str2
)
199 return (INT16
)strcmp( str1
, str2
);