Mercurial > hg > xmms-sid
comparison 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 |
comparison
equal
deleted
inserted
replaced
238:5a390af358fc | 239:7833df935239 |
---|---|
112 | 112 |
113 return 0; | 113 return 0; |
114 } | 114 } |
115 | 115 |
116 | 116 |
117 /* Concatenate a given string up to given dest size or \n. | |
118 * If size max is reached, change the end to "..." | |
119 */ | |
120 void xs_pnstrcat(gchar *pDest, size_t iSize, gchar *pStr) | |
121 { | |
122 size_t i, n; | |
123 gchar *s, *d; | |
124 | |
125 d = pDest; i = 0; | |
126 while (*d && (i < iSize)) { i++; d++; } | |
127 | |
128 s = pStr; | |
129 while (*s && (*s != '\n') && (i < iSize)) | |
130 { | |
131 *d = *s; | |
132 d++; s++; i++; | |
133 } | |
134 | |
135 *d = 0; | |
136 | |
137 if (i >= iSize) | |
138 { | |
139 i--; d--; n = 3; | |
140 while ((i > 0) && (n > 0)) | |
141 { | |
142 *d = '.'; | |
143 d--; i--; n--; | |
144 } | |
145 } | |
146 } | |
147 | |
148 | |
117 /* Locate character in string | 149 /* Locate character in string |
118 */ | 150 */ |
119 gchar *xs_strrchr(gchar *pcStr, gchar ch) | 151 gchar *xs_strrchr(gchar *pcStr, gchar ch) |
120 { | 152 { |
121 gchar *lastPos = NULL; | 153 gchar *lastPos = NULL; |