diff options
Diffstat (limited to 'src/common/convert.c')
-rw-r--r-- | src/common/convert.c | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/src/common/convert.c b/src/common/convert.c index 2be2108..a8a6b9d 100644 --- a/src/common/convert.c +++ b/src/common/convert.c | |||
@@ -37,8 +37,8 @@ | |||
37 | */ | 37 | */ |
38 | char * | 38 | char * |
39 | EXTRACTOR_common_convert_to_utf8 (const char *input, | 39 | EXTRACTOR_common_convert_to_utf8 (const char *input, |
40 | size_t len, | 40 | size_t len, |
41 | const char *charset) | 41 | const char *charset) |
42 | { | 42 | { |
43 | #if HAVE_ICONV | 43 | #if HAVE_ICONV |
44 | size_t tmpSize; | 44 | size_t tmpSize; |
@@ -51,35 +51,35 @@ EXTRACTOR_common_convert_to_utf8 (const char *input, | |||
51 | 51 | ||
52 | i = input; | 52 | i = input; |
53 | cd = iconv_open ("UTF-8", charset); | 53 | cd = iconv_open ("UTF-8", charset); |
54 | if (cd == (iconv_t) - 1) | 54 | if (cd == (iconv_t) -1) |
55 | return strndup (i, len); | 55 | return strndup (i, len); |
56 | if (len > 1024 * 1024) | 56 | if (len > 1024 * 1024) |
57 | { | 57 | { |
58 | iconv_close (cd); | 58 | iconv_close (cd); |
59 | return NULL; /* too big for meta data */ | 59 | return NULL; /* too big for meta data */ |
60 | } | 60 | } |
61 | tmpSize = 3 * len + 4; | 61 | tmpSize = 3 * len + 4; |
62 | tmp = malloc (tmpSize); | 62 | tmp = malloc (tmpSize); |
63 | if (tmp == NULL) | 63 | if (tmp == NULL) |
64 | { | 64 | { |
65 | iconv_close (cd); | 65 | iconv_close (cd); |
66 | return NULL; | 66 | return NULL; |
67 | } | 67 | } |
68 | itmp = tmp; | 68 | itmp = tmp; |
69 | finSize = tmpSize; | 69 | finSize = tmpSize; |
70 | if (iconv (cd, (char **) &input, &len, &itmp, &finSize) == ((size_t) -1)) | 70 | if (iconv (cd, (char **) &input, &len, &itmp, &finSize) == ((size_t) -1)) |
71 | { | 71 | { |
72 | iconv_close (cd); | 72 | iconv_close (cd); |
73 | free (tmp); | 73 | free (tmp); |
74 | return strndup (i, len); | 74 | return strndup (i, len); |
75 | } | 75 | } |
76 | ret = malloc (tmpSize - finSize + 1); | 76 | ret = malloc (tmpSize - finSize + 1); |
77 | if (ret == NULL) | 77 | if (ret == NULL) |
78 | { | 78 | { |
79 | iconv_close (cd); | 79 | iconv_close (cd); |
80 | free (tmp); | 80 | free (tmp); |
81 | return NULL; | 81 | return NULL; |
82 | } | 82 | } |
83 | memcpy (ret, tmp, tmpSize - finSize); | 83 | memcpy (ret, tmp, tmpSize - finSize); |
84 | ret[tmpSize - finSize] = '\0'; | 84 | ret[tmpSize - finSize] = '\0'; |
85 | free (tmp); | 85 | free (tmp); |
@@ -95,4 +95,5 @@ EXTRACTOR_common_convert_to_utf8 (const char *input, | |||
95 | #endif | 95 | #endif |
96 | } | 96 | } |
97 | 97 | ||
98 | |||
98 | /* end of convert.c */ | 99 | /* end of convert.c */ |