1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-29 13:22:36 +00:00

simplify iconv_convert() a bit (exit early on error)

This commit is contained in:
Phil Sutter 2009-11-29 14:28:30 +01:00
parent 938af98ff3
commit d9dbd528c4

View File

@ -79,37 +79,38 @@ void free_iconv(struct text_object *obj)
void iconv_convert(size_t *a, char *buff_in, char *p, size_t p_max_size) void iconv_convert(size_t *a, char *buff_in, char *p, size_t p_max_size)
{ {
if (*a > 0 && iconv_converting && iconv_selected > 0 int bytes;
&& (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) { size_t dummy1, dummy2;
int bytes;
size_t dummy1, dummy2;
#ifdef __FreeBSD__ #ifdef __FreeBSD__
const char *ptr = buff_in; const char *ptr = buff_in;
#else #else
char *ptr = buff_in; char *ptr = buff_in;
#endif #endif
char *outptr = p; char *outptr = p;
dummy1 = dummy2 = *a; if (*a <= 0 || !iconv_converting || iconv_selected <= 0
|| iconv_cd[iconv_selected - 1] == (iconv_t) (-1))
return;
strncpy(buff_in, p, p_max_size); dummy1 = dummy2 = *a;
iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL); strncpy(buff_in, p, p_max_size);
while (dummy1 > 0) {
bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1, iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
&outptr, &dummy2); while (dummy1 > 0) {
if (bytes == -1) { bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
NORM_ERR("Iconv codeset conversion failed"); &outptr, &dummy2);
break; if (bytes == -1) {
} NORM_ERR("Iconv codeset conversion failed");
break;
} }
/* It is nessecary when we are converting from multibyte to
* singlebyte codepage */
//a = outptr - p;
//(*a) = *a - dummy2;
(*a) = outptr - p;
} }
/* It is nessecary when we are converting from multibyte to
* singlebyte codepage */
//a = outptr - p;
//(*a) = *a - dummy2;
(*a) = outptr - p;
} }
void init_iconv_start(struct text_object *obj, void *free_at_crash, const char *arg) void init_iconv_start(struct text_object *obj, void *free_at_crash, const char *arg)