YAZ 5.38.1
atoin.c File Reference

Implements atoi_n function. More...

#include <string.h>
#include <limits.h>
#include <yaz/yaz-iconv.h>
#include <yaz/atoi.h>

Go to the source code of this file.

Functions

int atoi_n (const char *buf, int len)
 like atoi(3) except that it reads exactly len characters
int atoi_n_check (const char *buf, int size, int *val)
 like atoi_n but checks for proper formatting
int yaz_atoi (int base, const char *ptr, int len, int *val)
 string to int conversion, with base
int yaz_atoul (int base, const char *ptr, int len, unsigned long *val)
 string to unsigned long conversion, with base

Detailed Description

Implements atoi_n function.

Definition in file atoin.c.

Function Documentation

◆ atoi_n()

int atoi_n ( const char * buf,
int len )

like atoi(3) except that it reads exactly len characters

Parameters
bufbuffer to read
lennumber of bytes to consider (being digits)
Returns
value

Definition at line 20 of file atoin.c.

References atoi_n(), and atoi_n_check().

Referenced by atoi_n(), and yaz_marc_read_iso2709().

◆ atoi_n_check()

int atoi_n_check ( const char * buf,
int size,
int * val )

like atoi_n but checks for proper formatting

Parameters
bufbuffer to read values from
sizesize of buffer
valvalue of decimal number (if successful)
Return values
0no value found (non-digits found)
1value found and *val holds value

Definition at line 27 of file atoin.c.

References atoi_n_check(), and yaz_atoi().

Referenced by atoi_n(), atoi_n_check(), convert_solrmarc(), replace_node(), yaz_marc_read_iso2709(), yaz_marc_read_line(), yaz_marc_set_leader(), yaz_marc_write_check(), yaz_marc_write_iso2709(), yaz_marc_write_json(), yaz_marc_write_line(), yaz_marc_write_marcxml_wrbuf(), yaz_marc_write_xml(), and yaz_marc_write_xml_turbo_xml().

◆ yaz_atoi()

int yaz_atoi ( int base,
const char * ptr,
int len,
int * val )

string to int conversion, with base

Parameters
basenumerical base (2-36)
ptrbuffer to read
lennumber of bytes to consider (being digits)
valvalue of decimal number (if successful)
Returns
number of bytes read if successful, or -1 on error (overflow or invalid base) The function stops at first digit not valid for base. In particular, if no digits are found, 0 is returned and *val is set to 0.

Definition at line 33 of file atoin.c.

References yaz_atoi(), and yaz_atoul().

Referenced by atoi_n_check(), cs_complete_http(), yaz_atoi(), and yaz_http_parse_chunks().

◆ yaz_atoul()

int yaz_atoul ( int base,
const char * ptr,
int len,
unsigned long * val )

string to unsigned long conversion, with base

Parameters
basenumerical base (2-36)
ptrbuffer to read
lenmaximum number of bytes to read
valvalue of number (if successful)
Returns
number of bytes read if successful, or -1 on error (overflow or invalid base) The function stops at first digit not valid for base. In particular, if no digits are found, 0 is returned and *val is set to 0.

Definition at line 45 of file atoin.c.

References yaz_atoul(), yaz_isdigit, yaz_islower, and yaz_isupper.

Referenced by yaz_atoi(), and yaz_atoul().