1IPSEC_TTOUL(3)             Library Functions Manual             IPSEC_TTOUL(3)
2
3
4

NAME

6       ipsec ttoul, ultot - convert unsigned-long numbers to and from text
7

SYNOPSIS

9       #include <freeswan.h>
10
11       const char *ttoul(const char *src, size_t srclen,
12           int base, unsigned long *n);
13       size_t ultot(unsigned long n, int format, char *dst,
14           size_t dstlen);
15

DESCRIPTION

17       Ttoul  converts a text-string number into a binary unsigned long value.
18       Ultot does the reverse conversion, back to a text version.
19
20       Numbers are specified in text as decimal  (e.g.   123),  octal  with  a
21       leading  zero  (e.g.   012,  which has value 10), or hexadecimal with a
22       leading 0x (e.g.  0x1f, which has value 31) in either  upper  or  lower
23       case.
24
25       The  srclen  parameter  of  ttoul  specifies  the  length of the string
26       pointed to by src; it is an error for there to be anything else  (e.g.,
27       a  terminating  NUL)  within  that  length.  As a convenience for cases
28       where an entire NUL-terminated string is  to  be  converted,  a  srclen
29       value of 0 is taken to mean strlen(src).
30
31       The base parameter of ttoul can be 8, 10, or 16, in which case the num‐
32       ber supplied is assumed to be of that form (and in the case of  16,  to
33       lack  any  0x  prefix).   It can also be 0, in which case the number is
34       examined for a leading zero or a leading 0x to determine its base.
35
36       The dstlen parameter of ultot specifies the size of the dst  parameter;
37       under  no  circumstances  are more than dstlen bytes written to dst.  A
38       result which will not fit is truncated.  Dstlen can be zero,  in  which
39       case  dst  need  not  be valid and no result is written, but the return
40       value is unaffected; in  all  other  cases,  the  (possibly  truncated)
41       result  is  NUL-terminated.   The freeswan.h header file defines a con‐
42       stant, ULTOT_BUF, which is the size of a buffer just large  enough  for
43       worst-case results.
44
45       The format parameter of ultot must be one of:
46
47              'o' octal conversion with leading 0
48
49               8  octal conversion with no leading 0
50
51              'd' decimal conversion
52
53              10  same as d
54
55              'x' hexadecimal conversion, including leading 0x
56
57              16  hexadecimal conversion with no leading 0x
58
59              17  like  16 except padded on left with 0s to eight digits (full
60                  width of a 32-bit number)
61
62       Ttoul returns NULL for success and a pointer to a string-literal  error
63       message  for  failure; see DIAGNOSTICS.  Ultot returns 0 for a failure,
64       and otherwise returns the size of  buffer  which  would  be  needed  to
65       accommodate  the  full conversion result, including terminating NUL (it
66       is the caller's responsibility to check this against the  size  of  the
67       provided buffer to determine whether truncation has occurred).
68

SEE ALSO

70       atol(3), strtoul(3)
71

DIAGNOSTICS

73       Fatal errors in ttoul are: empty input; unknown base; non-digit charac‐
74       ter found; number too large for an unsigned long.
75
76       Fatal errors in ultot are: unknown format.
77

HISTORY

79       Written for the FreeS/WAN project by Henry Spencer.
80

BUGS

82       Conversion of 0 with format o yields 00.
83
84       Ultot format 17 is a bit of a kludge.
85
86       The restriction of error reports to literal strings  (so  that  callers
87       don't  need to worry about freeing them or copying them) does limit the
88       precision of error reporting.
89
90       The error-reporting convention lends itself to slightly  obscure  code,
91       because  many  readers will not think of NULL as signifying success.  A
92       good way to make it clearer is to write something like:
93
94              const char *error;
95
96              error = ttoul( /* ... */ );
97              if (error != NULL) {
98                      /* something went wrong */
99
100
101
102                                  16 Aug 2000                   IPSEC_TTOUL(3)
Impressum