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