1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
4
<!-- lifted from troff+man by doclifter -->
7
<refentrytitle>IPSEC_ATOUL</refentrytitle>
8
<manvolnum>3</manvolnum>
9
<refmiscinfo class='date'>11 June 2001</refmiscinfo>
11
<refnamediv id='name'>
12
<refname>ipsec atoul</refname>
13
<refname>ultoa</refname>
14
<refpurpose>convert unsigned-long numbers to and from ASCII</refpurpose>
16
<!-- body begins here -->
17
<refsynopsisdiv id='synopsis'>
20
#include <freeswan.h>
24
<funcdef>const char *<function>atoul</function></funcdef>
25
<paramdef>const char * <parameter>src</parameter></paramdef>
26
<paramdef>size_t <parameter>srclen</parameter></paramdef>
27
<paramdef>int <parameter>base</parameter></paramdef>
28
<paramdef>unsigned long * <parameter>n</parameter></paramdef>
34
<funcdef>size_t <function>ultoa</function></funcdef>
35
<paramdef>unsigned long <parameter>n</parameter></paramdef>
36
<paramdef>int <parameter>base</parameter></paramdef>
37
<paramdef>char * <parameter>dst</parameter></paramdef>
38
<paramdef>size_t <parameter>dstlen</parameter></paramdef>
44
<refsect1 id='description'><title>DESCRIPTION</title>
45
<para>These functions are obsolete; see
46
<citerefentry><refentrytitle>ipsec_ttoul</refentrytitle><manvolnum>3</manvolnum></citerefentry>
47
for their replacements.</para>
49
<para><emphasis remap='I'>Atoul</emphasis>
50
converts an ASCII number into a binary
51
<emphasis remap='B'>unsigned long</emphasis>
53
<emphasis remap='I'>Ultoa</emphasis>
54
does the reverse conversion, back to an ASCII version.</para>
56
<para>Numbers are specified in ASCII as
58
<literal>123</literal>),
59
octal with a leading zero (e.g.
60
<literal>012</literal>,
62
or hexadecimal with a leading
63
<emphasis remap='B'>0x</emphasis>
65
<emphasis remap='B'>0x1f</emphasis>,
67
in either upper or lower case.</para>
70
<varname role='parameter'>srclen</varname>
72
<function>atoul</function>
73
specifies the length of the ASCII string pointed to by
74
<varname role='parameter'>src</varname>;
75
it is an error for there to be anything else
76
(e.g., a terminating NUL) within that length.
77
As a convenience for cases where an entire NUL-terminated string is
80
<varname role='parameter'>srclen</varname>
84
<emphasis remap='B'>strlen(src)</emphasis>.</para>
87
<varname role='parameter'>base</varname>
89
<function>atoul</function>
92
<literal>10</literal>,
94
<literal>16</literal>,
95
in which case the number supplied is assumed to be of that form
97
<literal>16</literal>,
99
<emphasis remap='B'>0x</emphasis>
102
<literal>0</literal>,
103
in which case the number is examined for a leading zero
105
<emphasis remap='B'>0x</emphasis>
106
to determine its base,
108
<literal>13</literal>
109
(halfway between 10 and 16),
110
which has the same effect as
112
except that a non-hexadecimal
113
number is considered decimal regardless of any leading zero.</para>
116
<varname role='parameter'>dstlen</varname>
118
<function>ultoa</function>
119
specifies the size of the
120
<varname role='parameter'>dst</varname>
122
under no circumstances are more than
123
<varname role='parameter'>dstlen</varname>
125
<varname role='parameter'>dst</varname>.
126
A result which will not fit is truncated.
127
<emphasis remap='I'>Dstlen</emphasis>
128
can be zero, in which case
129
<varname role='parameter'>dst</varname>
130
need not be valid and no result is written,
131
but the return value is unaffected;
132
in all other cases, the (possibly truncated) result is NUL-terminated.</para>
135
<varname role='parameter'>base</varname>
137
<function>ultoa</function>
139
<literal>8</literal>,
140
<literal>10</literal>,
142
<literal>16</literal>.</para>
144
<para><emphasis remap='I'>Atoul</emphasis>
145
returns NULL for success and
146
a pointer to a string-literal error message for failure;
148
<emphasis remap='I'>Ultoa</emphasis>
149
returns the size of buffer which would
151
accommodate the full conversion result, including terminating NUL;
152
it is the caller's responsibility to check this against the size of
153
the provided buffer to determine whether truncation has occurred.</para>
156
<refsect1 id='see_also'><title>SEE ALSO</title>
157
<para><citerefentry><refentrytitle>atol</refentrytitle><manvolnum>3</manvolnum></citerefentry>, <citerefentry><refentrytitle>strtoul</refentrytitle><manvolnum>3</manvolnum></citerefentry></para>
160
<refsect1 id='diagnostics'><title>DIAGNOSTICS</title>
161
<para>Fatal errors in
162
<function>atoul</function>
166
<varname role='parameter'>base</varname>;
167
non-digit character found;
168
number too large for an
169
<emphasis remap='B'>unsigned long</emphasis>.</para>
172
<refsect1 id='history'><title>HISTORY</title>
173
<para>Written for the FreeS/WAN project by Henry Spencer.</para>
176
<refsect1 id='bugs'><title>BUGS</title>
177
<para>There is no provision for reporting an invalid
178
<varname role='parameter'>base</varname>
180
<function>ultoa</function>.</para>
182
<para>The restriction of error reports to literal strings
183
(so that callers don't need to worry about freeing them or copying them)
184
does limit the precision of error reporting.</para>
186
<para>The error-reporting convention lends itself to slightly obscure code,
187
because many readers will not think of NULL as signifying success.
188
A good way to make it clearer is to write something like:</para>
191
<literallayout remap='.nf'>
192
<emphasis remap='B'>const char *error;</emphasis>
194
<emphasis remap='B'>error = atoul( /* ... */ );</emphasis>
195
<emphasis remap='B'>if (error != NULL) {</emphasis>
196
<emphasis remap='B'> /* something went wrong */</emphasis>
197
</literallayout> <!-- .fi -->