os2, geniconv: default functions pointers to Uni*() API,

In case they get accessed before SDL_Init() was called.
This commit is contained in:
Ozkan Sezer 2022-01-21 11:50:40 +03:00
parent 67cb548bef
commit d2456b6e4c
1 changed files with 17 additions and 12 deletions

View File

@ -46,17 +46,17 @@ extern size_t _System os2_iconv (iconv_t cd,
char **outbuf, size_t *outbytesleft);
extern int _System os2_iconv_close (iconv_t cd);
/* Functions pointers types */
/* Functions pointers */
typedef iconv_t (_System *FNICONV_OPEN)(const char*, const char*);
typedef size_t (_System *FNICONV) (iconv_t, char **, size_t *, char **, size_t *);
typedef int (_System *FNICONV_CLOSE)(iconv_t);
/* Used DLL module handle */
static HMODULE hmIconv = NULLHANDLE;
/* Functions pointers */
static FNICONV_OPEN fn_iconv_open = NULL;
static FNICONV fn_iconv = NULL;
static FNICONV_CLOSE fn_iconv_close = NULL;
static FNICONV_OPEN fn_iconv_open = os2_iconv_open;
static FNICONV fn_iconv = os2_iconv;
static FNICONV_CLOSE fn_iconv_close = os2_iconv_close;
static int geniconv_init = 0;
static BOOL _loadDLL(const char *dllname,
@ -102,10 +102,12 @@ static BOOL _loadDLL(const char *dllname,
static void _init(void)
{
if (fn_iconv_open != NULL) {
if (geniconv_init) {
return; /* Already initialized */
}
geniconv_init = 1;
/* Try to load kiconv.dll, iconv2.dll or iconv.dll */
if (!_loadDLL("KICONV", "_libiconv_open", "_libiconv", "_libiconv_close") &&
!_loadDLL("ICONV2", "_libiconv_open", "_libiconv", "_libiconv_close") &&
@ -123,16 +125,19 @@ static void _init(void)
* ----------------
*/
/* Non-standard function for iconv to unload the used dynamic library */
/* function to unload the used iconv dynamic library */
void libiconv_clean(void)
{
geniconv_init = 0;
/* reset the function pointers. */
fn_iconv_open = os2_iconv_open;
fn_iconv = os2_iconv;
fn_iconv_close = os2_iconv_close;
if (hmIconv != NULLHANDLE) {
DosFreeModule(hmIconv);
hmIconv = NULLHANDLE;
fn_iconv_open = NULL;
fn_iconv = NULL;
fn_iconv_close = NULL;
}
}