* Extend an sbuf. */
| 166 | * Extend an sbuf. |
| 167 | */ |
| 168 | static int |
| 169 | sbuf_extend(struct sbuf *s, int addlen) |
| 170 | { |
| 171 | char *newbuf; |
| 172 | int newsize; |
| 173 | |
| 174 | if (!SBUF_CANEXTEND(s)) |
| 175 | return (-1); |
| 176 | newsize = sbuf_extendsize(s->s_size + addlen); |
| 177 | newbuf = SBMALLOC(newsize, SBUF_MALLOCFLAG(s)); |
| 178 | if (newbuf == NULL) |
| 179 | return (-1); |
| 180 | memcpy(newbuf, s->s_buf, s->s_size); |
| 181 | if (SBUF_ISDYNAMIC(s)) |
| 182 | SBFREE(s->s_buf); |
| 183 | else |
| 184 | SBUF_SETFLAG(s, SBUF_DYNAMIC); |
| 185 | s->s_buf = newbuf; |
| 186 | s->s_size = newsize; |
| 187 | return (0); |
| 188 | } |
| 189 | |
| 190 | /* |
| 191 | * Initialize an sbuf. |
no test coverage detected