X-Git-Url: http://git.dolda2000.com/gitweb/?a=blobdiff_plain;f=daemon%2Futils.c;h=38e3ac95ec9830d64f62b611d45780dc79dc449c;hb=c7185019854aa79630ff944e191f59582c675d8b;hp=8f66370a0529e6cfa9e242418202d0bb4779efe7;hpb=a2761258409c929d70fc23735dc7c1c47fe296c4;p=doldaconnect.git diff --git a/daemon/utils.c b/daemon/utils.c index 8f66370..38e3ac9 100644 --- a/daemon/utils.c +++ b/daemon/utils.c @@ -126,6 +126,19 @@ wchar_t *swprintf2(wchar_t *format, ...) return(buf); } +int havecharset(char *charset) +{ + iconv_t cd; + + if((cd = iconv_open("wchar_t", charset)) == (iconv_t)-1) + return(0); + iconv_close(cd); + if((cd = iconv_open(charset, "wchar_t")) == (iconv_t)-1) + return(0); + iconv_close(cd); + return(1); +} + wchar_t *icmbstowcs(char *mbs, char *charset) { int ret; @@ -190,7 +203,7 @@ wchar_t *icsmbstowcs(char *mbs, char *charset, wchar_t *def) free(buf); if((buf = icmbstowcs(mbs, charset)) == NULL) { - if(*def == '~') + if((def != NULL) && (*def == L'~')) { flog(LOG_WARNING, "icsmbstowcs: could not convert wcs string into charset %s: %s", charset, strerror(errno)); def++; @@ -264,7 +277,7 @@ char *icswcstombs(wchar_t *wcs, char *charset, char *def) free(buf); if((buf = icwcstombs(wcs, charset)) == NULL) { - if(*def == '~') + if((def != NULL) && (*def == '~')) { flog(LOG_WARNING, "icswcstombs: could not convert mbs string from charset %s: %s", charset, strerror(errno)); def++; @@ -768,10 +781,15 @@ struct wcspair *newwcspair(wchar_t *key, wchar_t *val, struct wcspair **list) void freewcspair(struct wcspair *pair, struct wcspair **list) { - if(list != NULL) + struct wcspair *cur; + + for(cur = *list; cur != NULL; list = &(cur->next), cur = cur->next) { - if(*list == pair) - *list = pair->next; + if(cur == pair) + { + *list = cur->next; + break; + } } free(pair->key); free(pair->val);