Asterisk - The Open Source Telephony Project GIT-master-0bf3178
conversions.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2017, Digium, Inc.
5 *
6 * Kevin Harwell <kharwell@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*! \file
20 * \brief Conversion utility functions
21 */
22
23#ifndef _ASTERISK_CONVERSIONS_H
24#define _ASTERISK_CONVERSIONS_H
25
26#include <stdint.h>
27
28/*!
29 * \brief Convert the given string to a signed integer
30 *
31 * This function will return failure for the following reasons:
32 *
33 * The given string to convert is NULL
34 * The given string to convert is empty.
35 * The given string to convert contains non numeric values
36 * Once converted the number is out of range (less than INT_MIN
37 * or greater than INT_MAX)
38 *
39 * \param str The string to convert
40 * \param[out] res The converted value
41 *
42 * \returns -1 if it fails to convert, 0 on success
43 */
44int ast_str_to_int(const char *str, int *res);
45
46/*!
47 * \brief Convert the given string to an unsigned integer
48 *
49 * This function will return failure for the following reasons:
50 *
51 * The given string to convert is NULL
52 * The given string to convert is empty.
53 * The given string to convert is negative (starts with a '-')
54 * The given string to convert contains non numeric values
55 * Once converted the number is out of range (greater than UINT_MAX)
56 *
57 * \param str The string to convert
58 * \param[out] res The converted value
59 *
60 * \returns -1 if it fails to convert, 0 on success
61 */
62int ast_str_to_uint(const char *str, unsigned int *res);
63
64/*!
65 * \brief Convert the given string to a signed long
66 *
67 * This function will return failure for the following reasons:
68 *
69 * The given string to convert is NULL
70 * The given string to convert is empty.
71 * The given string to convert contains non numeric values
72 * Once converted the number is out of range (less than LONG_MIN
73 * or greater than LONG_MAX)
74 *
75 * \param str The string to convert
76 * \param[out] res The converted value
77 *
78 * \returns -1 if it fails to convert, 0 on success
79 */
80int ast_str_to_long(const char *str, long *res);
81
82/*!
83 * \brief Convert the given string to an unsigned long
84 *
85 * This function will return failure for the following reasons:
86 *
87 * The given string to convert is NULL
88 * The given string to convert is empty.
89 * The given string to convert is negative (starts with a '-')
90 * The given string to convert contains non numeric values
91 * Once converted the number is out of range (greater than ULONG_MAX)
92 *
93 * \param str The string to convert
94 * \param[out] res The converted value
95 *
96 * \returns -1 if it fails to convert, 0 on success
97 */
98int ast_str_to_ulong(const char *str, unsigned long *res);
99
100/*!
101 * \brief Convert the given string to a signed max size integer
102 *
103 * This function will return failure for the following reasons:
104 *
105 * The given string to convert is NULL
106 * The given string to convert is empty.
107 * The given string to convert contains non numeric values
108 * Once converted the number is out of range (less than INTMAX_MIN
109 * or greater than INTMAX_MAX)
110 *
111 * \param str The string to convert
112 * \param[out] res The converted value
113 *
114 * \returns -1 if it fails to convert, 0 on success
115 */
116int ast_str_to_imax(const char *str, intmax_t *res);
117
118/*!
119 * \brief Convert the given string to an unsigned max size integer
120 *
121 * This function will return failure for the following reasons:
122 *
123 * The given string to convert is NULL
124 * The given string to convert is empty.
125 * The given string to convert is negative (starts with a '-')
126 * The given string to convert contains non numeric values
127 * Once converted the number is out of range (greater than UINTMAX_MAX)
128 *
129 * \param str The string to convert
130 * \param[out] res The converted value
131 *
132 * \returns -1 if it fails to convert, 0 on success
133 */
134int ast_str_to_umax(const char *str, uintmax_t *res);
135
136#endif /* _ASTERISK_CONVERSIONS_H */
const char * str
Definition: app_jack.c:147
int ast_str_to_long(const char *str, long *res)
Convert the given string to a signed long.
Definition: conversions.c:68
int ast_str_to_imax(const char *str, intmax_t *res)
Convert the given string to a signed max size integer.
Definition: conversions.c:92
int ast_str_to_umax(const char *str, uintmax_t *res)
Convert the given string to an unsigned max size integer.
Definition: conversions.c:119
int ast_str_to_int(const char *str, int *res)
Convert the given string to a signed integer.
Definition: conversions.c:44
int ast_str_to_uint(const char *str, unsigned int *res)
Convert the given string to an unsigned integer.
Definition: conversions.c:56
int ast_str_to_ulong(const char *str, unsigned long *res)
Convert the given string to an unsigned long.
Definition: conversions.c:80