From: Pekka Riikonen Date: Sat, 21 Sep 2002 17:18:52 +0000 (+0000) Subject: Added silc_strncat. X-Git-Tag: silc.client.0.9.6~83 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=b424d54ae3239007b4d4e2e9b3f4bf55781450bb Added silc_strncat. --- diff --git a/lib/silcutil/silcstrutil.c b/lib/silcutil/silcstrutil.c index 53c1a024..b685f055 100644 --- a/lib/silcutil/silcstrutil.c +++ b/lib/silcutil/silcstrutil.c @@ -574,3 +574,25 @@ silc_mime_parse(const unsigned char *mime, SilcUInt32 mime_len, 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; +} diff --git a/lib/silcutil/silcstrutil.h b/lib/silcutil/silcstrutil.h index 1f0608cf..e29be072 100644 --- a/lib/silcutil/silcstrutil.h +++ b/lib/silcutil/silcstrutil.h @@ -214,4 +214,21 @@ silc_mime_parse(const unsigned char *mime, SilcUInt32 mime_len, char *transfer_encoding, SilcUInt32 transfer_encoding_size, unsigned char **mime_data_ptr, SilcUInt32 *mime_data_len); +/****f* silcutil/SilcStrUtilAPI/silc_strncat + * + * SYNOPSIS + * + * char *silc_strncat(char *dest, SilcUInt32 dest_size, + * const char *src, SilcUInt32 src_len); + * + * DESCRIPTION + * + * 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); + #endif /* SILCSTRUTIL_H */