Skip to content

Commit 1712ad6

Browse files
committed
util: add attr_as_bool
1 parent cbd4618 commit 1712ad6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

qdl.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ int sahara_run(struct qdl_device *qdl, char *img_arr[], bool single_image,
3737
void print_hex_dump(const char *prefix, const void *buf, size_t len);
3838
unsigned attr_as_unsigned(xmlNode *node, const char *attr, int *errors);
3939
const char *attr_as_string(xmlNode *node, const char *attr, int *errors);
40+
bool attr_as_bool(xmlNode *node, const char *attr, int *errors);
4041

4142
extern bool qdl_debug;
4243

util.c

+17
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* POSSIBILITY OF SUCH DAMAGE.
3030
*/
3131
#include <ctype.h>
32+
#include <stdbool.h>
3233
#include <stdint.h>
3334
#include <stdio.h>
3435
#include <string.h>
@@ -110,3 +111,19 @@ const char *attr_as_string(xmlNode *node, const char *attr, int *errors)
110111

111112
return strdup((char*)value);
112113
}
114+
115+
bool attr_as_bool(xmlNode *node, const char *attr, int *errors)
116+
{
117+
xmlChar *value;
118+
119+
if (!xmlHasProp(node, (xmlChar*)attr))
120+
return false;
121+
122+
value = xmlGetProp(node, (xmlChar*)attr);
123+
if (!value) {
124+
(*errors)++;
125+
return false;
126+
}
127+
128+
return xmlStrcmp(value, (xmlChar*)"true") == 0;
129+
}

0 commit comments

Comments
 (0)