aboutsummaryrefslogtreecommitdiffstats
path: root/doc/manpage.d/ipsec_ultoa.3.html
blob: 7669dce520278d7687188415c2dcd91b3cceafee (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
Content-type: text/html

<HTML><HEAD><TITLE>Manpage of IPSEC_ATOUL</TITLE>
</HEAD><BODY>
<H1>IPSEC_ATOUL</H1>
Section: C Library Functions (3)<BR>Updated: 11 June 2001<BR><A HREF="#index">Index</A>
<A HREF="http://localhost/cgi-bin/man/man2html">Return to Main Contents</A><HR>


<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>

ipsec atoul, ultoa - convert unsigned-long numbers to and from ASCII
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>

<B>#include &lt;<A HREF="file:/usr/include/freeswan.h">freeswan.h</A>&gt;</B>

<P>
<B>const char *atoul(const char *src, size_t srclen,</B>

<BR>
&nbsp;
<B>int base, unsigned long *n);</B>

<BR>

<B>size_t ultoa(unsigned long n, int base, char *dst,</B>

<BR>
&nbsp;
<B>size_t dstlen);</B>

<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>

These functions are obsolete; see
<I><A HREF="ipsec_ttoul.3.html">ipsec_ttoul</A></I>(3)

for their replacements.
<P>

<I>Atoul</I>

converts an ASCII number into a binary
<B>unsigned long</B>

value.
<I>Ultoa</I>

does the reverse conversion, back to an ASCII version.
<P>

Numbers are specified in ASCII as
decimal (e.g.
<B>123</B>),

octal with a leading zero (e.g.
<B>012</B>,

which has value 10),
or hexadecimal with a leading
<B>0x</B>

(e.g.
<B>0x1f</B>,

which has value 31)
in either upper or lower case.
<P>

The
<I>srclen</I>

parameter of
<I>atoul</I>

specifies the length of the ASCII string pointed to by
<I>src</I>;

it is an error for there to be anything else
(e.g., a terminating NUL) within that length.
As a convenience for cases where an entire NUL-terminated string is
to be converted,
a
<I>srclen</I>

value of
<B>0</B>

is taken to mean
<B>strlen(src)</B>.

<P>

The
<I>base</I>

parameter of
<I>atoul</I>

can be
<B>8</B>,

<B>10</B>,

or
<B>16</B>,

in which case the number supplied is assumed to be of that form
(and in the case of
<B>16</B>,

to lack any
<B>0x</B>

prefix).
It can also be
<B>0</B>,

in which case the number is examined for a leading zero
or a leading
<B>0x</B>

to determine its base,
or
<B>13</B>

(halfway between 10 and 16),
which has the same effect as
<B>0</B>

except that a non-hexadecimal
number is considered decimal regardless of any leading zero.
<P>

The
<I>dstlen</I>

parameter of
<I>ultoa</I>

specifies the size of the
<I>dst</I>

parameter;
under no circumstances are more than
<I>dstlen</I>

bytes written to
<I>dst</I>.

A result which will not fit is truncated.
<I>Dstlen</I>

can be zero, in which case
<I>dst</I>

need not be valid and no result is written,
but the return value is unaffected;
in all other cases, the (possibly truncated) result is NUL-terminated.
<P>

The
<I>base</I>

parameter of
<I>ultoa</I>

must be
<B>8</B>,

<B>10</B>,

or
<B>16</B>.

<P>

<I>Atoul</I>

returns NULL for success and
a pointer to a string-literal error message for failure;
see DIAGNOSTICS.
<I>Ultoa</I>

returns the size of buffer which would 
be needed to
accommodate the full conversion result, including terminating NUL;
it is the caller's responsibility to check this against the size of
the provided buffer to determine whether truncation has occurred.
<A NAME="lbAE">&nbsp;</A>
<H2>SEE ALSO</H2>

<A HREF="atol.3.html">atol</A>(3), <A HREF="strtoul.3.html">strtoul</A>(3)
<A NAME="lbAF">&nbsp;</A>
<H2>DIAGNOSTICS</H2>

Fatal errors in
<I>atoul</I>

are:
empty input;
unknown
<I>base</I>;

non-digit character found;
number too large for an
<B>unsigned long</B>.

<A NAME="lbAG">&nbsp;</A>
<H2>HISTORY</H2>

Written for the FreeS/WAN project by Henry Spencer.
<A NAME="lbAH">&nbsp;</A>
<H2>BUGS</H2>

There is no provision for reporting an invalid
<I>base</I>

parameter given to
<I>ultoa</I>.

<P>

The restriction of error reports to literal strings
(so that callers don't need to worry about freeing them or copying them)
does limit the precision of error reporting.
<P>

The error-reporting convention lends itself to slightly obscure code,
because many readers will not think of NULL as signifying success.
A good way to make it clearer is to write something like:
<P>

<DL COMPACT><DT><DD>
<PRE>
<B>const char *error;</B>

<B>error = atoul( /* ... */ );</B>
<B>if (error != NULL) {</B>
<B>        /* something went wrong */</B>
</PRE>

</DL>

<P>

<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT><A HREF="#lbAE">SEE ALSO</A><DD>
<DT><A HREF="#lbAF">DIAGNOSTICS</A><DD>
<DT><A HREF="#lbAG">HISTORY</A><DD>
<DT><A HREF="#lbAH">BUGS</A><DD>
</DL>
<HR>
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 21:40:18 GMT, November 11, 2003
</BODY>
</HTML>