X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flibsigrok-internal.h;h=5b20e54b7e5a3fc6a6d53fe262f799f240639bcc;hb=97aa41e9b59c7a5f6f902939a769efa8aba33efc;hp=465a16e965ace8cf426cbafb866d92005e67f61f;hpb=f1833600a0e498dae8bf9babe83208de8b46f38a;p=libsigrok.git diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 465a16e9..5b20e54b 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -142,6 +142,23 @@ static inline int16_t read_i16le(const uint8_t *p) } #define RL16S(x) read_i16le((const uint8_t *)(x)) +/** + * Read a 24 bits little endian unsigned integer out of memory. + * @param x a pointer to the input memory + * @return the corresponding unsigned integer + */ +static inline uint32_t read_u24le(const uint8_t *p) +{ + uint32_t u; + + u = 0; + u <<= 8; u |= p[2]; + u <<= 8; u |= p[1]; + u <<= 8; u |= p[0]; + + return u; +} + /** * Read a 32 bits big endian unsigned integer out of memory. * @param x a pointer to the input memory @@ -499,6 +516,23 @@ static inline uint32_t read_u32be_inc(const uint8_t **p) return v; } +/** + * Read unsigned 24bit integer from raw memory (little endian format), increment read position. + * @param[in, out] p Pointer into byte stream. + * @return Retrieved integer value, unsigned. + */ +static inline uint32_t read_u24le_inc(const uint8_t **p) +{ + uint32_t v; + + if (!p || !*p) + return 0; + v = read_u24le(*p); + *p += 3 * sizeof(uint8_t); + + return v; +} + /** * Read unsigned 32bit integer from raw memory (little endian format), increment read position. * @param[in, out] p Pointer into byte stream. @@ -1467,6 +1501,7 @@ SR_PRIV void *sr_resource_load(struct sr_context *ctx, int type, /*--- strutil.c -------------------------------------------------------------*/ SR_PRIV int sr_atol(const char *str, long *ret); +SR_PRIV int sr_atol_base(const char *str, long *ret, char **end, int base); SR_PRIV int sr_atoi(const char *str, int *ret); SR_PRIV int sr_atod(const char *str, double *ret); SR_PRIV int sr_atof(const char *str, float *ret);