123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #ifndef _printbuf_h_
- #define _printbuf_h_
- #ifdef __cplusplus
- extern "C" {
- #endif
- struct printbuf {
- char *buf;
- int bpos;
- int size;
- };
- typedef struct printbuf printbuf;
- extern struct printbuf*
- printbuf_new(void);
- extern int
- printbuf_memappend(struct printbuf *p, const char *buf, int size);
- #define printbuf_memappend_fast(p, bufptr, bufsize) \
- do { \
- if ((p->size - p->bpos) > bufsize) { \
- memcpy(p->buf + p->bpos, (bufptr), bufsize); \
- p->bpos += bufsize; \
- p->buf[p->bpos]= '\0'; \
- } else { printbuf_memappend(p, (bufptr), bufsize); } \
- } while (0)
- #define printbuf_length(p) ((p)->bpos)
- #define _printbuf_check_literal(mystr) ("" mystr)
- #define printbuf_strappend(pb, str) \
- printbuf_memappend ((pb), _printbuf_check_literal(str), sizeof(str) - 1)
- extern int
- printbuf_memset(struct printbuf *pb, int offset, int charvalue, int len);
- extern int
- sprintbuf(struct printbuf *p, const char *msg, ...);
- extern void
- printbuf_reset(struct printbuf *p);
- extern void
- printbuf_free(struct printbuf *p);
- #ifdef __cplusplus
- }
- #endif
- #endif
|