logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

strtol.3p (6710B)


  1. '\" et
  2. .TH STRTOL "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. strtol,
  12. strtoll
  13. \(em convert a string to a long integer
  14. .SH SYNOPSIS
  15. .LP
  16. .nf
  17. #include <stdlib.h>
  18. .P
  19. long strtol(const char *restrict \fInptr\fP, char **restrict \fIendptr\fP, int \fIbase\fP);
  20. long long strtoll(const char *restrict \fInptr\fP, char **restrict \fIendptr\fP,
  21. int \fIbase\fP)
  22. .fi
  23. .SH DESCRIPTION
  24. The functionality described on this reference page is aligned with the
  25. ISO\ C standard. Any conflict between the requirements described here and the
  26. ISO\ C standard is unintentional. This volume of POSIX.1\(hy2017 defers to the ISO\ C standard.
  27. .P
  28. These functions shall convert the initial portion of the string pointed
  29. to by
  30. .IR nptr
  31. to a type
  32. .BR "long"
  33. and
  34. .BR "long long"
  35. representation, respectively. First, they decompose the input string
  36. into three parts:
  37. .IP " 1." 4
  38. An initial, possibly empty, sequence of white-space characters (as
  39. specified by
  40. \fIisspace\fR())
  41. .IP " 2." 4
  42. A subject sequence interpreted as an integer represented in some radix
  43. determined by the value of
  44. .IR base
  45. .IP " 3." 4
  46. A final string of one or more unrecognized characters, including
  47. the terminating NUL character of the input string.
  48. .P
  49. Then they shall attempt to convert the subject sequence to an
  50. integer, and return the result.
  51. .P
  52. If the value of
  53. .IR base
  54. is 0, the expected form of the subject sequence is that of a decimal
  55. constant, octal constant, or hexadecimal constant, any of which may be
  56. preceded by a
  57. .BR '+'
  58. or
  59. .BR '\-'
  60. sign. A decimal constant begins with a non-zero digit, and consists of
  61. a sequence of decimal digits. An octal constant consists of the prefix
  62. .BR '0'
  63. optionally followed by a sequence of the digits
  64. .BR '0'
  65. to
  66. .BR '7'
  67. only. A hexadecimal constant consists of the prefix 0x or 0X followed
  68. by a sequence of the decimal digits and letters
  69. .BR 'a'
  70. (or
  71. .BR 'A' )
  72. to
  73. .BR 'f'
  74. (or
  75. .BR 'F' )
  76. with values 10 to 15 respectively.
  77. .P
  78. If the value of
  79. .IR base
  80. is between 2 and 36, the expected form of the subject sequence is a
  81. sequence of letters and digits representing an integer with the radix
  82. specified by
  83. .IR base ,
  84. optionally preceded by a
  85. .BR '+'
  86. or
  87. .BR '\-'
  88. sign. The letters from
  89. .BR 'a'
  90. (or
  91. .BR 'A' )
  92. to
  93. .BR 'z'
  94. (or
  95. .BR 'Z' )
  96. inclusive are ascribed the values 10 to 35; only letters whose ascribed
  97. values are less than that of
  98. .IR base
  99. are permitted. If the value of
  100. .IR base
  101. is 16, the characters 0x or 0X may optionally precede the sequence of
  102. letters and digits, following the sign if present.
  103. .P
  104. The subject sequence is defined as the longest initial subsequence of
  105. the input string, starting with the first non-white-space character
  106. that is of the expected form. The subject sequence shall contain no
  107. characters if the input string is empty or consists entirely of
  108. white-space characters, or if the first non-white-space character is
  109. other than a sign or a permissible letter or digit.
  110. .P
  111. If the subject sequence has the expected form and the value of
  112. .IR base
  113. is 0, the sequence of characters starting with the first digit shall be
  114. interpreted as an integer constant. If the subject sequence has the
  115. expected form and the value of
  116. .IR base
  117. is between 2 and 36, it shall be used as the base for conversion,
  118. ascribing to each letter its value as given above. If the subject
  119. sequence begins with a
  120. <hyphen-minus>,
  121. the value resulting from the
  122. conversion shall be negated. A pointer to the final string shall be
  123. stored in the object pointed to by
  124. .IR endptr ,
  125. provided that
  126. .IR endptr
  127. is not a null pointer.
  128. .P
  129. In other than the C
  130. or POSIX
  131. locale, additional locale-specific subject sequence forms may be
  132. accepted.
  133. .P
  134. If the subject sequence is empty or does not have the expected form, no
  135. conversion is performed; the value of
  136. .IR nptr
  137. shall be stored in the object pointed to by
  138. .IR endptr ,
  139. provided that
  140. .IR endptr
  141. is not a null pointer.
  142. .P
  143. These functions shall not change the setting of
  144. .IR errno
  145. if successful.
  146. .P
  147. Since 0,
  148. {LONG_MIN}
  149. or
  150. {LLONG_MIN},
  151. and
  152. {LONG_MAX}
  153. or
  154. {LLONG_MAX}
  155. are returned on error and are also valid returns on success, an
  156. application wishing to check for error situations should set
  157. .IR errno
  158. to 0, then call
  159. \fIstrtol\fR()
  160. or
  161. \fIstrtoll\fR(),
  162. then check
  163. .IR errno .
  164. .SH "RETURN VALUE"
  165. Upon successful completion, these functions shall return the converted
  166. value, if any. If no conversion could be performed, 0 shall be returned
  167. and
  168. .IR errno
  169. may be set to
  170. .BR [EINVAL] .
  171. .P
  172. If the value of
  173. .IR base
  174. is not supported, 0 shall be returned and
  175. .IR errno
  176. shall be set to
  177. .BR [EINVAL] .
  178. .P
  179. If the correct value is outside the range of representable values,
  180. {LONG_MIN},
  181. {LONG_MAX},
  182. {LLONG_MIN},
  183. or
  184. {LLONG_MAX}
  185. shall be returned (according to the sign of the value), and
  186. .IR errno
  187. set to
  188. .BR [ERANGE] .
  189. .SH ERRORS
  190. These functions shall fail if:
  191. .TP
  192. .BR EINVAL
  193. The value of
  194. .IR base
  195. is not supported.
  196. .TP
  197. .BR ERANGE
  198. The value to be returned is not representable.
  199. .P
  200. These functions may fail if:
  201. .TP
  202. .BR EINVAL
  203. No conversion could be performed.
  204. .LP
  205. .IR "The following sections are informative."
  206. .SH EXAMPLES
  207. None.
  208. .SH "APPLICATION USAGE"
  209. Since the value of
  210. .IR *endptr
  211. is unspecified if the value of
  212. .IR base
  213. is not supported, applications should either ensure that
  214. .IR base
  215. has a supported value (0 or between 2 and 36) before the call, or check
  216. for an
  217. .BR [EINVAL]
  218. error before examining
  219. .IR *endptr .
  220. .SH RATIONALE
  221. None.
  222. .SH "FUTURE DIRECTIONS"
  223. None.
  224. .SH "SEE ALSO"
  225. .IR "\fIfscanf\fR\^(\|)",
  226. .IR "\fIisalpha\fR\^(\|)",
  227. .IR "\fIstrtod\fR\^(\|)"
  228. .P
  229. The Base Definitions volume of POSIX.1\(hy2017,
  230. .IR "\fB<stdlib.h>\fP"
  231. .\"
  232. .SH COPYRIGHT
  233. Portions of this text are reprinted and reproduced in electronic form
  234. from IEEE Std 1003.1-2017, Standard for Information Technology
  235. -- Portable Operating System Interface (POSIX), The Open Group Base
  236. Specifications Issue 7, 2018 Edition,
  237. Copyright (C) 2018 by the Institute of
  238. Electrical and Electronics Engineers, Inc and The Open Group.
  239. In the event of any discrepancy between this version and the original IEEE and
  240. The Open Group Standard, the original IEEE and The Open Group Standard
  241. is the referee document. The original Standard can be obtained online at
  242. http://www.opengroup.org/unix/online.html .
  243. .PP
  244. Any typographical or formatting errors that appear
  245. in this page are most likely
  246. to have been introduced during the conversion of the source files to
  247. man page format. To report such errors, see
  248. https://www.kernel.org/doc/man-pages/reporting_bugs.html .