Lines 19-24
Link Here
|
19 |
/* Ick. Its for die() */ |
19 |
/* Ick. Its for die() */ |
20 |
#include "utility.h" |
20 |
#include "utility.h" |
21 |
#include "sysutil.h" |
21 |
#include "sysutil.h" |
|
|
22 |
#include "stdio.h" |
23 |
#include "errno.h" |
24 |
#include "tunables.h" |
25 |
|
26 |
/* For iconv read and write */ |
27 |
#define ICONV_READ 0 |
28 |
#define ICONV_WRITE 1 |
22 |
|
29 |
|
23 |
/* File local functions */ |
30 |
/* File local functions */ |
24 |
static void str_split_text_common(struct mystr* p_src, struct mystr* p_rhs, |
31 |
static void str_split_text_common(struct mystr* p_src, struct mystr* p_rhs, |
Lines 666-668
Link Here
|
666 |
} |
673 |
} |
667 |
} |
674 |
} |
668 |
|
675 |
|
|
|
676 |
void |
677 |
str_iconv_inout(struct mystr* p_str, char io_direction) |
678 |
{ |
679 |
iconv_t cd; |
680 |
char *from_buf; |
681 |
char *dyn_from_buf, *to_buf, *dyn_to_buf; |
682 |
size_t from_len; |
683 |
size_t dyn_from_len, to_len, dyn_to_len; |
684 |
size_t print_buf; |
685 |
|
686 |
from_buf = str_getbuf(p_str); |
687 |
from_len = str_getlen(p_str); |
688 |
|
689 |
p_str->p_buf = 0; |
690 |
str_free(p_str); |
691 |
|
692 |
private_str_alloc_memchunk(p_str, from_buf, from_len); |
693 |
str_reserve(p_str, 2*from_len); |
694 |
p_str->len=2*from_len; |
695 |
vsf_sysutil_memclr(p_str->p_buf, p_str->len+1); |
696 |
dyn_from_buf = from_buf; |
697 |
dyn_from_len = from_len; |
698 |
to_buf = p_str->p_buf; |
699 |
dyn_to_buf = to_buf; |
700 |
to_len = p_str->len; |
701 |
dyn_to_len = to_len; |
702 |
|
703 |
if(io_direction == ICONV_READ) |
704 |
{ |
705 |
if((cd = vsf_sysutil_iconv_init_read())==(iconv_t)(-1)) |
706 |
{ |
707 |
bug("str_iconv_read"); |
708 |
} |
709 |
} |
710 |
else |
711 |
{ |
712 |
if((cd = vsf_sysutil_iconv_init_write())==(iconv_t)(-1)) |
713 |
{ |
714 |
bug("str_iconv_write"); |
715 |
} |
716 |
} |
717 |
|
718 |
while(vsf_sysutil_iconv(cd, &dyn_from_buf, &dyn_from_len, &dyn_to_buf, &dyn_to_len)==(size_t)(-1)) |
719 |
{ |
720 |
switch(errno) |
721 |
{ |
722 |
case EILSEQ: |
723 |
if((dyn_to_buf<to_buf+to_len)&&(dyn_to_buf>=to_buf)) |
724 |
{ |
725 |
vsf_sysutil_memcpy(dyn_to_buf, dyn_from_buf, 1); |
726 |
dyn_to_buf+=1; |
727 |
dyn_to_len-=1; |
728 |
dyn_from_buf+=1; |
729 |
dyn_from_len = from_buf + from_len -dyn_from_buf; |
730 |
if(dyn_from_len==0) break; |
731 |
} |
732 |
else |
733 |
{ |
734 |
break; |
735 |
} |
736 |
continue; |
737 |
|
738 |
case EINVAL: |
739 |
break; |
740 |
|
741 |
case E2BIG: |
742 |
str_reserve(p_str, to_len+dyn_from_len); |
743 |
p_str->len=to_len+dyn_from_len; |
744 |
dyn_to_len+=dyn_from_len; |
745 |
dyn_to_buf = p_str->p_buf + (dyn_to_buf-to_buf); |
746 |
to_buf = p_str->p_buf; |
747 |
to_len = p_str->len; |
748 |
continue; |
749 |
|
750 |
default: |
751 |
die("iconv set strange errno. Should not happenned!"); |
752 |
break; |
753 |
} |
754 |
break; |
755 |
} |
756 |
|
757 |
str_trunc(p_str, (p_str->len)-dyn_to_len); |
758 |
|
759 |
vsf_sysutil_iconv_close(cd); |
760 |
vsf_sysutil_free(from_buf); |
761 |
} |
762 |
|
763 |
void |
764 |
str_iconv_read(struct mystr* p_str) |
765 |
{ |
766 |
str_iconv_inout(p_str, ICONV_READ); |
767 |
} |
768 |
|
769 |
void |
770 |
str_iconv_write(struct mystr* p_str) |
771 |
{ |
772 |
str_iconv_inout(p_str, ICONV_WRITE); |
773 |
} |
774 |
|