NeoMutt  2022-04-29-81-g9c5a59
Teaching an old dog new tricks
DOXYGEN
atoi.h File Reference

Parse a number in a string. More...

#include <stdbool.h>
+ Include dependency graph for atoi.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define make_str_ato_wrappers(flavour, type)
 

Functions

const char * mutt_str_atoi (const char *str, int *dst)
 Convert ASCII string to an integer. More...
 
const char * mutt_str_atol (const char *str, long *dst)
 Convert ASCII string to a long. More...
 
const char * mutt_str_atos (const char *str, short *dst)
 Convert ASCII string to a short. More...
 
const char * mutt_str_atoui (const char *str, unsigned int *dst)
 Convert ASCII string to an unsigned integer. More...
 
const char * mutt_str_atoul (const char *str, unsigned long *dst)
 Convert ASCII string to an unsigned long. More...
 
const char * mutt_str_atoull (const char *str, unsigned long long *dst)
 Convert ASCII string to an unsigned long long. More...
 
const char * mutt_str_atous (const char *str, unsigned short *dst)
 Convert ASCII string to an unsigned short. More...
 
 make_str_ato_wrappers (i, int) make_str_ato_wrappers(l
 
long make_str_ato_wrappers (s, short) make_str_ato_wrappers(ui
 
long unsigned int make_str_ato_wrappers (ul, unsigned long) make_str_ato_wrappers(ull
 

Detailed Description

Parse a number in a string.

Authors
  • Pietro Cerutti

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.h.

Macro Definition Documentation

◆ make_str_ato_wrappers

#define make_str_ato_wrappers (   flavour,
  type 
)
Value:
static inline bool mutt_str_ato ## flavour ## _full(const char *src, type *dst) \
{ \
const char * end = mutt_str_ato ## flavour(src, dst); \
return end && !*end; \
} \

Definition at line 36 of file atoi.h.

Function Documentation

◆ mutt_str_atoi()

const char* mutt_str_atoi ( const char *  str,
int *  dst 
)

Convert ASCII string to an integer.

Parameters
[in]strString to read
[out]dstStore the result
Return values
endptrendptr == 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 178 of file atoi.c.

179 {
180  long l;
181  const char *res = str_atol_clamp(str, &l, INT_MIN, INT_MAX);
182  if (dst)
183  {
184  *dst = res ? l : 0;
185  }
186  return res;
187 }
static const char * str_atol_clamp(const char *str, long *dst, long lmin, long lmax)
Convert ASCII string to a long and clamp.
Definition: atoi.c:50
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_str_atol()

const char* mutt_str_atol ( const char *  str,
long *  dst 
)

Convert ASCII string to a long.

Parameters
[in]strString to read
[out]dstStore the result
Return values
endptrendptr == 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 135 of file atoi.c.

136 {
137  return str_atol_clamp(str, dst, LONG_MIN, LONG_MAX);
138 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_str_atos()

const char* mutt_str_atos ( const char *  str,
short *  dst 
)

Convert ASCII string to a short.

Parameters
[in]strString to read
[out]dstStore the result
Return values
0Success
-1Error
-2Error, 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 153 of file atoi.c.

154 {
155  long l;
156  const char *res = str_atol_clamp(str, &l, SHRT_MIN, SHRT_MAX);
157  if (dst)
158  {
159  *dst = res ? l : 0;
160  }
161  return res;
162 }
+ Here is the call graph for this function:

◆ mutt_str_atoui()

const char* mutt_str_atoui ( const char *  str,
unsigned int *  dst 
)

Convert ASCII string to an unsigned integer.

Parameters
[in]strString to read
[out]dstStore the result
Return values
endptrendptr == 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
Note
This function's return value differs from the other functions. They return -1 if there is input beyond the number.

Definition at line 202 of file atoi.c.

203 {
204  unsigned long long l;
205  const char *res = str_atoull_clamp(str, &l, UINT_MAX);
206  if (dst)
207  {
208  *dst = res ? l : 0;
209  }
210  return res;
211 }
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.
Definition: atoi.c:93
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_str_atoul()

const char* mutt_str_atoul ( const char *  str,
unsigned long *  dst 
)

Convert ASCII string to an unsigned long.

Parameters
[in]strString to read
[out]dstStore the result
Return values
endptrendptr == 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
Note
This function's return value differs from the other functions. They return -1 if there is input beyond the number.

Definition at line 226 of file atoi.c.

227 {
228  unsigned long long l;
229  const char *res = str_atoull_clamp(str, &l, ULONG_MAX);
230  if (dst)
231  {
232  *dst = res ? l : 0;
233  }
234  return res;
235 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_str_atoull()

const char* mutt_str_atoull ( const char *  str,
unsigned long long *  dst 
)

Convert ASCII string to an unsigned long long.

Parameters
[in]strString to read
[out]dstStore the result
Return values
endptrendptr == 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
Note
This function's return value differs from the other functions. They return -1 if there is input beyond the number.

Definition at line 274 of file atoi.c.

275 {
276  return str_atoull_clamp(str, dst, ULLONG_MAX);
277 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_str_atous()

const char* mutt_str_atous ( const char *  str,
unsigned short *  dst 
)

Convert ASCII string to an unsigned short.

Parameters
[in]strString to read
[out]dstStore the result
Return values
endptrendptr == 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
Note
This function's return value differs from the other functions. They return -1 if there is input beyond the number.

Definition at line 250 of file atoi.c.

251 {
252  unsigned long long l;
253  const char *res = str_atoull_clamp(str, &l, USHRT_MAX);
254  if (dst)
255  {
256  *dst = res ? l : 0;
257  }
258  return res;
259 }
+ Here is the call graph for this function:

◆ make_str_ato_wrappers() [1/3]

make_str_ato_wrappers ( ,
int   
)

◆ make_str_ato_wrappers() [2/3]

long make_str_ato_wrappers ( ,
short   
)

◆ make_str_ato_wrappers() [3/3]

long unsigned int make_str_ato_wrappers ( ul  ,
unsigned long   
)