File: obuf_putsnumw.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (44 lines) | stat: -rw-r--r-- 1,095 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "fmt.h"
#include "obuf.h"

/** Write a signed integer to the \c obuf with optional padding. */
int obuf_putsnumw(obuf* out, long data, unsigned width, char pad,
		  unsigned base, const char* digits)
{
  unsigned len = fmt_snumw(0, data, width, pad, base, digits);
  char buf[len];
  fmt_snumw(buf, data, width, pad, base, digits);
  return obuf_write(out, buf, len);
}

/** Write a signed integer as decimal to the \c obuf with padding. */
int obuf_putiw(obuf* out, long data, unsigned width, char pad)
{
  return obuf_putsnumw(out, data, width, pad, 10, fmt_lcase_digits);
}

/** Write a signed integer as decimal to the \c obuf. */
int obuf_puti(obuf* out, long data)
{
  return obuf_putsnumw(out, data, 0, 0, 10, fmt_lcase_digits);
}

#ifdef SELFTEST_MAIN
MAIN
{
  obuf_putiw(&outbuf,  10, 0,   0); NL();
  obuf_putiw(&outbuf, -10, 0,   0); NL();
  obuf_putiw(&outbuf,  10, 5, ' '); NL();
  obuf_putiw(&outbuf,  10, 5, '0'); NL();
  obuf_putiw(&outbuf, -10, 5, ' '); NL();
  obuf_putiw(&outbuf, -10, 5, '0'); NL();
}
#endif
#ifdef SELFTEST_EXP
10
-10
   10
00010
  -10
-0010
#endif