Lev Walkin | d922184 | 2017-08-22 01:44:56 -0700 | [diff] [blame] | 1 | #ifndef ASN1_BUFFER_H |
| 2 | #define ASN1_BUFFER_H |
| 3 | |
Lev Walkin | e3204e7 | 2017-08-23 06:22:53 -0700 | [diff] [blame] | 4 | #include <stdarg.h> |
| 5 | |
Lev Walkin | d922184 | 2017-08-22 01:44:56 -0700 | [diff] [blame] | 6 | /* |
| 7 | * Your typical dynamic character string buffer. |
| 8 | */ |
| 9 | typedef struct { |
| 10 | const char *buffer; |
| 11 | size_t length; |
| 12 | size_t size; |
| 13 | } abuf; |
| 14 | |
| 15 | /* |
| 16 | * Create and destroy the buffer. |
| 17 | */ |
| 18 | abuf *abuf_new(void); |
| 19 | void abuf_free(abuf *); |
| 20 | |
| 21 | /* |
| 22 | * Erase contents of the buffer (without destroying it). |
| 23 | */ |
| 24 | void abuf_clear(abuf *); |
| 25 | |
| 26 | /* |
| 27 | * Add characters to the buffer. |
| 28 | */ |
| 29 | void abuf_str(abuf *, const char *str); |
| 30 | void abuf_buf(abuf *, const abuf *); |
Lev Walkin | e3204e7 | 2017-08-23 06:22:53 -0700 | [diff] [blame] | 31 | void abuf_add_bytes(abuf *, const char *, size_t); |
| 32 | int abuf_printf(abuf *, const char *fmt, ...) |
Lev Walkin | d922184 | 2017-08-22 01:44:56 -0700 | [diff] [blame] | 33 | __attribute__((format(printf, 2, 3))); |
Lev Walkin | e3204e7 | 2017-08-23 06:22:53 -0700 | [diff] [blame] | 34 | int abuf_vprintf(abuf *, const char *fmt, va_list); |
Lev Walkin | d922184 | 2017-08-22 01:44:56 -0700 | [diff] [blame] | 35 | |
| 36 | #endif /* ASN1_BUFFER_H */ |