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

NAME

6       ipsec atoul, ultoa - convert unsigned-long numbers to and from ASCII
7

SYNOPSIS

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

DESCRIPTION

17       These  functions  are  obsolete;  see ipsec_ttoul(3) for their replace‐
18       ments.
19
20       Atoul converts an ASCII number  into  a  binary  unsigned  long  value.
21       Ultoa does the reverse conversion, back to an ASCII version.
22
23       Numbers  are  specified  in  ASCII as decimal (e.g.  123), octal with a
24       leading zero (e.g.  012, which has value 10),  or  hexadecimal  with  a
25       leading  0x  (e.g.   0x1f, which has value 31) in either upper or lower
26       case.
27
28       The srclen parameter of atoul specifies the length of the ASCII  string
29       pointed  to by src; it is an error for there to be anything else (e.g.,
30       a terminating NUL) within that length.   As  a  convenience  for  cases
31       where  an  entire  NUL-terminated  string  is to be converted, a srclen
32       value of 0 is taken to mean strlen(src).
33
34       The base parameter of atoul can be 8, 10, or 16, in which case the num‐
35       ber  supplied  is assumed to be of that form (and in the case of 16, to
36       lack any 0x prefix).  It can also be 0, in which  case  the  number  is
37       examined  for  a leading zero or a leading 0x to determine its base, or
38       13 (halfway between 10 and 16), which has the same effect as  0  except
39       that  a  non-hexadecimal number is considered decimal regardless of any
40       leading zero.
41
42       The dstlen parameter of ultoa specifies the size of the dst  parameter;
43       under  no  circumstances  are more than dstlen bytes written to dst.  A
44       result which will not fit is truncated.  Dstlen can be zero,  in  which
45       case  dst  need  not  be valid and no result is written, but the return
46       value is unaffected; in  all  other  cases,  the  (possibly  truncated)
47       result is NUL-terminated.
48
49       The base parameter of ultoa must be 8, 10, or 16.
50
51       Atoul  returns NULL for success and a pointer to a string-literal error
52       message for failure; see DIAGNOSTICS.  Ultoa returns the size of buffer
53       which  would  be  needed  to  accommodate  the  full conversion result,
54       including terminating NUL; it is the caller's responsibility  to  check
55       this against the size of the provided buffer to determine whether trun‐
56       cation has occurred.
57

SEE ALSO

59       atol(3), strtoul(3)
60

DIAGNOSTICS

62       Fatal errors in atoul are: empty input; unknown base; non-digit charac‐
63       ter found; number too large for an unsigned long.
64

HISTORY

66       Written for the FreeS/WAN project by Henry Spencer.
67

BUGS

69       There  is no provision for reporting an invalid base parameter given to
70       ultoa.
71
72       The restriction of error reports to literal strings  (so  that  callers
73       don't  need to worry about freeing them or copying them) does limit the
74       precision of error reporting.
75
76       The error-reporting convention lends itself to slightly  obscure  code,
77       because  many  readers will not think of NULL as signifying success.  A
78       good way to make it clearer is to write something like:
79
80              const char *error;
81
82              error = atoul( /* ... */ );
83              if (error != NULL) {
84                      /* something went wrong */
85
86
87
88                                 11 June 2001                   IPSEC_ATOUL(3)
Impressum