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;
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++;
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++;
}
return(NULL);
}
+
+struct wcspair *newwcspair(wchar_t *key, wchar_t *val, struct wcspair **list)
+{
+ struct wcspair *pair;
+
+ pair = smalloc(sizeof(*pair));
+ memset(pair, 0, sizeof(*pair));
+ if(key != NULL)
+ pair->key = swcsdup(key);
+ if(val != NULL)
+ pair->val = swcsdup(val);
+ if(list == NULL)
+ {
+ pair->next = NULL;
+ } else {
+ pair->next = *list;
+ *list = pair;
+ }
+ return(pair);
+}
+
+void freewcspair(struct wcspair *pair, struct wcspair **list)
+{
+ struct wcspair *cur;
+
+ for(cur = *list; cur != NULL; list = &(cur->next), cur = cur->next)
+ {
+ if(cur == pair)
+ {
+ *list = cur->next;
+ break;
+ }
+ }
+ free(pair->key);
+ free(pair->val);
+ free(pair);
+}
+
+wchar_t *wpfind(struct wcspair *list, wchar_t *key)
+{
+ for(; list != NULL; list = list->next)
+ {
+ if(!wcscmp(list->key, key))
+ return(list->val);
+ }
+ return(NULL);
+}