Debian Codegraph @

src/common/err_queue.c

raw symbols SCIP
1 /*
2 * Copyright 2013 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
22 #include <config.h>cxx . . $ `<file>/build/config.h`/
23 #endif
24
25 #include "_error.h"cxx . . $ `<file>/src/common/_error.h`/
26 #include "err_queue.h"cxx . . $ `<file>/src/common/err_queue.h`/
27 #include <stdlib.h>
28 #include <string.h>
29
30 struct err_queuecxx . . $ err_queue# {
31 struct oscap_err_tcxx . . $ oscap_err_t# *firstcxx . . $ err_queue#first.;
32 struct oscap_err_tcxx . . $ oscap_err_t# *lastcxx . . $ err_queue#last.;
33 };
34
35 struct err_queuecxx . . $ err_queue# *err_queue_newcxx . . $ err_queue_new(14ccda84b3465fef).(void)
36 {
37 return (struct err_queuecxx . . $ err_queue# *) calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct err_queuecxx . . $ err_queue#));
38 }
39
40 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! err_queue_pushcxx . . $ err_queue_push(130f920746fcff31).(struct err_queuecxx . . $ err_queue# *q, struct oscap_err_tcxx . . $ oscap_err_t# *error)
41 {
42 if (q == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || error == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
43 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(false);
44 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
45 }
46 error->nextcxx . . $ oscap_err_t#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
47
48 if (q->lastcxx . . $ err_queue#last. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
49 q->firstcxx . . $ err_queue#first. = error;
50 q->lastcxx . . $ err_queue#last. = error;
51 }
52 else {
53 q->lastcxx . . $ err_queue#last.->nextcxx . . $ oscap_err_t#next. = error;
54 q->lastcxx . . $ err_queue#last. = error;
55 }
56 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
57 }
58
59 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! err_queue_is_emptycxx . . $ err_queue_is_empty(ac3ca0b8c1867adc).(struct err_queuecxx . . $ err_queue# *q)
60 {
61 if (q == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
62 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(false);
63 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
64 }
65 return q->lastcxx . . $ err_queue#last. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
66 }
67
68 struct oscap_err_tcxx . . $ oscap_err_t# *err_queue_pop_firstcxx . . $ err_queue_pop_first(d10ef9605042fd40).(struct err_queuecxx . . $ err_queue# *q)
69 {
70 if (q == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || q->firstcxx . . $ err_queue#first. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
71 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(false);
72 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
73 }
74
75 struct oscap_err_tcxx . . $ oscap_err_t# *pom = q->firstcxx . . $ err_queue#first.;
76 q->firstcxx . . $ err_queue#first. = pom->nextcxx . . $ oscap_err_t#next.;
77 if (q->lastcxx . . $ err_queue#last. == pom)
78 q->lastcxx . . $ err_queue#last. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
79 return pom;
80 }
81
82 const struct oscap_err_tcxx . . $ oscap_err_t# *err_queue_get_lastcxx . . $ err_queue_get_last(e5bbd80691f081f8).(struct err_queuecxx . . $ err_queue# *q)
83 {
84 if (q == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || q->lastcxx . . $ err_queue#last. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
85 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(false);
86 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
87 }
88 return q->lastcxx . . $ err_queue#last.;
89 }
90
91 void err_queue_freecxx . . $ err_queue_free(db4c3ce443b7b377).(struct err_queuecxx . . $ err_queue# *q, oscap_destruct_funccxx . . $ oscap_destruct_func# destructor)
92 {
93 if (q == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
94 return;
95
96 if (destructor != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
97 while (!err_queue_is_emptycxx . . $ err_queue_is_empty(ac3ca0b8c1867adc).(q))
98 destructor(err_queue_pop_firstcxx . . $ err_queue_pop_first(d10ef9605042fd40).(q));
99 freecxx . . $ free(5d22bdacc48458e8).(q);
100 }
101
102 int err_queue_to_stringcxx . . $ err_queue_to_string(11c23276edec036e).(struct err_queuecxx . . $ err_queue# *q, char **result)
103 {
104 if (q == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || result == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
105 assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(false);
106 return 1;
107 }
108
109 size_t size = 0;
110 struct oscap_err_tcxx . . $ oscap_err_t# *err = q->firstcxx . . $ err_queue#first.;
111 while (err != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
112 if (err->desccxx . . $ oscap_err_t#desc. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
113 int pom = strlencxx . . $ strlen(751346f8406fd082).(err->desccxx . . $ oscap_err_t#desc.);
114 if (pom != 0)
115 size += pom + 1;
116 }
117 err = err->nextcxx . . $ oscap_err_t#next.;
118 }
119 if (size == 0) {
120 *result = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
121 return 0;
122 }
123
124 *result = (char *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(size + 1);
125 if (*result == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
126 return 1;
127 char *pos = *result;
128 pos[0] = '\0';
129 err = q->firstcxx . . $ err_queue#first.;
130 while (err != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
131 if (err->desccxx . . $ oscap_err_t#desc. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
132 const size_t desc_len = strlencxx . . $ strlen(751346f8406fd082).(err->desccxx . . $ oscap_err_t#desc.);
133 memcpycxx . . $ memcpy(cc817cb175f282d).(pos, err->desccxx . . $ oscap_err_t#desc., desc_len);
134 pos += desc_len;
135 *pos = '\n';
136 pos++;
137 }
138 err = err->nextcxx . . $ oscap_err_t#next.;
139 }
140 (*result)[size-1] = '\0';
141 return 0;
142 }
143