]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libsysdecode/support.h
sqlite3: Vendor import of sqlite3 3.39.3
[FreeBSD/FreeBSD.git] / lib / libsysdecode / support.h
1 /*
2  * Copyright (c) 2006 "David Kirchner" <dpk@dpk.net>. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25
26 #ifndef __SYSDECODE_SUPPORT_H__
27 #define __SYSDECODE_SUPPORT_H__
28
29 /*
30  * This is taken from the xlat tables originally in truss which were
31  * in turn taken from strace.
32  */
33 struct name_table {
34         uintmax_t val;
35         const char *str;
36 };
37
38 /*
39  * These are simple support macros. print_or utilizes a variable
40  * defined in the calling function to track whether or not it should
41  * print a logical-OR character ('|') before a string. if_print_or
42  * simply handles the necessary "if" statement used in many lines
43  * of this file.
44  */
45 #define print_or(fp,str,orflag) do {                     \
46         if (orflag) fputc(fp, '|'); else orflag = true;  \
47         fprintf(fp, str); }                              \
48         while (0)
49 #define if_print_or(fp,i,flag,orflag) do {         \
50         if ((i & flag) == flag)                    \
51         print_or(fp,#flag,orflag); }               \
52         while (0)
53
54 const char *lookup_value(struct name_table *, uintmax_t);
55 void    print_integer(FILE *, int, int);
56 bool    print_mask_0(FILE *, struct name_table *, int, int *);
57 bool    print_mask_0ul(FILE *, struct name_table *, u_long, u_long *);
58 bool    print_mask_int(FILE *, struct name_table *, int, int *);
59 void    print_mask_part(FILE *, struct name_table *, uintmax_t *, bool *);
60 bool    print_value(FILE *, struct name_table *, uintmax_t);
61
62 #endif /* !__SYSDECODE_SUPPORT_H__ */