ocp = (char *)utf8;
inlen = bin_len;
outlen = utf8_size;
- if (icd != (iconv_t)-1 &&
- (iconv(icd, &icp, &inlen, &ocp, &outlen) != -1)) {
- utf8_size -= outlen;
- iconv_close(icd);
- return utf8_size;
- } else {
- if (icd != (iconv_t)-1)
+ if (icp && ocp && icd != (iconv_t)-1) {
+ if (iconv(icd, &icp, &inlen, &ocp, &outlen) != -1) {
+ utf8_size -= outlen;
iconv_close(icd);
+ return utf8_size;
+ }
}
+ if (icd != (iconv_t)-1)
+ iconv_close(icd);
}
#endif
ocp = (char *)bin;
inlen = utf8_len;
outlen = bin_size;
- if (icd != (iconv_t)-1 &&
- (iconv(icd, &icp, &inlen, &ocp, &outlen) != -1)) {
- bin_size -= outlen;
- iconv_close(icd);
- return bin_size;
- } else {
- if (icd != (iconv_t)-1)
+ if (icp && ocp && icd != (iconv_t)-1) {
+ if (iconv(icd, &icp, &inlen, &ocp, &outlen) != -1) {
+ bin_size -= outlen;
iconv_close(icd);
+ return bin_size;
+ }
}
+ if (icd != (iconv_t)-1)
+ iconv_close(icd);
}
#endif
return TRUE;
}
+
+/* Concatenates the `src' into `dest'. If `src_len' is more than the
+ size of the `dest' (minus NULL at the end) the `src' will be
+ truncated to fit. */
+
+char *silc_strncat(char *dest, SilcUInt32 dest_size,
+ const char *src, SilcUInt32 src_len)
+{
+ int len;
+
+ dest[dest_size - 1] = '\0';
+
+ len = dest_size - 1 - strlen(dest);
+ if (len < src_len) {
+ if (len > 0)
+ strncat(dest, src, len);
+ } else {
+ strncat(dest, src, src_len);
+ }
+
+ return dest;
+}