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

atoi.3p (3006B)


  1. '\" et
  2. .TH ATOI "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. atoi
  12. \(em convert a string to an integer
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <stdlib.h>
  17. .P
  18. int atoi(const char *\fIstr\fP);
  19. .fi
  20. .SH DESCRIPTION
  21. The functionality described on this reference page is aligned with the
  22. ISO\ C standard. Any conflict between the requirements described here and the
  23. ISO\ C standard is unintentional. This volume of POSIX.1\(hy2017 defers to the ISO\ C standard.
  24. .P
  25. The call
  26. .IR atoi ( str )
  27. shall be equivalent to:
  28. .sp
  29. .RS 4
  30. .nf
  31. (int) strtol(str, (char **)NULL, 10)
  32. .fi
  33. .P
  34. .RE
  35. .P
  36. except that the handling of errors may differ. If the value cannot be
  37. represented, the behavior is undefined.
  38. .SH "RETURN VALUE"
  39. The
  40. \fIatoi\fR()
  41. function shall return the converted value if the value can be
  42. represented.
  43. .SH ERRORS
  44. No errors are defined.
  45. .LP
  46. .IR "The following sections are informative."
  47. .SH EXAMPLES
  48. .SS "Converting an Argument"
  49. .P
  50. The following example checks for proper usage of the program. If there
  51. is an argument and the decimal conversion of this argument (obtained
  52. using
  53. \fIatoi\fR())
  54. is greater than 0, then the program has a valid number of minutes to
  55. wait for an event.
  56. .sp
  57. .RS 4
  58. .nf
  59. #include <stdlib.h>
  60. #include <stdio.h>
  61. \&...
  62. int minutes_to_event;
  63. \&...
  64. if (argc < 2 || ((minutes_to_event = atoi (argv[1]))) <= 0) {
  65. fprintf(stderr, "Usage: %s minutes\en", argv[0]); exit(1);
  66. }
  67. \&...
  68. .fi
  69. .P
  70. .RE
  71. .SH "APPLICATION USAGE"
  72. The
  73. \fIatoi\fR()
  74. function is subsumed by
  75. \fIstrtol\fR()
  76. but is retained because it is used extensively in existing code. If the
  77. number is not known to be in range,
  78. \fIstrtol\fR()
  79. should be used because
  80. \fIatoi\fR()
  81. is not required to perform any error checking.
  82. .SH RATIONALE
  83. None.
  84. .SH "FUTURE DIRECTIONS"
  85. None.
  86. .SH "SEE ALSO"
  87. .IR "\fIstrtol\fR\^(\|)"
  88. .P
  89. The Base Definitions volume of POSIX.1\(hy2017,
  90. .IR "\fB<stdlib.h>\fP"
  91. .\"
  92. .SH COPYRIGHT
  93. Portions of this text are reprinted and reproduced in electronic form
  94. from IEEE Std 1003.1-2017, Standard for Information Technology
  95. -- Portable Operating System Interface (POSIX), The Open Group Base
  96. Specifications Issue 7, 2018 Edition,
  97. Copyright (C) 2018 by the Institute of
  98. Electrical and Electronics Engineers, Inc and The Open Group.
  99. In the event of any discrepancy between this version and the original IEEE and
  100. The Open Group Standard, the original IEEE and The Open Group Standard
  101. is the referee document. The original Standard can be obtained online at
  102. http://www.opengroup.org/unix/online.html .
  103. .PP
  104. Any typographical or formatting errors that appear
  105. in this page are most likely
  106. to have been introduced during the conversion of the source files to
  107. man page format. To report such errors, see
  108. https://www.kernel.org/doc/man-pages/reporting_bugs.html .