2022-07-31 17:15:32 +02:00
|
|
|
#include "val.h"
|
2018-04-01 12:40:53 +02:00
|
|
|
#include "cw.h"
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
#include "dbg.h"
|
|
|
|
|
2022-07-31 17:15:32 +02:00
|
|
|
cw_Val_t * cw_ktv_replace(mavl_t kvtstore, const char *key, const struct cw_Type *type,
|
2018-04-25 10:43:27 +02:00
|
|
|
const void * valguard,
|
2018-04-01 12:40:53 +02:00
|
|
|
const uint8_t * data, int len)
|
|
|
|
{
|
2022-07-31 17:15:32 +02:00
|
|
|
cw_Val_t mdata, *mresult;
|
2018-04-01 12:40:53 +02:00
|
|
|
int exists;
|
|
|
|
|
|
|
|
mdata.key=cw_strdup(key);
|
|
|
|
if (!mdata.key){
|
|
|
|
cw_log(LOG_ERR, "Can't allocate memory for KTV key %s: %s",
|
|
|
|
key,strerror(errno));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mresult = type->get(&mdata,data,len);
|
|
|
|
if (!mresult){
|
|
|
|
cw_log(LOG_ERR, "Can't create kvstore element for key %s of type %s: %s",
|
|
|
|
key,type->name, strerror(errno));
|
|
|
|
free(mdata.key);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mresult = mavl_replace(kvtstore, &mdata, &exists);
|
|
|
|
|
|
|
|
return mresult;
|
|
|
|
}
|