Lines Matching refs:p
31 static int printbuf_extend(struct printbuf *p, int min_size);
35 struct printbuf *p; in printbuf_new() local
37 p = (struct printbuf*)calloc(1, sizeof(struct printbuf)); in printbuf_new()
38 if(!p) return NULL; in printbuf_new()
39 p->size = 32; in printbuf_new()
40 p->bpos = 0; in printbuf_new()
41 if(!(p->buf = (char*)malloc(p->size))) { in printbuf_new()
42 free(p); in printbuf_new()
45 return p; in printbuf_new()
57 static int printbuf_extend(struct printbuf *p, int min_size) in printbuf_extend() argument
62 if (p->size >= min_size) in printbuf_extend()
65 new_size = p->size * 2; in printbuf_extend()
71 p->bpos, min_size, p->size, new_size); in printbuf_extend()
73 if(!(t = (char*)realloc(p->buf, new_size))) in printbuf_extend()
75 p->size = new_size; in printbuf_extend()
76 p->buf = t; in printbuf_extend()
80 int printbuf_memappend(struct printbuf *p, const char *buf, int size) in printbuf_memappend() argument
82 if (p->size <= p->bpos + size + 1) { in printbuf_memappend()
83 if (printbuf_extend(p, p->bpos + size + 1) < 0) in printbuf_memappend()
86 memcpy(p->buf + p->bpos, buf, size); in printbuf_memappend()
87 p->bpos += size; in printbuf_memappend()
88 p->buf[p->bpos]= '\0'; in printbuf_memappend()
153 int sprintbuf(struct printbuf *p, const char *msg, ...) in sprintbuf() argument
172 printbuf_memappend(p, t, size); in sprintbuf()
176 printbuf_memappend(p, buf, size); in sprintbuf()
181 void printbuf_reset(struct printbuf *p) in printbuf_reset() argument
183 p->buf[0] = '\0'; in printbuf_reset()
184 p->bpos = 0; in printbuf_reset()
187 void printbuf_free(struct printbuf *p) in printbuf_free() argument
189 if(p) { in printbuf_free()
190 free(p->buf); in printbuf_free()
191 free(p); in printbuf_free()