1 /* 2 * SPDX-License-Identifier: ISC 3 * 4 * Copyright (c) 2007, 2010, 2011, 2013-2015 5 * Todd C. Miller <Todd.Miller@sudo.ws> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #ifndef SUDO_LBUF_H 21 #define SUDO_LBUF_H 22 23 /* 24 * Line buffer struct. 25 */ 26 struct sudo_lbuf { 27 int (*output)(const char *); 28 char *buf; 29 const char *continuation; 30 int indent; 31 int len; 32 int size; 33 short cols; 34 short error; 35 }; 36 37 typedef int (*sudo_lbuf_output_t)(const char *); 38 39 sudo_dso_public void sudo_lbuf_init_v1(struct sudo_lbuf *lbuf, sudo_lbuf_output_t output, int indent, const char *continuation, int cols); 40 sudo_dso_public void sudo_lbuf_destroy_v1(struct sudo_lbuf *lbuf); 41 sudo_dso_public bool sudo_lbuf_append_v1(struct sudo_lbuf *lbuf, const char *fmt, ...) __printflike(2, 3); 42 sudo_dso_public bool sudo_lbuf_append_quoted_v1(struct sudo_lbuf *lbuf, const char *set, const char *fmt, ...) __printflike(3, 4); 43 sudo_dso_public void sudo_lbuf_print_v1(struct sudo_lbuf *lbuf); 44 sudo_dso_public bool sudo_lbuf_error_v1(struct sudo_lbuf *lbuf); 45 sudo_dso_public void sudo_lbuf_clearerr_v1(struct sudo_lbuf *lbuf); 46 47 #define sudo_lbuf_init(_a, _b, _c, _d, _e) sudo_lbuf_init_v1((_a), (_b), (_c), (_d), (_e)) 48 #define sudo_lbuf_destroy(_a) sudo_lbuf_destroy_v1((_a)) 49 #define sudo_lbuf_append sudo_lbuf_append_v1 50 #define sudo_lbuf_append_quoted sudo_lbuf_append_quoted_v1 51 #define sudo_lbuf_print(_a) sudo_lbuf_print_v1((_a)) 52 #define sudo_lbuf_error(_a) sudo_lbuf_error_v1((_a)) 53 #define sudo_lbuf_clearerr(_a) sudo_lbuf_clearerr_v1((_a)) 54 55 #endif /* SUDO_LBUF_H */ 56