fixed NREA write functions; made them aware about non-realloc buffer;
This commit is contained in:
parent
8ddcddf18f
commit
b07795a039
24
ndbuf.c
24
ndbuf.c
@ -283,12 +283,23 @@ static int __rdb_grow(ndbuf_t *b, uint32_t len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int __ndbuf_is_ro(ndbuf_t *b)
|
||||
{
|
||||
return (b->flags & NDBUF_RORB) ? 1 : 0;
|
||||
}
|
||||
|
||||
static inline int __ndbuf_is_nrea(ndbuf_t *b)
|
||||
{
|
||||
return (b->flags & NDBUF_NREA) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* write different types, should return the size of the
|
||||
* written data, otherwise error occurs */
|
||||
uint32_t ndbuf_write_u8(ndbuf_t *b, uint8_t u)
|
||||
{
|
||||
if(!b || !b->raw) return 0;
|
||||
if(b->ulength == b->rlength) {
|
||||
if(__ndbuf_is_nrea(b)) return 0; /* non reallocatable buffer */
|
||||
if(__rdb_grow(b, sizeof(uint8_t))) return 0;
|
||||
}
|
||||
|
||||
@ -302,6 +313,7 @@ uint32_t ndbuf_write_u16(ndbuf_t *b, uint16_t uu)
|
||||
{
|
||||
if(!b || !b->raw) return 0;
|
||||
if(b->ulength + sizeof(uint16_t) >= b->rlength) {
|
||||
if(__ndbuf_is_nrea(b)) return 0; /* non reallocatable buffer */
|
||||
if(__rdb_grow(b, sizeof(uint16_t))) return 0;
|
||||
}
|
||||
|
||||
@ -315,6 +327,7 @@ uint32_t ndbuf_write_u32(ndbuf_t *b, uint32_t uu)
|
||||
{
|
||||
if(!b || !b->raw) return 0;
|
||||
if(b->ulength + sizeof(uint32_t) >= b->rlength) {
|
||||
if(__ndbuf_is_nrea(b)) return 0; /* non reallocatable buffer */
|
||||
if(__rdb_grow(b, sizeof(uint32_t))) return 0;
|
||||
}
|
||||
|
||||
@ -328,6 +341,7 @@ uint32_t ndbuf_write_u64(ndbuf_t *b, uint64_t uu)
|
||||
{
|
||||
if(!b || !b->raw) return 0;
|
||||
if(b->ulength + sizeof(uint64_t) >= b->rlength) {
|
||||
if(__ndbuf_is_nrea(b)) return 0; /* non reallocatable buffer */
|
||||
if(__rdb_grow(b, sizeof(uint64_t))) return 0;
|
||||
}
|
||||
|
||||
@ -337,16 +351,6 @@ uint32_t ndbuf_write_u64(ndbuf_t *b, uint64_t uu)
|
||||
return sizeof(uint64_t);
|
||||
}
|
||||
|
||||
static inline int __ndbuf_is_ro(ndbuf_t *b)
|
||||
{
|
||||
return (b->flags & NDBUF_RORB) ? 1 : 0;
|
||||
}
|
||||
|
||||
static inline int __ndbuf_is_nrea(ndbuf_t *b)
|
||||
{
|
||||
return (b->flags & NDBUF_NREA) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* write raw data with the given length */
|
||||
uint32_t ndbuf_write_raw(ndbuf_t *b, void *wi, uint32_t len)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user