Parse a number in a string. More...
#include "config.h"
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include "atoi.h"
Go to the source code of this file.
Functions | |
static const char * | str_atol_clamp (const char *str, long *dst, long lmin, long lmax) |
Convert ASCII string to a long and clamp. | |
static const char * | str_atoull_clamp (const char *str, unsigned long long *dst, unsigned long long ullmax) |
Convert ASCII string to an unsigned long long and clamp. | |
const char * | mutt_str_atol (const char *str, long *dst) |
Convert ASCII string to a long. | |
const char * | mutt_str_atos (const char *str, short *dst) |
Convert ASCII string to a short. | |
const char * | mutt_str_atoi (const char *str, int *dst) |
Convert ASCII string to an integer. | |
const char * | mutt_str_atoui (const char *str, unsigned int *dst) |
Convert ASCII string to an unsigned integer. | |
const char * | mutt_str_atoul (const char *str, unsigned long *dst) |
Convert ASCII string to an unsigned long. | |
const char * | mutt_str_atous (const char *str, unsigned short *dst) |
Convert ASCII string to an unsigned short. | |
const char * | mutt_str_atoull (const char *str, unsigned long long *dst) |
Convert ASCII string to an unsigned long long. | |
Parse a number in a string.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file atoi.c.
|
static |
Convert ASCII string to a long and clamp.
[in] | str | String to read |
[in] | lmin | Lower bound |
[in] | lmax | Upper bound |
[out] | dst | Store the result |
ptr | endptr |
Condition | Description |
---|---|
endptr == NULL | No conversion happened, or overflow |
endptr[0] == '\0' | str was fully converted |
endptr[0] != '\0' | endptr points to first non converted char in str |
This is a strtol() wrapper with range checking. errno may be set on error, e.g. ERANGE
Definition at line 54 of file atoi.c.
|
static |
Convert ASCII string to an unsigned long long and clamp.
[in] | str | String to read |
[in] | ullmax | Upper bound |
[out] | dst | Store the result |
ptr | endptr |
Condition | Description |
---|---|
endptr == NULL | No conversion happened, or overflow |
endptr[0] == '\0' | str was fully converted |
endptr[0] != '\0' | endptr points to first non converted char in str |
This is a strtoull() wrapper with range checking. errno may be set on error, e.g. ERANGE
Definition at line 99 of file atoi.c.
const char * mutt_str_atol | ( | const char * | str, |
long * | dst | ||
) |
Convert ASCII string to a long.
[in] | str | String to read |
[out] | dst | Store the result |
ptr | endptr |
Condition | Description |
---|---|
endptr == NULL | No conversion happened, or overflow |
endptr[0] == '\0' | str was fully converted |
endptr[0] != '\0' | endptr points to first non converted char in str |
This is a strtol() wrapper with range checking. errno may be set on error, e.g. ERANGE
Definition at line 143 of file atoi.c.
const char * mutt_str_atos | ( | const char * | str, |
short * | dst | ||
) |
Convert ASCII string to a short.
[in] | str | String to read |
[out] | dst | Store the result |
0 | Success |
-1 | Error |
-2 | Error, overflow |
This is a strtol() wrapper with range checking. If dst is NULL, the string will be tested only (without conversion).
errno may be set on error, e.g. ERANGE
Definition at line 161 of file atoi.c.
const char * mutt_str_atoi | ( | const char * | str, |
int * | dst | ||
) |
Convert ASCII string to an integer.
[in] | str | String to read |
[out] | dst | Store the result |
ptr | endptr |
Condition | Description |
---|---|
endptr == NULL | No conversion happened, or overflow |
endptr[0] == '\0' | str was fully converted |
endptr[0] != '\0' | endptr points to first non converted char in str |
This is a strtol() wrapper with range checking. If dst is NULL, the string will be tested only (without conversion). errno may be set on error, e.g. ERANGE
Definition at line 188 of file atoi.c.
const char * mutt_str_atoui | ( | const char * | str, |
unsigned int * | dst | ||
) |
Convert ASCII string to an unsigned integer.
[in] | str | String to read |
[out] | dst | Store the result |
ptr | endptr |
Condition | Description |
---|---|
endptr == NULL | No conversion happened, or overflow |
endptr[0] == '\0' | str was fully converted |
endptr[0] != '\0' | endptr points to first non converted char in str |
Definition at line 214 of file atoi.c.
const char * mutt_str_atoul | ( | const char * | str, |
unsigned long * | dst | ||
) |
Convert ASCII string to an unsigned long.
[in] | str | String to read |
[out] | dst | Store the result |
ptr | endptr |
Condition | Description |
---|---|
endptr == NULL | No conversion happened, or overflow |
endptr[0] == '\0' | str was fully converted |
endptr[0] != '\0' | endptr points to first non converted char in str |
Definition at line 240 of file atoi.c.
const char * mutt_str_atous | ( | const char * | str, |
unsigned short * | dst | ||
) |
Convert ASCII string to an unsigned short.
[in] | str | String to read |
[out] | dst | Store the result |
ptr | endptr |
Condition | Description |
---|---|
endptr == NULL | No conversion happened, or overflow |
endptr[0] == '\0' | str was fully converted |
endptr[0] != '\0' | endptr points to first non converted char in str |
Definition at line 266 of file atoi.c.
const char * mutt_str_atoull | ( | const char * | str, |
unsigned long long * | dst | ||
) |
Convert ASCII string to an unsigned long long.
[in] | str | String to read |
[out] | dst | Store the result |
ptr | endptr |
Condition | Description |
---|---|
endptr == NULL | No conversion happened, or overflow |
endptr[0] == '\0' | str was fully converted |
endptr[0] != '\0' | endptr points to first non converted char in str |
Definition at line 292 of file atoi.c.