1
.TH IPSEC_TTOUL 3 "16 Aug 2000"
2
.\" RCSID $Id: ttoul.3,v 1.3 2004/04/09 18:00:37 mcr Exp $
4
ipsec ttoul, ultot \- convert unsigned-long numbers to and from text
6
.B "#include <freeswan.h>
8
.B "const char *ttoul(const char *src, size_t srclen,"
10
.B "int base, unsigned long *n);"
12
.B "size_t ultot(unsigned long n, int format, char *dst,"
17
converts a text-string number into a binary
21
does the reverse conversion, back to a text version.
23
Numbers are specified in text as
26
octal with a leading zero (e.g.
29
or hexadecimal with a leading
34
in either upper or lower case.
40
specifies the length of the string pointed to by
42
it is an error for there to be anything else
43
(e.g., a terminating NUL) within that length.
44
As a convenience for cases where an entire NUL-terminated string is
62
in which case the number supplied is assumed to be of that form
70
in which case the number is examined for a leading zero
73
to determine its base.
79
specifies the size of the
82
under no circumstances are more than
86
A result which will not fit is truncated.
88
can be zero, in which case
90
need not be valid and no result is written,
91
but the return value is unaffected;
92
in all other cases, the (possibly truncated) result is NUL-terminated.
95
header file defines a constant,
97
which is the size of a buffer just large enough for worst-case results.
106
octal conversion with leading
109
octal conversion with no leading
117
hexadecimal conversion, including leading
120
hexadecimal conversion with no leading
125
except padded on left with
127
to eight digits (full width of a 32-bit number)
131
returns NULL for success and
132
a pointer to a string-literal error message for failure;
137
for a failure, and otherwise
138
returns the size of buffer which would
140
accommodate the full conversion result, including terminating NUL
141
(it is the caller's responsibility to check this against the size of
142
the provided buffer to determine whether truncation has occurred).
152
non-digit character found;
153
number too large for an
154
.BR "unsigned long" .
162
Written for the FreeS/WAN project by Henry Spencer.
174
is a bit of a kludge.
176
The restriction of error reports to literal strings
177
(so that callers don't need to worry about freeing them or copying them)
178
does limit the precision of error reporting.
180
The error-reporting convention lends itself to slightly obscure code,
181
because many readers will not think of NULL as signifying success.
182
A good way to make it clearer is to write something like:
186
.B "const char *error;"
188
.B "error = ttoul( /* ... */ );"
189
.B "if (error != NULL) {"
190
.B " /* something went wrong */"