⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ttoul.3

📁 This a good VPN source
💻 3
字号:
.TH IPSEC_TTOUL 3 "16 Aug 2000".\" RCSID $Id: ttoul.3,v 1.3 2004/04/09 18:00:37 mcr Exp $.SH NAMEipsec ttoul, ultot \- convert unsigned-long numbers to and from text.SH SYNOPSIS.B "#include <freeswan.h>.sp.B "const char *ttoul(const char *src, size_t srclen,".ti +1c.B "int base, unsigned long *n);".br.B "size_t ultot(unsigned long n, int format, char *dst,".ti +1c.B "size_t dstlen);".SH DESCRIPTION.I Ttoulconverts a text-string number into a binary.B "unsigned long"value..I Ultotdoes the reverse conversion, back to a text version..PPNumbers are specified in text asdecimal (e.g..BR 123 ),octal with a leading zero (e.g..BR 012 ,which has value 10),or hexadecimal with a leading.B 0x(e.g..BR 0x1f ,which has value 31)in either upper or lower case..PPThe.I srclenparameter of.I ttoulspecifies the length of the string pointed to by.IR src ;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 isto be converted,a.I srclenvalue of.B 0is taken to mean.BR strlen(src) ..PPThe.I baseparameter of.I ttoulcan be.BR 8 ,.BR 10 ,or.BR 16 ,in which case the number supplied is assumed to be of that form(and in the case of.BR 16 ,to lack any.B 0xprefix).It can also be.BR 0 ,in which case the number is examined for a leading zeroor a leading.B 0xto determine its base..PPThe.I dstlenparameter of.I ultotspecifies the size of the.I dstparameter;under no circumstances are more than.I dstlenbytes written to.IR dst .A result which will not fit is truncated..I Dstlencan be zero, in which case.I dstneed 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.The.I freeswan.hheader file defines a constant,.BR ULTOT_BUF ,which is the size of a buffer just large enough for worst-case results..PPThe.I formatparameter of.I ultotmust be one of:.RS.IP \fB'o'\fR 4octal conversion with leading.B 0.IP \fB\ 8\fRoctal conversion with no leading.B 0.IP \fB'd'\fRdecimal conversion.IP \fB10\fRsame as.B d.IP \fB'x'\fRhexadecimal conversion, including leading.B 0x.IP \fB16\fRhexadecimal conversion with no leading.B 0x.IP \fB17\fRlike.B 16except padded on left with.BR 0 sto eight digits (full width of a 32-bit number).RE.PP.I Ttoulreturns NULL for success anda pointer to a string-literal error message for failure;see DIAGNOSTICS..I Ultotreturns.B 0for a failure, and otherwisereturns the size of buffer which would be needed toaccommodate the full conversion result, including terminating NUL(it is the caller's responsibility to check this against the size ofthe provided buffer to determine whether truncation has occurred)..SH SEE ALSOatol(3), strtoul(3).SH DIAGNOSTICSFatal errors in.I ttoulare:empty input;unknown.IR base ;non-digit character found;number too large for an.BR "unsigned long" ..PPFatal errors in.I ultotare:unknown.IR format ..SH HISTORYWritten for the FreeS/WAN project by Henry Spencer..SH BUGSConversion of.B 0with format.B oyields.BR 00 ..PP.I Ultotformat.B 17is a bit of a kludge..PPThe 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..PPThe 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:.PP.RS.nf.B "const char *error;".sp.B "error = ttoul( /* ... */ );".B "if (error != NULL) {".B "        /* something went wrong */".fi.RE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -