summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2024-04-14 18:19:14 +0200
committerGravatar Nikias Bassen2024-04-14 18:19:14 +0200
commita91f5740d100414a76959714b819422ee5b2d8a8 (patch)
tree087400da3ed5af11ef1f4806ffc58a9a3a090323 /src
parent612cdf3ffd3e8c200e4a21ec15e3b3f0af170b42 (diff)
downloadlibplist-a91f5740d100414a76959714b819422ee5b2d8a8.tar.gz
libplist-a91f5740d100414a76959714b819422ee5b2d8a8.tar.bz2
Change API around #PLIST_DATA to use uint8_t instead of char arrays
This makes it more obvious that it is arbitrary data and not necessarily a string value.
Diffstat (limited to 'src')
-rw-r--r--src/Data.cpp12
-rw-r--r--src/plist.c11
2 files changed, 12 insertions, 11 deletions
diff --git a/src/Data.cpp b/src/Data.cpp
index a96fc50..c4709f7 100644
--- a/src/Data.cpp
+++ b/src/Data.cpp
@@ -34,7 +34,7 @@ Data::Data(plist_t node, Node* parent) : Node(node, parent)
Data::Data(const PList::Data& d) : Node(PLIST_DATA)
{
- std::vector<char> b = d.GetValue();
+ std::vector<uint8_t> b = d.GetValue();
plist_set_data_val(_node, &b[0], b.size());
}
@@ -45,7 +45,7 @@ Data& Data::operator=(const PList::Data& b)
return *this;
}
-Data::Data(const std::vector<char>& buff) : Node(PLIST_DATA)
+Data::Data(const std::vector<uint8_t>& buff) : Node(PLIST_DATA)
{
plist_set_data_val(_node, &buff[0], buff.size());
}
@@ -59,17 +59,17 @@ Node* Data::Clone() const
return new Data(*this);
}
-void Data::SetValue(const std::vector<char>& buff)
+void Data::SetValue(const std::vector<uint8_t>& buff)
{
plist_set_data_val(_node, &buff[0], buff.size());
}
-std::vector<char> Data::GetValue() const
+std::vector<uint8_t> Data::GetValue() const
{
- char* buff = NULL;
+ uint8_t* buff = NULL;
uint64_t length = 0;
plist_get_data_val(_node, &buff, &length);
- std::vector<char> ret(buff, buff + length);
+ std::vector<uint8_t> ret(buff, buff + length);
delete buff;
return ret;
}
diff --git a/src/plist.c b/src/plist.c
index 2078520..57f5ead 100644
--- a/src/plist.c
+++ b/src/plist.c
@@ -35,6 +35,7 @@
#include <limits.h>
#include <float.h>
#include <ctype.h>
+#include <inttypes.h>
#ifdef WIN32
#include <windows.h>
@@ -490,7 +491,7 @@ plist_t plist_new_real(double val)
return plist_new_node(data);
}
-plist_t plist_new_data(const char *val, uint64_t length)
+plist_t plist_new_data(const uint8_t *val, uint64_t length)
{
plist_data_t data = plist_new_plist_data();
data->type = PLIST_DATA;
@@ -1142,7 +1143,7 @@ void plist_get_real_val(plist_t node, double *val)
assert(length == sizeof(double));
}
-void plist_get_data_val(plist_t node, char **val, uint64_t * length)
+void plist_get_data_val(plist_t node, uint8_t **val, uint64_t * length)
{
if (!node || !val || !length)
return;
@@ -1152,7 +1153,7 @@ void plist_get_data_val(plist_t node, char **val, uint64_t * length)
plist_get_type_and_value(node, &type, (void *) val, length);
}
-const char* plist_get_data_ptr(plist_t node, uint64_t* length)
+const uint8_t* plist_get_data_ptr(plist_t node, uint64_t* length)
{
if (!node || !length)
return NULL;
@@ -1161,7 +1162,7 @@ const char* plist_get_data_ptr(plist_t node, uint64_t* length)
return NULL;
plist_data_t data = plist_get_data(node);
*length = data->length;
- return (const char*)data->buff;
+ return data->buff;
}
void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec)
@@ -1332,7 +1333,7 @@ void plist_set_real_val(plist_t node, double val)
plist_set_element_val(node, PLIST_REAL, &val, sizeof(double));
}
-void plist_set_data_val(plist_t node, const char *val, uint64_t length)
+void plist_set_data_val(plist_t node, const uint8_t *val, uint64_t length)
{
plist_set_element_val(node, PLIST_DATA, val, length);
}