| Code Coverage: vinyl-cache/include/vsb.h |
| |
| 82217aa4fc7094b3610340078afaf78cd95a8ec9 |
| |
| 0 |
|
/*- |
| 1 |
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD |
| 2 |
|
* |
| 3 |
|
* Copyright (c) 2000-2011 Poul-Henning Kamp <phk@FreeBSD.org> |
| 4 |
|
* Copyright (c) 2000-2008 Dag-Erling Coïdan Smørgrav |
| 5 |
|
* All rights reserved. |
| 6 |
|
* |
| 7 |
|
* Redistribution and use in source and binary forms, with or without |
| 8 |
|
* modification, are permitted provided that the following conditions |
| 9 |
|
* are met: |
| 10 |
|
* 1. Redistributions of source code must retain the above copyright |
| 11 |
|
* notice, this list of conditions and the following disclaimer |
| 12 |
|
* in this position and unchanged. |
| 13 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 14 |
|
* notice, this list of conditions and the following disclaimer in the |
| 15 |
|
* documentation and/or other materials provided with the distribution. |
| 16 |
|
* |
| 17 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 18 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 21 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 |
|
* SUCH DAMAGE. |
| 28 |
|
* |
| 29 |
|
* $FreeBSD: head/sys/sys/vsb.h 221993 2011-05-16 16:18:40Z phk $ |
| 30 |
|
*/ |
| 31 |
|
|
| 32 |
|
#ifndef VSB_H_INCLUDED |
| 33 |
|
#define VSB_H_INCLUDED |
| 34 |
|
|
| 35 |
|
/* |
| 36 |
|
* Structure definition |
| 37 |
|
*/ |
| 38 |
|
struct vsb { |
| 39 |
|
unsigned magic; |
| 40 |
1951935 |
#define VSB_MAGIC 0x4a82dd8a |
| 41 |
|
int s_error; /* current error code */ |
| 42 |
|
char *s_buf; /* storage buffer */ |
| 43 |
|
ssize_t s_size; /* size of storage buffer */ |
| 44 |
|
ssize_t s_len; /* current length of string */ |
| 45 |
66187 |
#define VSB_FIXEDLEN 0x00000000 /* fixed length buffer (default) */ |
| 46 |
8483002 |
#define VSB_AUTOEXTEND 0x00000001 /* automatically extend buffer */ |
| 47 |
|
#define VSB_USRFLAGMSK 0x0000ffff /* mask of flags the user may specify */ |
| 48 |
5104854 |
#define VSB_DYNAMIC 0x00010000 /* s_buf must be freed */ |
| 49 |
|
#define VSB_FINISHED 0x00020000 /* set by VSB_finish() */ |
| 50 |
|
#define VSB_DYNSTRUCT 0x00080000 /* vsb must be freed */ |
| 51 |
|
int s_flags; /* flags */ |
| 52 |
|
int s_indent; /* Ident level */ |
| 53 |
|
}; |
| 54 |
|
|
| 55 |
|
#ifdef __cplusplus |
| 56 |
|
extern "C" { |
| 57 |
|
#endif |
| 58 |
|
/* |
| 59 |
|
* API functions |
| 60 |
|
*/ |
| 61 |
|
struct vsb *VSB_init(struct vsb *, void *, ssize_t); |
| 62 |
|
struct vsb *VSB_new_auto(void); |
| 63 |
|
void VSB_clear(struct vsb *); |
| 64 |
|
int VSB_bcat(struct vsb *, const void *, ssize_t); |
| 65 |
|
int VSB_cat(struct vsb *, const char *); |
| 66 |
|
int VSB_printf(struct vsb *, const char *, ...) |
| 67 |
|
v_printflike_(2, 3); |
| 68 |
|
#ifdef va_start |
| 69 |
|
int VSB_vprintf(struct vsb *, const char *, va_list) |
| 70 |
|
v_printflike_(2, 0); |
| 71 |
|
#endif |
| 72 |
|
int VSB_putc(struct vsb *, int); |
| 73 |
|
int VSB_error(const struct vsb *); |
| 74 |
|
int VSB_finish(struct vsb *); |
| 75 |
|
char *VSB_data(const struct vsb *); |
| 76 |
|
ssize_t VSB_len(const struct vsb *); |
| 77 |
|
void VSB_fini(struct vsb *); |
| 78 |
|
void VSB_destroy(struct vsb **); |
| 79 |
|
|
| 80 |
|
/* |
| 81 |
|
* VSB_quote[_pfx] has four major modes, and two modifiers |
| 82 |
|
*/ |
| 83 |
|
|
| 84 |
1 |
#define VSB_QUOTE_PLAIN 0 |
| 85 |
|
/* |
| 86 |
|
* Basic "show me the string" mode |
| 87 |
|
* All output is a single line |
| 88 |
|
*/ |
| 89 |
658977 |
#define VSB_QUOTE_JSON 2 |
| 90 |
|
/* |
| 91 |
|
* JSON-like output suitable for inclusion between "..." |
| 92 |
|
* Quotes <0x20 as \u%04x |
| 93 |
|
* Keeps >0x7e unquoted |
| 94 |
|
*/ |
| 95 |
866991 |
#define VSB_QUOTE_HEX 4 |
| 96 |
|
/* |
| 97 |
|
* Hex dump, single line. |
| 98 |
|
* All zero data is compressed to "0x0...0" |
| 99 |
|
*/ |
| 100 |
2150097 |
#define VSB_QUOTE_CSTR 8 |
| 101 |
|
/* |
| 102 |
|
* C language source code literal string(s) |
| 103 |
|
* Breaks strings at \n (expecting string concatenation) |
| 104 |
|
*/ |
| 105 |
1094908 |
#define VSB_QUOTE_UNSAFE 16 |
| 106 |
|
/* |
| 107 |
|
* For general display applications |
| 108 |
|
* " and \ are not quoted |
| 109 |
|
* Splits output to new line at '\n' |
| 110 |
|
* Implies VSB_QUOTE_NONL |
| 111 |
|
*/ |
| 112 |
|
|
| 113 |
740828 |
#define VSB_QUOTE_NONL 1 |
| 114 |
|
/* |
| 115 |
|
* If the output does not end in \n, append \n |
| 116 |
|
* Can be combined with all other modes. |
| 117 |
|
*/ |
| 118 |
|
|
| 119 |
577694 |
#define VSB_QUOTE_ESCHEX 32 |
| 120 |
|
/* |
| 121 |
|
* Use \x%02x instead of \%03o |
| 122 |
|
* Not valid with VSB_QUOTE_JSON and VSB_QUOTE_HEX |
| 123 |
|
*/ |
| 124 |
|
|
| 125 |
711804 |
#define VSB_QUOTE_ABBREVIATE 64 |
| 126 |
|
/* |
| 127 |
|
* Abbreviate with "[...]" If longer than specified length |
| 128 |
|
*/ |
| 129 |
|
|
| 130 |
|
void VSB_quote_pfx(struct vsb *, const char*, const void *, |
| 131 |
|
int len, int how); |
| 132 |
|
void VSB_quote(struct vsb *, const void *, int len, int how); |
| 133 |
|
void VSB_indent(struct vsb *, int); |
| 134 |
|
int VSB_tofile(const struct vsb *, int fd); |
| 135 |
|
#ifdef __cplusplus |
| 136 |
|
}; |
| 137 |
|
#endif |
| 138 |
|
|
| 139 |
|
#endif |