|
|
@ -336,12 +336,25 @@ uint32_t ndbuf_write_u64(ndbuf_t *b, uint64_t uu)
|
|
|
|
return sizeof(uint64_t);
|
|
|
|
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 */
|
|
|
|
/* write raw data with the given length */
|
|
|
|
uint32_t ndbuf_write_raw(ndbuf_t *b, void *wi, uint32_t len)
|
|
|
|
uint32_t ndbuf_write_raw(ndbuf_t *b, void *wi, uint32_t len)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(!b || !b->raw) return 0;
|
|
|
|
if(!b || !b->raw) return 0;
|
|
|
|
if(!wi || !len) return 0;
|
|
|
|
if(!wi || !len) return 0;
|
|
|
|
|
|
|
|
if(__ndbuf_is_ro(b)) return 0; /* read only buffer */
|
|
|
|
|
|
|
|
|
|
|
|
if(b->ulength + len >= b->rlength) {
|
|
|
|
if(b->ulength + len >= b->rlength) {
|
|
|
|
|
|
|
|
if(__ndbuf_is_nrea(b)) return 0; /* non reallocatable buffer */
|
|
|
|
if(__rdb_grow(b, len)) return 0;
|
|
|
|
if(__rdb_grow(b, len)) return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -361,7 +374,10 @@ uint32_t ndbuf_write_raw_head(ndbuf_t *b, void *wi, uint32_t len)
|
|
|
|
|
|
|
|
|
|
|
|
if(!b || !b->raw) return 0;
|
|
|
|
if(!b || !b->raw) return 0;
|
|
|
|
if(!wi || !len) return 0;
|
|
|
|
if(!wi || !len) return 0;
|
|
|
|
|
|
|
|
if(__ndbuf_is_ro(b)) return 0; /* read only buffer */
|
|
|
|
|
|
|
|
|
|
|
|
if(b->ulength + len > b->rlength) {
|
|
|
|
if(b->ulength + len > b->rlength) {
|
|
|
|
|
|
|
|
if(__ndbuf_is_nrea(b)) return 0; /* non reallocatable buffer */
|
|
|
|
/* allocate a new one and copy it right */
|
|
|
|
/* allocate a new one and copy it right */
|
|
|
|
if(b->rlength + len > NDBUF_MAXLENGTH) return -1;
|
|
|
|
if(b->rlength + len > NDBUF_MAXLENGTH) return -1;
|
|
|
|
|
|
|
|
|
|
|
@ -617,6 +633,8 @@ uint32_t ndbuf_print_va(ndbuf_t *b, const char *fmt, int argc, va_list ap)
|
|
|
|
uint32_t len = 0, clen;
|
|
|
|
uint32_t len = 0, clen;
|
|
|
|
int r, count;
|
|
|
|
int r, count;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(__ndbuf_is_ro(b)) return 0; /* read only buffer */
|
|
|
|
|
|
|
|
|
|
|
|
for(t = fmt, count = 0; *t != '\0'; t++, count++) {
|
|
|
|
for(t = fmt, count = 0; *t != '\0'; t++, count++) {
|
|
|
|
if(count > argc && argc != -1) return 0;
|
|
|
|
if(count > argc && argc != -1) return 0;
|
|
|
|
switch(*t) {
|
|
|
|
switch(*t) {
|
|
|
|