Mercurial > hg > nnchat
comparison libnnchat.c @ 304:61884ce9db41 dev-0_9_2
Use th_vputch() and th_vputs() instead of similar routines in libnnchat.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 11 Jun 2011 05:10:30 +0300 |
parents | b765f15f9895 |
children | a0c001672b44 |
comparison
equal
deleted
inserted
replaced
303:859578ec3275 | 304:61884ce9db41 |
---|---|
230 WSACleanup(); | 230 WSACleanup(); |
231 #endif | 231 #endif |
232 } | 232 } |
233 | 233 |
234 | 234 |
235 static BOOL bufRealloc(char **buf, size_t *size, size_t add) | 235 #define PUSHCHAR(x) th_vputch(&result, &resSize, &resPos, x) |
236 { | 236 #define PUSHSTR(x) th_vputs(&result, &resSize, &resPos, x) |
237 return ((*buf = th_realloc(*buf, *size + add)) != NULL); | |
238 } | |
239 | |
240 #define PUSHCHAR(x) bufPushChar(&result, &resSize, &resPos, x) | |
241 static BOOL bufPushChar(char **buf, size_t *size, size_t *pos, char ch) | |
242 { | |
243 if (*pos >= *size && !bufRealloc(buf, size, NN_ALLOC_SIZE)) | |
244 return FALSE; | |
245 | |
246 (*buf)[*pos] = ch; | |
247 (*pos)++; | |
248 return TRUE; | |
249 } | |
250 | |
251 #define PUSHSTR(x) bufPushStr(&result, &resSize, &resPos, x) | |
252 static BOOL bufPushStr(char **buf, size_t *size, size_t *pos, char *str) | |
253 { | |
254 size_t tmpLen; | |
255 | |
256 if (str == NULL) return FALSE; | |
257 tmpLen = strlen(str); | |
258 | |
259 if ((*pos + tmpLen) >= *size && !bufRealloc(buf, size, tmpLen + NN_ALLOC_SIZE)) | |
260 return FALSE; | |
261 | |
262 strcpy(*buf + *pos, str); | |
263 (*pos) += tmpLen; | |
264 return TRUE; | |
265 } | |
266 | |
267 | 237 |
268 char *nn_encode_str1(const char *str) | 238 char *nn_encode_str1(const char *str) |
269 { | 239 { |
270 const char *s = str; | 240 const char *s = str; |
271 char *result; | 241 char *result; |