Mercurial > hg > xmms-sid
diff src/xs_support.c @ 239:7833df935239
Added xs_pnstrcat() to ease forming of limited size strings.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 21 Dec 2004 15:03:05 +0000 |
parents | 608f31f6c095 |
children | d5aab11eea3d |
line wrap: on
line diff
--- a/src/xs_support.c Tue Dec 21 13:44:03 2004 +0000 +++ b/src/xs_support.c Tue Dec 21 15:03:05 2004 +0000 @@ -114,6 +114,38 @@ } +/* Concatenate a given string up to given dest size or \n. + * If size max is reached, change the end to "..." + */ +void xs_pnstrcat(gchar *pDest, size_t iSize, gchar *pStr) +{ + size_t i, n; + gchar *s, *d; + + d = pDest; i = 0; + while (*d && (i < iSize)) { i++; d++; } + + s = pStr; + while (*s && (*s != '\n') && (i < iSize)) + { + *d = *s; + d++; s++; i++; + } + + *d = 0; + + if (i >= iSize) + { + i--; d--; n = 3; + while ((i > 0) && (n > 0)) + { + *d = '.'; + d--; i--; n--; + } + } +} + + /* Locate character in string */ gchar *xs_strrchr(gchar *pcStr, gchar ch)