| 1 | #include "stralloc.h" |
| 2 | |
| 3 | int stralloc_catulong0(stralloc *sa,unsigned long u,unsigned int n) |
| 4 | { |
| 5 | unsigned int len; |
| 6 | unsigned long q; |
| 7 | char *s; |
| 8 | |
| 9 | len = 1; |
| 10 | q = u; |
| 11 | while (q > 9) { ++len; q /= 10; } |
| 12 | if (len < n) len = n; |
| 13 | |
| 14 | if (!stralloc_readyplus(sa,len)) return 0; |
| 15 | s = sa->s + sa->len; |
| 16 | sa->len += len; |
| 17 | while (len) { s[--len] = '0' + (u % 10); u /= 10; } |
| 18 | |
| 19 | return 1; |
| 20 | } |
| 21 | |
| 22 | int stralloc_catlong0(stralloc *sa,long l,unsigned int n) |
| 23 | { |
| 24 | if (l < 0) { |
| 25 | if (!stralloc_append(sa,"-")) return 0; |
| 26 | l = -l; |
| 27 | } |
| 28 | return stralloc_catulong0(sa,l,n); |
| 29 | } |