Simple data structures / objects in plain C Snapshot
Defines | Functions
Strtoint

an attempt to normalize the wild strtol/stroll/strtoul/strtoull set of functions for the stdint.h world. More...

Defines

#define strto_int64_t   strtoll
#define strto_uint64_t   strtoull

Functions

M_INLINE int16_t strto_int16_t (const char *nptr, char **endptr, int base)
M_INLINE uint16_t strto_uint16_t (const char *nptr, char **endptr, int base)
M_INLINE int32_t strto_int32_t (const char *nptr, char **endptr, int base)
M_INLINE uint32_t strto_uint32_t (const char *nptr, char **endptr, int base)

Detailed Description

an attempt to normalize the wild strtol/stroll/strtoul/strtoull set of functions for the stdint.h world.


Define Documentation

#define strto_int64_t   strtoll

Definition at line 54 of file strtoint.h.

#define strto_uint64_t   strtoull

Definition at line 55 of file strtoint.h.


Function Documentation

M_INLINE int16_t strto_int16_t ( const char *  nptr,
char **  endptr,
int  base 
)

Definition at line 17 of file strtoint.h.

{
  long rval = strtol( nptr, endptr, base );
  if (rval > SHRT_MAX) {
    errno = ERANGE;
  }
  return (int16_t) rval;
}
M_INLINE int32_t strto_int32_t ( const char *  nptr,
char **  endptr,
int  base 
)

Definition at line 36 of file strtoint.h.

{
  long rval = strtol( nptr, endptr, base );
  if (rval > INT_MAX) {
    errno = ERANGE;
  }
  return (int32_t) rval;
}
M_INLINE uint16_t strto_uint16_t ( const char *  nptr,
char **  endptr,
int  base 
)

Definition at line 26 of file strtoint.h.

{
  long rval = strtoul( nptr, endptr, base );
  if (rval > USHRT_MAX) {
    errno = ERANGE;
  }
  return (uint16_t) rval;
}
M_INLINE uint32_t strto_uint32_t ( const char *  nptr,
char **  endptr,
int  base 
)

Definition at line 45 of file strtoint.h.

{
  uint32_t rval = strtol( nptr, endptr, base );
  if (rval > UINT_MAX) {
    errno = ERANGE;
  }
  return (int32_t) rval;
}