Mercurial > hg > nnchat
comparison th_string.c @ 127:f741718d13c5
Portability fixes.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 29 Oct 2010 23:12:23 +0300 |
parents | 9ae3d87a686f |
children | 3896861974ac |
comparison
equal
deleted
inserted
replaced
126:9ae3d87a686f | 127:f741718d13c5 |
---|---|
56 | 56 |
57 /* Simulate a sprintf() that allocates memory | 57 /* Simulate a sprintf() that allocates memory |
58 */ | 58 */ |
59 char * th_strdup_vprintf(const char *fmt, va_list args) | 59 char * th_strdup_vprintf(const char *fmt, va_list args) |
60 { | 60 { |
61 ssize_t size = 100; | 61 int size = 100; |
62 char *buf, *nbuf = NULL; | 62 char *buf, *nbuf = NULL; |
63 | 63 |
64 if ((buf = th_malloc(size)) == NULL) | 64 if ((buf = th_malloc(size)) == NULL) |
65 return NULL; | 65 return NULL; |
66 | 66 |
67 while (1) { | 67 while (1) { |
68 ssize_t n = vsnprintf(buf, size, fmt, args); | 68 int n = vsnprintf(buf, size, fmt, args); |
69 if (n > -1 && n < size) | 69 if (n > -1 && n < size) |
70 return buf; | 70 return buf; |
71 if (n > -1) | 71 if (n > -1) |
72 size = n + 1; | 72 size = n + 1; |
73 else | 73 else |